CloudBuild-execラッパーを使用してCloudSQL Proxy +その他のGCPリソースに接続する際の認証情報エラー

しなければならなかった

exec-wrapperクラウドビルドステップでを使用してクラウドSQLプロキシを実行し、ノードスクリプトを実行してカスタムデータベース移行を実行しようとしています。クラウドビルド構成は次のようになります。

steps:
- name: gcr.io/cloud-builders/docker
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/api-stg', '.']
- name: gcr.io/cloud-builders/docker
  args: ['push', 'gcr.io/$PROJECT_ID/api-stg']
- name: gcr.io/cloud-builders/gcloud
  args: ['app', 'deploy', 'app-stg.yaml', '--image-url=gcr.io/$PROJECT_ID/api-stg']
- name: "gcr.io/google-appengine/exec-wrapper"
  args: ["-i", "gcr.io/$PROJECT_ID/api-stg",
         "-s", "$PROJECT_ID:us-central1:<Cloud SQL Instance Name>",
         "--", "scripts/management/custom_migration"]

images: ['gcr.io/$PROJECT_ID/api-stg']
timeout: 1200s # 20 minutes

そして私のcustom_migration.jsファイルには次のようなものがあります:

const {Storage} = require('@google-cloud/storage');

const storage = new Storage();
const bucket = storage.bucket(BUCKET_NAME);
const file = await bucket.file(key);
const result = await new Promise(resolve => file.download((err, data) => {...}));
...

これにより、次のエラーが発生しますgoogle-auth-library

Error: The file at /root/.google/credentials does not exist, or it is not a file. 
Error: ENOENT: no such file or directory, lstat '/root/.google'

My App Engine Flexible環境では、新しいバージョンでデプロイしたときにこのコードを実行できますが、クラウドビルドステップの同じコードが正しく認証されていません。exec-wrapperがAppEngineフレキシブル環境のデフォルトの認証情報を使用できるようにするにはどうすればよいですか?

ギヨームブラキエール

このステップは私のために働きます

steps:
  - name: 'node:14-alpine'
    entrypoint: 'sh'
    args:
      - -c
      - |
        wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
        chmod +x cloud_sql_proxy
        ./cloud_sql_proxy -instances=my-project-id:us-central1:vertx=tcp:5432 &
        npm install @google-cloud/storage pg
        node index-test.js

カスタムコンテナの内容がわからないので、このようなものを適応させることができます

steps:
  - name: 'gcr.io/$PROJECT_ID/api-stg'
    entrypoint: 'sh'
    args:
      - -c
      - |
        wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
        chmod +x cloud_sql_proxy
        ./cloud_sql_proxy -instances=my-project-id:us-central1:vertx=tcp:5432 &
        npm install @google-cloud/storage pg
        node scripts/management/custom_migration

標準ライブラリの問題については、AppEngine環境とCloudBuild環境の競合だと思います。

Google Authライブラリを見ると、App Engine認証情報のケースと、Compute認証情報のケースがわかります。コンピューティングは、すべてのGoogle Cloudサービス(Cloud Run、Cloud Functions、Compute Engine、Cloud Buildなど)で標準で使用されますが、AppEngineには固有の機能があります。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ