File size: 15,809 Bytes
c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 eb895b1 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 eb895b1 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 eb895b1 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 2794920 c8f3b98 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | """Task: CI/CD Build & Push Pipeline β HARD.
Agent debugs combined GHA + Docker + Registry pipeline failures:
GHCR login missing token, wrong image tag in workflow, missing permissions,
Dockerfile + workflow arg mismatch, multi-stage build output mismatch.
"""
from server.models import TaskDifficulty
from server.tasks.base import BaseTask
class PipelineBuildDeployTask(BaseTask):
NAME = "CI/CD Build & Push Pipeline"
DESCRIPTION = "Debug GHA-to-Docker-to-Registry pipeline failures across multiple files"
DIFFICULTY = TaskDifficulty.HARD
AVAILABLE_SECRETS = ["GITHUB_TOKEN", "DOCKER_USERNAME", "DOCKER_PASSWORD"]
SCENARIOS = [
# Scenario 1: Registry mismatch β build tags ghcr.io but push targets docker.io
{
"id": "registry_mismatch",
"files": [
{
"path": ".github/workflows/deploy.yml",
"type": "workflow",
"content": (
"name: Build and Push\n"
"on:\n"
" push:\n"
" branches: [main]\n"
"\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" permissions:\n"
" packages: write\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
"\n"
" - name: Login to GHCR\n"
" run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin\n"
"\n"
" - name: Build image\n"
" run: docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} .\n"
"\n"
" - name: Push image\n"
" run: docker push docker.io/${{ github.repository }}:${{ github.sha }}\n"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM node:20-alpine\n"
"WORKDIR /app\n"
"COPY package*.json ./\n"
"RUN npm ci\n"
"COPY . .\n"
"EXPOSE 3000\n"
'CMD ["npm", "start"]\n'
),
},
{
"path": "package.json",
"type": "other",
"content": '{"name": "myapp", "scripts": {"start": "node server.js"}}',
},
],
"error": {
"phase": "pipeline_build",
"message": (
"Run: Build and Push\n"
"\n"
"Step: Build image β\n"
"Step: Push image β\n"
"Error: An image does not exist locally with the tag: docker.io/<repo>:<sha>\n"
"\n"
"The image was built with a ghcr.io tag but the push targets docker.io."
),
"exit_code": 1,
"failed_step": "Push image",
},
"expected_fixes": [
{
"file": ".github/workflows/deploy.yml",
"type": "contains",
"expected": "docker push ghcr.io/",
"hint": "The push command targets docker.io but the image was tagged with ghcr.io β use the same registry",
}
],
},
# Scenario 2: Image tag mismatch between build and push steps
{
"id": "image_tag_mismatch",
"files": [
{
"path": ".github/workflows/build.yml",
"type": "workflow",
"content": (
"name: Build and Push\n"
"on:\n"
" push:\n"
" tags: ['v*']\n"
"\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
"\n"
" - name: Login to DockerHub\n"
" run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin\n"
"\n"
" - name: Build image\n"
" run: docker build -t myuser/myapp:${{ github.ref_name }} .\n"
"\n"
" - name: Push image\n"
" run: docker push myuser/myapp:${{ github.sha }}\n"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"WORKDIR /app\n"
"COPY requirements.txt .\n"
"RUN pip install -r requirements.txt\n"
"COPY . .\n"
"EXPOSE 7860\n"
'CMD ["python", "app.py"]\n'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "flask==3.0.0\ngunicorn==21.2.0\n",
},
],
"error": {
"phase": "pipeline_build",
"message": (
"Run: Build and Push\n"
"\n"
"Step: Build image β\n"
"Step: Push image β\n"
"Error: An image does not exist locally with the tag: myuser/myapp:<sha>\n"
"\n"
"The build used github.ref_name as the tag but push used github.sha. "
"These are different values."
),
"exit_code": 1,
"failed_step": "Push image",
},
"expected_fixes": [
{
"file": ".github/workflows/build.yml",
"type": "contains",
"expected": "docker push myuser/myapp:${{ github.ref_name }}",
"hint": "Build tags image with github.ref_name but push uses github.sha β use the same tag",
}
],
},
# Scenario 3: Build and push use different tagging strategies (sha vs latest)
{
"id": "inconsistent_tagging",
"files": [
{
"path": ".github/workflows/publish.yml",
"type": "workflow",
"content": (
"name: Publish\n"
"on:\n"
" push:\n"
" branches: [main]\n"
"\n"
"jobs:\n"
" publish:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
"\n"
" - name: Login to DockerHub\n"
" run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin\n"
"\n"
" - name: Build\n"
" run: docker build -t myuser/api:${{ github.sha }} .\n"
"\n"
" - name: Test\n"
" run: docker run myuser/api:${{ github.sha }} python -m pytest\n"
"\n"
" - name: Tag latest\n"
" run: docker tag myuser/api:latest myuser/api:stable\n"
"\n"
" - name: Push\n"
" run: |\n"
" docker push myuser/api:${{ github.sha }}\n"
" docker push myuser/api:stable\n"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"WORKDIR /app\n"
"COPY requirements.txt .\n"
"RUN pip install -r requirements.txt\n"
"COPY . .\n"
'CMD ["python", "app.py"]\n'
),
},
{
"path": "requirements.txt",
"type": "requirements",
"content": "flask==3.0.0\npytest==7.4.0\n",
},
],
"error": {
"phase": "pipeline_build",
"message": (
"Run: Publish\n"
"\n"
"Step: Build β (myuser/api:<sha>)\n"
"Step: Test β\n"
"Step: Tag latest β\n"
"Error: No such image: myuser/api:latest\n"
"\n"
"The tag command references 'myuser/api:latest' but no image with that tag exists."
),
"exit_code": 1,
"failed_step": "Tag latest",
},
"expected_fixes": [
{
"file": ".github/workflows/publish.yml",
"type": "contains",
"expected": "docker tag myuser/api:${{ github.sha }}",
"hint": "The 'docker tag' source must match the tag used in the build step β use the sha-tagged image as source",
}
],
},
# Scenario 4: Dockerfile ARG not passed from workflow build-arg
{
"id": "build_arg_not_passed",
"files": [
{
"path": ".github/workflows/build.yml",
"type": "workflow",
"content": (
"name: Build with Version\n"
"on:\n"
" push:\n"
" branches: [main]\n"
"\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
"\n"
" - name: Build image\n"
" run: docker build -t myapp:${{ github.sha }} .\n"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"ARG APP_VERSION\n"
"WORKDIR /app\n"
"COPY . .\n"
"RUN echo $APP_VERSION > /app/version.txt\n"
"EXPOSE 7860\n"
'CMD ["python", "app.py"]\n'
),
},
],
"error": {
"phase": "pipeline_build",
"message": (
"Run: Build with Version\n"
"\n"
"Step: Build image β (with warnings)\n"
"Warning: /app/version.txt is empty β APP_VERSION build arg was not provided\n"
"\n"
"The Dockerfile declares ARG APP_VERSION but the docker build command "
"does not pass --build-arg APP_VERSION=..."
),
"exit_code": 0,
"failed_step": "Build image",
},
"expected_fixes": [
{
"file": ".github/workflows/build.yml",
"type": "contains",
"expected": "--build-arg APP_VERSION=",
"hint": "Dockerfile uses ARG APP_VERSION but the build command doesn't pass --build-arg",
}
],
},
# Scenario 5: Dockerfile path wrong in workflow when using subdirectory structure
{
"id": "dockerfile_path_in_subdirectory",
"files": [
{
"path": ".github/workflows/build.yml",
"type": "workflow",
"content": (
"name: Build API\n"
"on:\n"
" push:\n"
" branches: [main]\n"
"\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
"\n"
" - name: Build API image\n"
" uses: docker/build-push-action@v5\n"
" with:\n"
" context: ./services/api\n"
" file: ./Dockerfile\n"
" push: false\n"
" tags: api:latest\n"
),
},
{
"path": "services/api/Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"WORKDIR /app\n"
"COPY requirements.txt .\n"
"RUN pip install -r requirements.txt\n"
"COPY . .\n"
"EXPOSE 7860\n"
'CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]\n'
),
},
{
"path": "services/api/requirements.txt",
"type": "requirements",
"content": "fastapi==0.104.0\nuvicorn==0.24.0\n",
},
],
"error": {
"phase": "pipeline_build",
"message": (
"Run: Build API\n"
"\n"
"Step: Build API image β\n"
"Error: unable to prepare context: unable to evaluate symlinks in Dockerfile path: "
"lstat /home/runner/work/repo/repo/Dockerfile: no such file or directory\n"
"\n"
"The Dockerfile is not at the repository root."
),
"exit_code": 1,
"failed_step": "Build API image",
},
"expected_fixes": [
{
"file": ".github/workflows/build.yml",
"type": "contains",
"expected": "file: ./services/api/Dockerfile",
"hint": "The 'file' path must point to where the Dockerfile actually is β ./services/api/Dockerfile, not ./Dockerfile",
}
],
},
]
|