visual-studio-codegoogle-cloud-platformgoogle-cloud-rungoogle-cloud-code

Unable to start a Cloud Run container on M1 Macbook


I haven't installed Rosetta on my M1 Macbook. Have Docker and all deps installed and this even worked a few times but not sure what caused this error suddenly:

Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Starting minikube, this may take a while.............
minikube successfully started
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration /Users/myname/Code/myprojectAPI/.vscode/launch.json
Configuring minikube gcp-auth addon
Using GCP project 'myproject-com' with minikube gcp-auth


Update initiated
Build started for artifact myprojectapi
Build completed for artifact myprojectapi

Deploy started
Deploy completed

Status check started
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource pod/myprojectapi-8695998b94-9lk7d status updated to In Progress
Resource deployment/myprojectapi status failed with waiting for rollout to finish: 0 of 1 updated replicas are available...
Status check failed

The image was built but failed to start on the cluster. Because you are on an ARM64 machine, it is likely that you built an ARM64 image for an x86_64 cluster.
Update failed with error code STATUSCHECK_CONTAINER_TERMINATED
1/1 deployment(s) failed
Skaffold exited with code 1.
Cleaning up...
Finished clean up.

Dockerfile:

FROM gcr.io/google.com/cloudsdktool/cloud-sdk:slim

RUN set -ex; \
  apt-get -y update; \
  curl -fsSL https://deb.nodesource.com/setup_17.x | bash -; \
  apt-get -y install nodejs; \
  apt-get -y install ghostscript; \
  apt-get -y install pngquant; \
  rm -rf /var/lib/apt/lists/*

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install dependencies.
# If you add a package-lock.json speed your build by switching to 'npm ci'.
RUN npm ci --only=production
# RUN npm install --production


# Copy local code to the container image.
COPY . ./

# Run the web service on container startup.
CMD [ "npm", "start" ]

I'm doing 'Cloud Run Emulator' deploy in VS Code using the Cloud Code extension.

What am I doing wrong?


Solution

  • I can confirm that the gcr.io/google.com/cloudsdktool/cloud-sdk:slim image used in your Dockerfile is an x86_64 image, which is incompatible with an ARM64-based M1 Mac. Since CloudSDK does not currently have any ARM64-based images, creating your own base image with CloudSDK will be necessary. The steps to do that are:

    1. Update the line in your Dockerfile pointing to gcr.io/google.com/cloudsdktool/cloud-sdk:slim to a new base image (debian:buster-slim for example)
    2. Install the CloudSDK tooling onto the image. It should look something like this in your Dockerfile:
    # Downloads the gCloud package
    RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
    
    # Installs the package
    RUN mkdir -p /usr/local/gcloud \
      && tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz \
      && /usr/local/gcloud/google-cloud-sdk/install.sh --quiet
    
    # Adds the package path to local
    ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
    

    Once those steps have run, you should be left with a new base image with CloudSDK installed! If you're curious about some of the context or additional configuration options, please take a look at the Docker documentation page about multi-arch support