从 M1 Mac 为 Cloud Code "Debug on Cloud Run Emulator" 构建 x86_64 图像
Build x86_64 image for Cloud Code's "Debug on Cloud Run Emulator" from M1 Mac
我目前正在尝试使用 VSCode 构建一个 python 3.10 应用程序,并希望尽快将该应用程序部署到云端 运行。 Google 有一个 Cloud Code 插件可以方便地帮助调试和部署我的代码,但我在使用这些工具时遇到了很大的问题。我在 M1 Mac 上,在 VSCode.
中启动“Debug on Cloud Emulator”命令时,我 运行 遇到以下问题
来自“云 运行 的日志:运行 / 本地调试”
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.
日志来自:云 运行:Run/Debug 本地 - 详细
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
}
]
}
我一直在研究 tasks.json 文件(曾尝试添加自定义选项,如“--platform linux/amd64”,但没有任何效果。任何帮助将不胜感激。
从 CMD exec
中删除 exec
:不幸的是,这会抛出 skaffold debug
。通常 Detailed 频道会包含一些日志来表明这一点,例如:
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.
但这似乎更 hit-and-miss 云 运行 模拟器,我通常会看到这样的日志:
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.
我们一直对 command-line 重写以删除 exec
持怀疑态度,但值得重新审视。我已经打开 https://github.com/GoogleContainerTools/skaffold/issues/7168 进行跟踪。
我目前正在尝试使用 VSCode 构建一个 python 3.10 应用程序,并希望尽快将该应用程序部署到云端 运行。 Google 有一个 Cloud Code 插件可以方便地帮助调试和部署我的代码,但我在使用这些工具时遇到了很大的问题。我在 M1 Mac 上,在 VSCode.
中启动“Debug on Cloud Emulator”命令时,我 运行 遇到以下问题来自“云 运行 的日志:运行 / 本地调试”
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.
日志来自:云 运行:Run/Debug 本地 - 详细
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
}
]
}
我一直在研究 tasks.json 文件(曾尝试添加自定义选项,如“--platform linux/amd64”,但没有任何效果。任何帮助将不胜感激。
从 CMD exec
中删除 exec
:不幸的是,这会抛出 skaffold debug
。通常 Detailed 频道会包含一些日志来表明这一点,例如:
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.
但这似乎更 hit-and-miss 云 运行 模拟器,我通常会看到这样的日志:
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.
我们一直对 command-line 重写以删除 exec
持怀疑态度,但值得重新审视。我已经打开 https://github.com/GoogleContainerTools/skaffold/issues/7168 进行跟踪。