Can't deploy container to GCE, using gcloud compute instances update-container, because of YML parse error

This issue has been tracked since 2022-05-16.

TL;DR

I am writing a Github Workflow that will build and push the docker container to GCR and then to the VM instance on GCE. But the deployment stage of GCE gives out the following error:

Run gcloud compute instances update-container "$GCE_INSTANCE" \
  gcloud compute instances update-container "$GCE_INSTANCE" \
    --zone "$GCE_INSTANCE_ZONE" \
    --container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
    
  shell: /usr/bin/bash -e ***0***
  env:
   ...

ERROR: (gcloud.compute.instances.update-container) Failed to parse YAML: mapping values are not allowed here
  in "<unicode string>", line 5, column 18:
                image: 'gcr.io/cloud-marketplace/goog ... 
                     ^ (line: 5)
Error: Process completed with exit code 1.

Expected behavior

gloud compute instances update-container should update the container on VM.

Observed behavior

Instead returns an error related to parsing of YML.

ERROR: (gcloud.compute.instances.update-container) Failed to parse YAML: mapping values are not allowed here
  in "<unicode string>", line 5, column 18:
                image: 'gcr.io/cloud-marketplace/goog ... 
                     ^ (line: 5)
Error: Process completed with exit code 1.

Action YAML

name: Build and Deploy to Google Compute Engine (one more time, yes)

on:
  push:
    branches:
    - 'main'

env:
  PROJECT_ID: ***
  GCE_INSTANCE: ***
  GCE_INSTANCE_ZONE: ***

jobs:
  setup-build-publish-deploy:
    name: Setup, Build, Publish, and Deploy
    runs-on: ubuntu-latest

    # Add "id-token" with the intended permissions.
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
    # Checkout Action
    - name: Checkout
      uses: actions/checko[email protected]

    # Authentication via credentials json
    - id: 'auth'
      uses: 'google-github-actions/[email protected]'
      with:
        credentials_json: '${{ secrets.GCP_SA_KEY }}'

    # Setup gcloud CLI
    - name: Set up Cloud SDK
      uses: google-github-actions/[email protected]

    # Configure Docker to use the gcloud command-line tool as a credential helper for authentication
    - run: |-
        gcloud --quiet auth configure-docker
    
    # Build the Docker image
    - name: Build
      run: |-
        docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" ./path/to/Dockerfile
    
    # Push the Docker image to Google Container Registry
    - name: Publish
      run: |-
        docker push "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
    
    # Add pruning and IP address update to VM startup script
    - name: Update startup script to prune and update IP address
      run: |-
        gcloud compute instances add-metadata $GCE_INSTANCE \
          --zone "$GCE_INSTANCE_ZONE" \
          --metadata=startup-script="#! /bin/bash
            docker image prune -af"
    
    # Deploy the Docker image to GCE
    - name: Deploy
      run: |-
        gcloud compute instances update-container "$GCE_INSTANCE" \
          --zone "$GCE_INSTANCE_ZONE" \
          --container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
          
    # Purge old images from GCR (not latest)
    - name: Purge GCR images
      run: |-
        gcloud container images list-tags gcr.io/$PROJECT_ID/$GCE_INSTANCE-image \
          --format="get(digest)" --filter="NOT tags=$GITHUB_SHA" | \
          awk -v image_path="gcr.io/$PROJECT_ID/[email protected]" '{print image_path $1}' | \
          xargs -r gcloud container images delete --force-delete-tags --quiet

Log output

https://github.com/OpenAIMP/qunsultant/runs/6445584217?check_suite_focus=true

Additional information

Earlier this same YML file worked fine and Container was updated on VM

sethvargo wrote this answer on 2022-05-16

Hi @HaiderSultanArc

Are you sure that's the action.yml file? The error message does not seem to correspond to given action.yml. It's referencing gcr.io/cloud-marketplace/..., which I do not see in your action.yml anywhere. Is this issue still happening?

HaiderSultanArc wrote this answer on 2022-05-16

@sethvargo thanks for the reply and, yes this is the yml file. I don't understand the nature of this error. I know it is in the gloud compute instances update-container command.

I don't know the internal working of the command. It takes these attributes and the format is perfectly fine. But it gives an error related to mapping values or parsing of yml or something.

sethvargo wrote this answer on 2022-05-16

@HaiderSultanArc what happens when you run the command locally?

HaiderSultanArc wrote this answer on 2022-05-16

@sethvargo it gives the exact same error locally on my terminal as well

sethvargo wrote this answer on 2022-05-17

Hi @HaiderSultanArc that points to an issue with your configuration or potentially a gcloud bug. If you have a Google support contract, you can open a case. If you do not have a support contract, see https://cloud.google.com/support/docs/issue-trackers for filing a bug.

Since this doesn't seem related to the GitHub Action, I'll close this out.

HaiderSultanArc wrote this answer on 2022-05-17

@sethvargo thanks for the coordination.

More Details About Repo
Owner Name google-github-actions
Repo Name setup-gcloud
Full Name google-github-actions/setup-gcloud
Language TypeScript
Created Date 2019-11-05
Updated Date 2023-03-23
Star Count 1505
Watcher Count 65
Fork Count 548
Issue Count 11

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date