Jim
Jim

Reputation: 239

I am using pycharm and cloud run plugin to deploy flask app to GCP on a Mac M1 and am getting exec format errors (only in cloud)

The code is the hello world app that comes with pycharm for flask apps, very simple build. When deploying to the local test container all is fine, when deploying to Cloud Run it builds a container locally and pushes it to the google repository (error free and seemingly ok) but fails when it tries to deploy in the end with an error

{ "textPayload": "terminated: Application failed to start: Failed to create init process: failed to load /usr/local/bin/python: exec format error", "insertId": "605e2de200094a2b42066c2b", "resource": { "type": "cloud_run_revision", "labels": { "revision_name": "insight-sync-00017-wur", "service_name": "insight-sync", "location": "europe-west2", "configuration_name": "insight-sync", "project_id": "insights-307616" } }, "timestamp": "2021-03-26T18:54:26.608749033Z", "severity": "ERROR", "labels": { "instanceId": "00bf4bf02d2807cc6001caa2eabfd154d00fbbfa3fb6b2b2e32d286040ae12bb7480bdaf6f72d62a612cc98c55abd3364155aec51e087180851f0c02bd" }, "logName": "projects/insights-307616/logs/run.googleapis.com%2Fvarlog%2Fsystem", "receiveTimestamp": "2021-03-26T18:54:26.613237692Z" }

If i launch the image locally (on the M1) from the docker dashboard and connect to it via terminal, the /usr/bin/local/python loads fine which indicates to me that the container or environment is not suitable for GCP itself but works on the M1.

I've looked a bit at buildx but am stuck with how to integrate that into the pycharm and GCP cloud run plugin... any assistance would be greatly appreciated in how to get past this.

Thanks in advance

Upvotes: 2

Views: 1326

Answers (1)

Jim
Jim

Reputation: 239

Thanks to John Hanley for the lead... The problem was that the docker image generated was for ARM and GCP required an AMD image. And there was no way to tell the pyCharm "Cloud Code" plugin to build for that when deploying to the cloud.

In the end the solution was to do all the testing locally and then deploy using the following commands in sequence... replace "docker_user/dockerproject" with your own credentials and "gcrname/project" with your gcr names:

do this once

docker buildx create --name mybuilder

docker buildx use mybuilder

docker buildx inspect --bootstrap

(from docker_docs)

Then from the working directory for a build and deploy do:

docker buildx build --platform linux/amd64 -t docker_user/dockerproject:latest --push .

(very important, while buildx lets you make multi architecture builds by specifying multiple items after --platform you do not want to to this if deploying to GCP.... GCP does not run these, so only specify one platform. This will mean that the container will not run on your M1 mac, but you can build a different copy for testing, so not a big deal)

docker buildx imagetools inspect docker_user/dockerproject:latest

docker pull docker_user/dockerproject:latest

docker tag docker_user/dockerproject:latest gcr.io/gcrname/project

docker push gcr.io/gcrname/project

(from Google docs )

(this command will note that it is pushing to gcr - you may need to set auth credentials for this in docker - another topic)

And finally:

(you can get this command by attempting to deploy via cloudrun in pyCharm, it is much nicer than the interactive process from the registry page in GCP admin)....

gcloud run deploy --quiet --image gcr.io/gcrname/project --platform managed --project --service-account --memory 256Mi --timeout 300 --concurrency 80 --max-instances 1000 --cpu 1 --clear-env-vars --clear-cloudsql-instances --client-name "Cloud Code for IntelliJ" --client-version 21.2.3-202 --region europe-west2 --allow-unauthenticated

But I am still hoping to see a revision of the plugin to make this simpler... now back to what I was trying to deploy :)

Upvotes: 3

Related Questions