I'm currently trying to build a python 3.10 application using VSCode and want to deploy the application to Cloud Run soon. Google conveniently has a Cloud Code plugin that is supposed to help with debugging and deployment of my code, but I'm having huge issues getting those tools to work. I'm on an M1 Mac, and I'm running into the following issues with starting the "Debug on Cloud Emulator" command in VSCode.
Logs from "Cloud Run: Run / Debug Locally"
Starting to debug 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/(username)/Developer/(project title)/.vscode/launch.json
Configuring minikube gcp-auth addon
Using GCP project '(project-id)' with minikube gcp-auth
Update initiated
Deploy started
Deploy completed
Status check started
Resource pod/myprojectapi-59898fbd97-m2npp status updated to In Progress
Resource deployment/myprojectapi status updated to In Progress
Resource pod/myprojectapi-59898fbd97-m2npp 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.
Logs from: Cloud Run: Run/Debug Locally - Detailed
Running skaffold command: /Users/userName/Library/Application Support/cloud-code/installer/google-cloud-sdk/bin/skaffold init --artifact {"image":"myProjectName","builder":"Docker","payload":{"path":"/Users/userName/Developer/myProjectName/Dockerfile"}} --kubernetes-manifest /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/pods_and_services.yaml --filename /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/skaffold.yaml --force
Setting build tagPolicy to SHA256.
Setting statusCheckDeadlineSeconds to 5 minutes
Setting build environment to 'local'
Created the file /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/skaffold.yaml.
Running gcloud command: /Users/userName/Library/Application Support/cloud-code/installer/google-cloud-sdk/bin/gcloud beta code export --readiness-probe --service-name myProjectName --image myProjectName --no-skaffold-file --dockerfile= --kubernetes-file /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/pods_and_services.yaml --env-vars K_SERVICE=myProjectName,K_REVISION=local,K_CONFIGURATION=myProjectName --service-account myServiceAccount --memory 256Mi --cpu 1 --quiet
Created the file /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/pods_and_services.yaml.
Running: skaffold debug -v info --port-forward --auto-build --auto-deploy --auto-sync --rpc-http-port 60515 --filename /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU/skaffold.yaml --kube-context cloud-run-dev-internal --minikube-profile cloud-run-dev-internal --status-check
Activated kube-context \"cloud-run-dev-internal\"
starting gRPC server on port 60955
starting gRPC HTTP server on port 60515 (proxying to 60955)
Skaffold &{Version:v1.36.0 ConfigVersion:skaffold/v2beta27 GitVersion: GitCommit:189a55291c18ac850277134d2b8f3eaa2c4f7a1d BuildDate:2022-02-09T17:07:58Z GoVersion:go1.17 Compiler:gc Platform:darwin/arm64 User:}
Loaded Skaffold defaults from \"/Users/userName/.skaffold/config\"
map entry found when executing locate for &{myProjectName /Users/userName/Developer/myProjectName <nil> {0x14000901550 <nil> <nil> <nil> <nil> <nil> <nil>} [] {[] []} []} of type *v1.Artifact and pointer: 1374391882240
Using kubectl context: cloud-run-dev-internal
Using minikube docker daemon at tcp://127.0.0.1:57168
build concurrency first set to 1 parsed from *local.Builder[0]
final build concurrency value is 1
Listing files to watch...
- myProjectName
List generated in 750.142584ms
Tags generated in 125.458µs
Generating tags...
- myProjectName -> myProjectName
Checking cache...
- myProjectName: Found Locally
Cache check completed in 311.094208ms
Tags used in deployment:
- myProjectName -> myProjectName:38ccca2ec01409d9578c2e6c21ed41751bd30e8bea584db725dcabbbde553670
Starting deploy...
Configuring \"\" for python debugging
\"myProjectName-container\" requires debugging support image \"python\"
Configuring installation of debugging support files
- Warning: spec.template.spec.containers[0].env[4].name: duplicate name "K_CONFIGURATION"
- Warning: spec.template.spec.containers[0].env[5].name: duplicate name "K_REVISION"
- Warning: spec.template.spec.containers[0].env[6].name: duplicate name "K_SERVICE"
- deployment.apps/myProjectName created
- service/myProjectName created
- secret/local-development-credential created
Deploy completed in 4.155 seconds
Waiting for deployments to stabilize...
- deployment/myProjectName: waiting for rollout to finish: 0 out of 1 new replicas have been updated...
- deployment/myProjectName: waiting for init container install-python-debug-support to complete
- pod/myProjectName-74f95d485c-4lxbs: waiting for init container install-python-debug-support to complete
> Error retrieving logs for pod myProjectName-74f95d485c-4lxbs: exit status 1.
Try `kubectl logs myProjectName-74f95d485c-4lxbs -n default -c install-python-debug-support`
- deployment/myProjectName: container myProjectName-container terminated with exit code 1
- pod/myProjectName-74f95d485c-4lxbs: container myProjectName-container terminated with exit code 1
> Error retrieving logs for pod myProjectName-74f95d485c-4lxbs: exit status 1.
Try `kubectl logs myProjectName-74f95d485c-4lxbs -n default -c myProjectName-container`
- deployment/myProjectName failed. Error: container myProjectName-container terminated with exit code 1.
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.
Cleaning up...
- deployment.apps "myProjectName" deleted
- service "myProjectName" deleted
- secret "local-development-credential" deleted
Cleanup completed in 646.769084ms
1/1 deployment(s) failed
Skaffold exited with code 1.
Cleaning up...
Deleted the temporary directory /var/folders/zl/jcdnyvrn7f7995yb8zvsfyqw0000gp/T/cloud-code-cloud-run-pRacQU.
Dockerfile:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.10-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy the requirements to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY requirements.txt ./
# Install production dependencies as per requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy over the rest of our files
COPY . ./
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "myProjectName:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"dockerRun": {
"env": {
"FLASK_APP": "venv/lib/python3.9/site-packages/flask/app.py"
}
},
"python": {
"args": [
"run",
"--no-debugger",
"--no-reload",
"--host",
"0.0.0.0",
"--port",
"5002"
],
"module": "flask"
}
}
]
}
launch.json
{
"configurations": [
{
"name": "Cloud Run: Run/Debug Locally",
"type": "cloudcode.cloudrun",
"request": "launch",
"build": {
"docker": {
"path": "Dockerfile"
}
},
"image": "myProjectName",
"service": {
"name": "myProjectName",
"containerPort": 8080,
"serviceAccountName": "myServiceAccount",
"addCloudSqlInstances": [
"myCloudsqlInstance"
],
"resources": {
"limits": {
"cpu": 1,
"memory": "256Mi"
}
}
},
"target": {
"minikube": {}
},
"watch": true
}
]
}
I've been playing around with the tasks.json file (have tried to add custom options like "--platform linux/amd64", but nothing has worked. Any help would be hugely appreciated.
CodePudding user response:
Remove the exec
from the CMD exec
: this unfortunately throws off skaffold debug
. Normally the Detailed channel will include some logs to indicate this, like:
Waiting for deployments to stabilize...
- pods: waiting for init container install-python-debug-support to start
- pod/python3: waiting for init container install-python-debug-support to start
- pods: container python3-web terminated with exit code 1
- pod/python3: container python3-web terminated with exit code 1
> [python3 python3-web] time="2022-03-08T15:24:02Z" level=warning msg="unable to determine launcher: could not find launcher \"exec\": exec: \"exec\": executable file not found in $PATH"
> [python3 python3-web] time="2022-03-08T15:24:02Z" level=fatal msg="error launching python debugging: exec: \"exec\": executable file not found in $PATH"
- pods failed. Error: container python3-web terminated with exit code 1.
But this seems more hit-and-miss with the Cloud Run emulator where I usually see logs like:
Waiting for deployments to stabilize...
Deploy completed in 2.538 seconds
- deployment/t: waiting for init container install-python-debug-support to start
- pod/t-7677684866-kbrlx: waiting for init container install-python-debug-support to start
- deployment/t: container t-container terminated with exit code 1
- pod/t-7677684866-kbrlx: container t-container terminated with exit code 1
> Error retrieving logs for pod t-7677684866-kbrlx: exit status 1.
Try `kubectl logs t-7677684866-kbrlx -n default -c t-container`
- deployment/t failed. Error: container t-container terminated with exit code 1.
We've been leery of command-line rewriting to remove exec
like this, but it's worth revisiting. I've opened https://github.com/GoogleContainerTools/skaffold/issues/7168 to track.