将Azure投票应用从GitLab推送到AKS时出现镜像标签不存在错误
Hey there! Let's break down what's going wrong here and get your Azure voting app deployed to AKS successfully.
Root Cause of the Error
Looking at your CI logs, the critical failure point is this line:
-----> Unable to select a buildpack
GitLab's Auto DevOps is using the gliderlabs/herokuish image to build your app, which relies on "buildpacks" to detect and build different types of applications (like Node.js, Python, Ruby apps). But your Azure voting app uses a custom Dockerfile (in the azure-vote folder) instead of a Heroku-style project structure (no Procfile, no language-specific source files in the root), so herokuish can't figure out how to build it. The subsequent "image does not exist locally" error is just a side effect of the build failing.
Step-by-Step Solutions
1. Disable Auto DevOps' Automatic Build & Use the Project's Dockerfile
Since your app already has a Dockerfile, we don't need herokuish. Here's how to fix your CI pipeline:
- Go to your GitLab project's Settings > CI/CD > Auto DevOps
- Uncheck the "Auto Build" option (this stops GitLab from using herokuish for builds)
- Create a custom
.gitlab-ci.ymlfile in your project root with these stages:
stages: - build - deploy # Build and push the Azure Vote app image to GitLab Container Registry build-azure-vote: stage: build image: docker:stable services: - docker:dind variables: DOCKER_DRIVER: overlay2 script: # Login to GitLab Container Registry using CI credentials - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" # Build the app image from the azure-vote folder's Dockerfile - docker build -t "$CI_REGISTRY/username/azure-voting-app-redis/azure-vote:$CI_COMMIT_SHORT_SHA" ./azure-vote - docker build -t "$CI_REGISTRY/username/azure-voting-app-redis/azure-vote:latest" ./azure-vote # Push both tagged images to the registry - docker push "$CI_REGISTRY/username/azure-voting-app-redis/azure-vote:$CI_COMMIT_SHORT_SHA" - docker push "$CI_REGISTRY/username/azure-voting-app-redis/azure-vote:latest" # Deploy the app to AKS using the provided Kubernetes manifest deploy-to-aks: stage: deploy image: alpine/k8s:latest script: # Update the Kubernetes manifest to use your GitLab registry image - sed -i "s/mcr.microsoft.com\/azure-samples\/azure-vote-front:v1/$CI_REGISTRY\/username\/azure-voting-app-redis\/azure-vote:latest/g" azure-vote-all-in-one-redis.yaml # Deploy to AKS (ensure your GitLab Runner has access to your AKS cluster's kubeconfig) - kubectl apply -f azure-vote-all-in-one-redis.yaml
2. Verify GitLab Runner's AKS Access
Make sure your GitLab Runner is properly configured to access your AKS cluster:
- If you're using a Kubernetes-based GitLab Runner, it should have a ServiceAccount with permissions to create/deploy resources in AKS
- If you're using a VM-based Runner, ensure the
kubeconfigfile for your AKS cluster is available in the Runner environment (you can add it as a CI/CD variable in GitLab)
3. Test Locally First
Before running the CI pipeline, test building the image locally to confirm the Dockerfile works:
cd azure-vote docker build -t azure-vote . docker run -p 8080:80 azure-vote
If you can access http://localhost:8080 and see the voting app, the Dockerfile is working correctly.
Why This Works
By using the project's existing Dockerfile, we skip the herokuish buildpack detection entirely. We build the image directly, push it to GitLab's registry, then update the Kubernetes manifest to use your custom image instead of the Azure sample one, and deploy it to AKS.
内容的提问来源于stack exchange,提问作者APRO

