Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HaiderSultanArc opened this issue May 16, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@HaiderSultanArc
Copy link

HaiderSultanArc commented May 16, 2022

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/checkout@v3

    # Authentication via credentials json
    - id: 'auth'
      uses: 'google-github-actions/auth@v0'
      with:
        credentials_json: '${{ secrets.GCP_SA_KEY }}'

    # Setup gcloud CLI
    - name: Set up Cloud SDK
      uses: google-github-actions/setup-gcloud@v0

    # 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/$GCE_INSTANCE-image@" '{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

@HaiderSultanArc HaiderSultanArc added the bug Something isn't working label May 16, 2022
@sethvargo
Copy link
Member

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
Copy link
Author

@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
Copy link
Member

@HaiderSultanArc what happens when you run the command locally?

@HaiderSultanArc
Copy link
Author

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

@sethvargo
Copy link
Member

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
Copy link
Author

@sethvargo thanks for the coordination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants