在构建期间,将文件从GCS复制到云运行docker容器中
我试图在构建步骤中使用在构建期间,将文件从GCS复制到云运行docker容器中,docker,google-cloud-platform,google-cloud-storage,google-cloud-run,Docker,Google Cloud Platform,Google Cloud Storage,Google Cloud Run,我试图在构建步骤中使用gsutil将文件从GCS复制到运行容器中 我尝试过的步骤: RUN pip install gsutil RUN gsutil -m cp -r gs://BUCKET_NAME $APP_HOME/artefacts 错误: ServiceException: 401 Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object. Command
gsutil
将文件从GCS复制到运行容器中
我尝试过的步骤:
RUN pip install gsutil
RUN gsutil -m cp -r gs://BUCKET_NAME $APP_HOME/artefacts
错误:
ServiceException: 401 Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.
CommandException: 1 file/object could not be transferred.
The command '/bin/sh -c gsutil -m cp -r gs://BUCKET_NAME $APP_HOME/artefacts' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
服务帐户(默认的compute&cloudbuild)确实可以访问GCS,我也尝试了gsutil config-a
和各种其他标志,但没有成功
我不确定如何通过身份验证才能成功访问bucket。我看到您标记了Cloud Build 您可以使用如下步骤:
steps:
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://mybucket/results.zip', 'previous_results.zip']
# operations that use previous_results.zip and produce new_results.zip
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'new_results.zip', 'gs://mybucket/results.zip']
我看到你标记了云构建 您可以使用如下步骤:
steps:
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://mybucket/results.zip', 'previous_results.zip']
# operations that use previous_results.zip and produce new_results.zip
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'new_results.zip', 'gs://mybucket/results.zip']
这是我的github行动任务
jobs:
build:
name: Build image
runs-on: ubuntu-latest
env:
BRANCH: ${GITHUB_REF##*/}
SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v2
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }}
project_id: ${{ secrets.PROJECT_ID }}
export_default_credentials: true
# Download the file locally
- name: Get_file
run: |-
gsutil cp gs://BUCKET_NAME/path/to/file .
# Build docker image
- name: Image_build
run: |-
docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME .
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
gcloud auth configure-docker -q
# Push image to Google Container Registry
- name: Image_push
run: |-
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME
你必须设定3个秘密:
- 服务帐户密钥:哪一个是您的服务帐户密钥文件
- 服务名称:容器的名称
- PROJECT\u ID:要在其中部署映像的项目
更新 如果你想在docker中这样做,你可以这样做 Dockerfile
FROM google/cloud-sdk:alpine as gcloud
WORKDIR /app
ARG KEY_FILE_CONTENT
RUN echo $KEY_FILE_CONTENT | gcloud auth activate-service-account --key-file=- \
&& gsutil cp gs://BUCKET_NAME/path/to/file .
....
FROM <FINAL LAYER>
COPY --from=gcloud /app/<myFile> .
....
您的密钥文件内容取决于您的环境。下面是一些注入它的解决方案:
- 关于Github操作:
${{secrets.SERVICE\u ACCOUNT\u KEY}
- 在本地环境中:
$(cat my_key.json)
jobs:
build:
name: Build image
runs-on: ubuntu-latest
env:
BRANCH: ${GITHUB_REF##*/}
SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v2
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }}
project_id: ${{ secrets.PROJECT_ID }}
export_default_credentials: true
# Download the file locally
- name: Get_file
run: |-
gsutil cp gs://BUCKET_NAME/path/to/file .
# Build docker image
- name: Image_build
run: |-
docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME .
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
gcloud auth configure-docker -q
# Push image to Google Container Registry
- name: Image_push
run: |-
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME
你必须设定3个秘密:
- 服务帐户密钥:哪一个是您的服务帐户密钥文件
- 服务名称:容器的名称
- PROJECT\u ID:要在其中部署映像的项目
更新 如果你想在docker中这样做,你可以这样做 Dockerfile
FROM google/cloud-sdk:alpine as gcloud
WORKDIR /app
ARG KEY_FILE_CONTENT
RUN echo $KEY_FILE_CONTENT | gcloud auth activate-service-account --key-file=- \
&& gsutil cp gs://BUCKET_NAME/path/to/file .
....
FROM <FINAL LAYER>
COPY --from=gcloud /app/<myFile> .
....
您的密钥文件内容取决于您的环境。下面是一些注入它的解决方案:
- 关于Github操作:
${{secrets.SERVICE\u ACCOUNT\u KEY}
- 在本地环境中:
$(cat my_key.json)