使用 github 操作在云运行中找不到图像

问题描述 投票:0回答:1

我可以将 docker 映像推送到工件注册表标记也工作正常,但是当我尝试使用日期标记执行时,它会出现以下错误

我在做什么

Building docker image
push to artifacts registry
from artifacts registry its deploy to cloud run at this stage im getting below error in github action
google-github-actions/deploy-cloudrun failed with: failed to execute gcloud command `gcloud run deploy hello-cloud-run --quiet --image us-central1-docker.pkg.dev/***/samples/static-site:$(date "+%F-%H%M")' --update-labels managed-by=github-actions,commit-sha=1b8c7bxxx0cca6dxxxxxxa3e7d7xxxf3d7 --platform managed --format json --region asia-south1 --port 80 --allow-unauthenticated`: Deploying container to Cloud Run service [hello-cloud-run] in project [***] region [asia-south1]
Deploying...
Setting IAM Policy..............................................done
Creating Revision.........................done
Routing traffic....failed
Deployment failed
ERROR: (gcloud.run.deploy) Revision 'hello-cloud-run-00017-6dh' is not ready and cannot serve traffic. Image 'us-central1-docker.pkg.dev/***/samples/static-site:$(date "+%F-%H%M")'' not found.

这是我的 github 操作的 yaml 文件

name: Build and Deploy to Cloud Run
on:
   push:
     branches: [ "master" ]

   workflow_dispatch:

env:
  PROJECT_ID: ${{ secrets.GKE_PROJECT }}
  REPOSITORY: samples                       # Add your repository name here.
  GAR_LOCATION: xxxx                        # Add your repository region name here.
  IMAGE_NAME: static-site                   # Add your image name here.
  IMAGE_TAG: $(date "+%F-%H%M")             # Add your image date-tag name here

### Build and Push the Docker image to Google Artifact Registry (GAR) ###
    - name: Build and Push to Artifact Registry
      run: |-
        docker build -t ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
        docker tag ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} us-central1-docker.pkg.dev/${{ secrets.GKE_PROJECT }}/samples/static-site:${{ env.IMAGE_TAG }}                                                                                                
        #docker push us-central1-docker.pkg.dev/${{ secrets.GKE_PROJECT }}/samples/static-site:${{ github.sha }}
        docker push ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
                    

### Get the Deploying Container to Gooogle Cloud RUN ###
    - name: Deploy to Cloud RUN (hello-cloud-run) 
      id: 'deploy1'
      uses: 'google-github-actions/deploy-cloudrun@v2'
      with:
        service: 'hello-cloud-run'
        region: 'asia-south1'
        flags: '--port=80 --allow-unauthenticated'
      #  image: 'us-central1-docker.pkg.dev/xxxxxx/samples/static-site:2023-12-06-1853'
      #  image: 'us-central1-docker.pkg.dev/${{ secrets.GKE_PROJECT }}/samples/static-site:${{ env.IMAGE_TAG }}'
        image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}'
        
    - name: 'Show output'
     # run: 'curl "${{ steps.deploy.outputs.url }}"'
      run: echo ${{ steps.deploy.outputs.url }}

### Get the Deploying Container to Gooogle Cloud RUN ###
    - name: Deploy to Cloud RUN (ui-services)
      id: 'deploy2'
      uses: 'google-github-actions/deploy-cloudrun@v2'
      with:
        service: 'ui-services'
        region: 'europe-west2'
        flags: '--port=80 --allow-unauthenticated'
        image: 'us-central1-docker.pkg.dev/${{ secrets.GKE_PROJECT }}/samples/static-site:${{ env.IMAGE_TAG }}'

    - name: 'Show output'
     # run: 'curl "${{ steps.deploy.outputs.url }}"'
      run: echo ${{ steps.deploy.outputs.url }}

我不想手动使用此图像日期标签

image: 'us-central1-docker.pkg.dev/xxxxxx/samples/static-site:2023-12-06-1853'

它应该使用日期标签自动生成,如下所示

image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}'
github google-cloud-platform github-actions cloud google-cloud-run
1个回答
0
投票

我使用 gcloud 命令,它开始工作了

旧的

### Get the Deploying Container to Gooogle Cloud RUN ###
    - name: Deploy to Cloud RUN 
      id: 'deploy2'
      uses: 'google-github-actions/deploy-cloudrun@v2'
      with:
        service: 'ui-services'
        region: 'europe-west2'
        flags: '--port=80 --allow-unauthenticated'
        image: 'us-central1-docker.pkg.dev/${{ secrets.GKE_PROJECT }}/samples/static-site:${{ env.IMAGE_TAG }}'

新的(替换上面的)

### Get the Deploying Container to Gooogle Cloud RUN ###
      - name: Deploy to Cloud Run
        run: |
           gcloud run deploy ${{ env.GCR_SERVICE }} \
             --image ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ env.IMAGE_TAG }} \
             --region ${{ env.GCR_REGION }} \
             --platform managed \
             --allow-unauthenticated \
             --port=8080 \
             --timeout=3600 \
             --update-labels commit-sha=${{ github.sha }}
© www.soinside.com 2019 - 2024. All rights reserved.