在AWS Amplify构建中获取私有子模块

时间:2019-05-20 10:29:44

标签: git amazon-web-services git-submodules aws-amplify

我正在使用AWS Amplify部署我的应用程序。我决定将我的应用程序的一部分分成一个子模块。现在,当我在Amplify的构建中构建运行git submodule update --init --recursive时,它给了我一个访问错误,因为它是一个私有存储库,AWS无法访问它。

我有两种选择,一种是使用https来获取仓库,但这需要我将用户名和密码放入子模块中。或找出使AWS生成SSH密钥的方法,我可以将其与子模块SSH访问配对以继续。我想使用后者,但是我不知道如何在AWS Amplify中做到这一点。

2 个答案:

答案 0 :(得分:1)

也就此问题向AWS咨询,第二种选择目前没有解决方案。

您可以创建一个对子模块存储库具有只读访问权限的单独的GitHub用户,并通过HTTPS将其添加:https://USERNAME:PASSWORD@github.com/ACCOUNT/SUBMOUDLE-REPO.git

奖金:如果您想将更改推送到子模块存储库,则可以更改原始推送URL。在子模块目录中:git config remote.origin.pushurl git@github.com:ACCOUNT/SUBMODULE-REPO.git

FWIW,Netlify在几个月前遇到了相同的问题(不确定是否仍然存在),他们的解决方法是让他们手动为子模块存储库生成部署密钥,但是由于GitHub的限制,该密钥只能使用一次-对于需要使用子模块的其他任何存储库/站点,您将需要再次执行该过程。

答案 1 :(得分:0)

一种解决方案似乎是生成带有密码短语(不安全的解决方案)的SSH密钥,然后将其添加为aws-amplify项目中的环境变量:

  1. 生成不带密码的ssh密钥:
  • starting build "570f00c9-e462-4f2e-8314-ea75df68e590" FETCHSOURCE BUILD Starting Step #0 - "fetcher" Step #0 - "fetcher": Already have image (with digest): gcr.io/cloud-builders/gcs-fetcher Step #0 - "fetcher": Fetching manifest gs://staging.myapp.appspot.com/ae/2ee45089-8d39-47ad-85f5-f9489c54badc/manifest.json. Step #0 - "fetcher": Processing 9 files. Step #0 - "fetcher": ****************************************************** Step #0 - "fetcher": Status: SUCCESS Step #0 - "fetcher": Started: 2020-08-03T23:42:00Z Step #0 - "fetcher": Completed: 2020-08-03T23:42:00Z Step #0 - "fetcher": Requested workers: 200 Step #0 - "fetcher": Actual workers: 9 Step #0 - "fetcher": Total files: 9 Step #0 - "fetcher": Total retries: 0 Step #0 - "fetcher": GCS timeouts: 0 Step #0 - "fetcher": MiB downloaded: 0.10 MiB Step #0 - "fetcher": MiB/s throughput: 0.71 MiB/s Step #0 - "fetcher": Time for manifest: 213.58 ms Step #0 - "fetcher": Total time: 0.36 s Step #0 - "fetcher": ****************************************************** Finished Step #0 - "fetcher" Starting Step #1 - "prep" Step #1 - "prep": Already have image (with digest): gcr.io/cloud-builders/gcloud Finished Step #1 - "prep" Starting Step #2 - "detector" Step #2 - "detector": Pulling image: us.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20200711_12_18_2_RC00 Step #2 - "detector": nodejs12_20200711_12_18_2_RC00: Pulling from gae-runtimes/buildpacks/nodejs12/builder Step #2 - "detector": 5e0f2488a094: Already exists Step #2 - "detector": 07013743b8c6: Already exists Step #2 - "detector": 3c2cba919283: Already exists Step #2 - "detector": 3d34396a5442: Already exists Step #2 - "detector": 541e48a6a2b5: Already exists Step #2 - "detector": 34f928489dc6: Already exists Step #2 - "detector": 64208d02cb2c: Already exists Step #2 - "detector": 1b7c7906717c: Already exists Step #2 - "detector": 610bcfea19fe: Already exists Step #2 - "detector": fbad6c6a4dc9: Already exists Step #2 - "detector": 9c961dbc83b2: Already exists Step #2 - "detector": 584a50f27d83: Pulling fs layer Step #2 - "detector": 229c810fe4b6: Pulling fs layer Step #2 - "detector": 67f333b251cc: Pulling fs layer Step #2 - "detector": 67d3732ac306: Pulling fs layer Step #2 - "detector": fa3555d01e5c: Pulling fs layer Step #2 - "detector": 7cadee99477d: Pulling fs layer Step #2 - "detector": 8f7829806b7c: Pulling fs layer Step #2 - "detector": f6cfa6a7f25d: Pulling fs layer Step #2 - "detector": c5269ff7ab58: Pulling fs layer Step #2 - "detector": 52a8b2fcfc34: Pulling fs layer Step #2 - "detector": b59bca8d4380: Pulling fs layer Step #2 - "detector": 06f428a8446f: Pulling fs layer Step #2 - "detector": d77ba4498082: Pulling fs layer Step #2 - "detector": 2979886df2cc: Pulling fs layer Step #2 - "detector": afbfc3e27982: Pulling fs layer Step #2 - "detector": 27046f732e4e: Pulling fs layer Step #2 - "detector": 7a4302826804: Pulling fs layer Step #2 - "detector": eb078dded89c: Pulling fs layer Step #2 - "detector": c661568c601b: Pulling fs layer Step #2 - "detector": 8b4f47d49eb8: Pulling fs layer Step #2 - "detector": 4f4fb700ef54: Pulling fs layer Step #2 - "detector": 67d3732ac306: Waiting Step #2 - "detector": fa3555d01e5c: Waiting Step #2 - "detector": 7cadee99477d: Waiting Step #2 - "detector": 8f7829806b7c: Waiting Step #2 - "detector": f6cfa6a7f25d: Waiting Step #2 - "detector": c5269ff7ab58: Waiting Step #2 - "detector": 52a8b2fcfc34: Waiting Step #2 - "detector": b59bca8d4380: Waiting Step #2 - "detector": 06f428a8446f: Waiting Step #2 - "detector": d77ba4498082: Waiting Step #2 - "detector": 2979886df2cc: Waiting Step #2 - "detector": afbfc3e27982: Waiting Step #2 - "detector": 27046f732e4e: Waiting Step #2 - "detector": 7a4302826804: Waiting Step #2 - "detector": eb078dded89c: Waiting Step #2 - "detector": c661568c601b: Waiting Step #2 - "detector": 8b4f47d49eb8: Waiting Step #2 - "detector": 4f4fb700ef54: Waiting Step #2 - "detector": 584a50f27d83: Verifying Checksum Step #2 - "detector": 584a50f27d83: Download complete Step #2 - "detector": 229c810fe4b6: Verifying Checksum Step #2 - "detector": 229c810fe4b6: Download complete Step #2 - "detector": fa3555d01e5c: Verifying Checksum Step #2 - "detector": fa3555d01e5c: Download complete Step #2 - "detector": 584a50f27d83: Pull complete Step #2 - "detector": 7cadee99477d: Verifying Checksum Step #2 - "detector": 7cadee99477d: Download complete Step #2 - "detector": 229c810fe4b6: Pull complete Step #2 - "detector": 67d3732ac306: Verifying Checksum Step #2 - "detector": 67d3732ac306: Download complete Step #2 - "detector": 67f333b251cc: Verifying Checksum Step #2 - "detector": 67f333b251cc: Download complete Step #2 - "detector": 8f7829806b7c: Verifying Checksum Step #2 - "detector": 8f7829806b7c: Download complete Step #2 - "detector": c5269ff7ab58: Verifying Checksum Step #2 - "detector": c5269ff7ab58: Download complete Step #2 - "detector": f6cfa6a7f25d: Verifying Checksum Step #2 - "detector": f6cfa6a7f25d: Download complete Step #2 - "detector": 52a8b2fcfc34: Verifying Checksum Step #2 - "detector": 52a8b2fcfc34: Download complete Step #2 - "detector": 06f428a8446f: Verifying Checksum Step #2 - "detector": 06f428a8446f: Download complete Step #2 - "detector": b59bca8d4380: Verifying Checksum Step #2 - "detector": b59bca8d4380: Download complete Step #2 - "detector": 2979886df2cc: Verifying Checksum Step #2 - "detector": 2979886df2cc: Download complete Step #2 - "detector": d77ba4498082: Verifying Checksum Step #2 - "detector": d77ba4498082: Download complete Step #2 - "detector": afbfc3e27982: Verifying Checksum Step #2 - "detector": afbfc3e27982: Download complete Step #2 - "detector": 27046f732e4e: Verifying Checksum Step #2 - "detector": 27046f732e4e: Download complete Step #2 - "detector": eb078dded89c: Verifying Checksum Step #2 - "detector": eb078dded89c: Download complete Step #2 - "detector": 7a4302826804: Verifying Checksum Step #2 - "detector": 7a4302826804: Download complete Step #2 - "detector": c661568c601b: Verifying Checksum Step #2 - "detector": c661568c601b: Download complete Step #2 - "detector": 4f4fb700ef54: Verifying Checksum Step #2 - "detector": 4f4fb700ef54: Download complete Step #2 - "detector": 67f333b251cc: Pull complete Step #2 - "detector": 8b4f47d49eb8: Verifying Checksum Step #2 - "detector": 8b4f47d49eb8: Download complete Step #2 - "detector": 67d3732ac306: Pull complete Step #2 - "detector": fa3555d01e5c: Pull complete Step #2 - "detector": 7cadee99477d: Pull complete Step #2 - "detector": 8f7829806b7c: Pull complete Step #2 - "detector": f6cfa6a7f25d: Pull complete Step #2 - "detector": c5269ff7ab58: Pull complete Step #2 - "detector": 52a8b2fcfc34: Pull complete Step #2 - "detector": b59bca8d4380: Pull complete Step #2 - "detector": 06f428a8446f: Pull complete Step #2 - "detector": d77ba4498082: Pull complete Step #2 - "detector": 2979886df2cc: Pull complete Step #2 - "detector": afbfc3e27982: Pull complete Step #2 - "detector": 27046f732e4e: Pull complete Step #2 - "detector": 7a4302826804: Pull complete Step #2 - "detector": eb078dded89c: Pull complete Step #2 - "detector": c661568c601b: Pull complete Step #2 - "detector": 8b4f47d49eb8: Pull complete Step #2 - "detector": 4f4fb700ef54: Pull complete Step #2 - "detector": Digest: sha256:268a9ef00dd901e5f207edd928a7e0ee18c1b62d7868b03211e566eb1c90296c Step #2 - "detector": Status: Downloaded newer image for us.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20200711_12_18_2_RC00 Step #2 - "detector": us.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20200711_12_18_2_RC00 Step #2 - "detector": ======== Output: google.nodejs.yarn-gcp-build@0.9.0 ======== Step #2 - "detector": yarn.lock not found. Step #2 - "detector": ======== Output: google.nodejs.yarn@0.9.0 ======== Step #2 - "detector": yarn.lock not found. Step #2 - "detector": ======== Results ======== Step #2 - "detector": skip: google.nodejs.yarn-gcp-build@0.9.0 Step #2 - "detector": fail: google.nodejs.yarn@0.9.0 Step #2 - "detector": pass: google.nodejs.appengine@0.9.0 Step #2 - "detector": ======== Output: google.nodejs.npm-gcp-build@0.9.0 ======== Step #2 - "detector": gcp-build script not found in package.json. Step #2 - "detector": ======== Results ======== Step #2 - "detector": skip: google.nodejs.npm-gcp-build@0.9.0 Step #2 - "detector": pass: google.nodejs.npm@0.9.0 Step #2 - "detector": pass: google.nodejs.appengine@0.9.0 Step #2 - "detector": Resolving plan... (try #1) Step #2 - "detector": 2 of 3 buildpacks participating Step #2 - "detector": google.nodejs.npm 0.9.0 Step #2 - "detector": google.nodejs.appengine 0.9.0 Finished Step #2 - "detector" Starting Step #3 - "analyzer" Step #3 - "analyzer": Already have image (with digest): us.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20200711_12_18_2_RC00 Step #3 - "analyzer": ERROR: failed to initialize cache: failed to create image cache: accessing cache image "us.gcr.io/myapp/app-engine-tmp/build-cache/ttl-7d/default/buildpack-cache:latest": connect to repo store 'us.gcr.io/myapp/app-engine-tmp/build-cache/ttl-7d/default/buildpack-cache:latest': GET https://us.gcr.io/v2/myapp/app-engine-tmp/build-cache/ttl-7d/default/buildpack-cache/manifests/latest: DENIED: Permission denied for "latest" from request "/v2/myapp/app-engine-tmp/build-cache/ttl-7d/default/buildpack-cache/manifests/latest". Finished Step #3 - "analyzer" ERROR ERROR: build step 3 "us.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20200711_12_18_2_RC00" failed: step exited with non-zero status: 1
  • 将私钥ssh-keygen -f deploy_key -N ""的base64编码内容复制到Amplify项目环境变量中。例如。 DEPLOY_KEY
  • 将您的公共密钥cat deploy_key | base64 -w0的内容复制到您的〜/ .ssh / authorized_keys中(取决于您的存储库提供者,在我们的案例中,Bitbucket的存储库设置中的访问密钥)
  1. 在amplify.yml的preBuild或build部分中,添加以下内容:
cat deploy_key.pub