Hands-on Exam: CI/CD Pipelines and Docker

Session length: 120 minutes  |  Total: 100 points  |  Practical, graded by script

Before you start
Schedule
PartTaskTimePoints
1Set up the lab and confirm Docker works0:00 to 0:105
2Fix the Dockerfile, build and run the image0:10 to 0:3525
3Scan the image for vulnerabilities and report0:35 to 1:0025
4Write the CI pipeline1:00 to 1:2525
5Troubleshoot and fix an unsafe pipeline1:25 to 1:4510
6Build hygiene: .dockerignore and image check1:45 to 2:0010

Spare time at the end is for re-checking. Run the grader after each part, not only at the end.

How to use the grader (read first)

The grader, grade.py, checks your work in each part and prints a score out of 100. You run it yourself as often as you like.

One-time setup
  1. Check Python 3.12 and Docker are installed: python3 --version and docker --version.
  2. Install the YAML library: pip install pyyaml.
  3. Put grade.py in the folder that contains wms-lab, not inside it. Your exam pack includes the file, and Appendix A at the end of this paper has the same code.
Running it
python3 grade.py wms-lab
Before each run
Reading the output
OutputMeaning and what to do
FAIL ... image wms-api:1.0.0 existsBuild it: docker build -t wms-api:1.0.0 . in wms-lab.
FAIL ... scan target is wms-api:1.0.0The report was made from another image or is from an old scan. Rerun the Trivy command above.
FAIL ... ci.yml parsesThe YAML is invalid. Indentation is the usual cause.
FAIL ... image contains no .git directoryYou edited .dockerignore but did not rebuild the image.
FAIL ... no step echoes a secretA run: line prints a secret. Pass secrets only through env:.

The grader checks the result, not your method. A check that fails for a correct approach is a grader bug: tell the invigilator.

Setup (do this first, not timed beyond Part 1)

Save the script below as setup.sh in an empty folder, then run bash setup.sh. It creates the lab folder wms-lab with a small Flask app, a broken Dockerfile, a broken pipeline, and a smoke test script.

#!/usr/bin/env bash
set -euo pipefail
mkdir -p wms-lab/{app,tests,scripts,broken,fixes,.github/workflows}
cd wms-lab
touch app/__init__.py

cat > app/web.py <<'EOF'
from flask import Flask, jsonify, request

app = Flask(__name__)


@app.get("/health")
def health():
    return jsonify(status="ok", version="1.0.0")


@app.get("/add")
def add():
    a = float(request.args.get("a", 0))
    b = float(request.args.get("b", 0))
    return jsonify(result=a + b)
EOF

cat > requirements.txt <<'EOF'
flask==3.0.3
gunicorn==22.0.0
EOF

cat > requirements-dev.txt <<'EOF'
pytest==8.3.3
EOF

cat > tests/test_web.py <<'EOF'
from app.web import app


def test_health_ok():
    response = app.test_client().get("/health")
    assert response.status_code == 200
    assert response.get_json()["status"] == "ok"
EOF

cat > Dockerfile <<'EOF'
FROM python:latest
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD gunicorn -b 0.0.0.0:8000 app.web:app
EOF


cat > broken/ci.yml <<'EOF'
name: broken
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: docker build -t acme/wms-api:latest .
      - run: docker push acme/wms-api:latest
  deploy:
    runs-on: ubuntu-latest
    steps:
      - run: echo "key is ${{ secrets.DEPLOY_KEY }}"
      - run: ./scripts/deploy.sh staging
EOF

cat > scripts/smoke_test.sh <<'EOF'
#!/usr/bin/env bash
# usage: smoke_test.sh BASE_URL [ATTEMPTS] [DELAY_SECONDS]
set -euo pipefail
URL="$1"; N="${2:-20}"; D="${3:-15}"
for i in $(seq 1 "$N"); do
  if curl -fsS "$URL/health" | grep -q '"status": *"ok"'; then
    echo "healthy on attempt $i"; exit 0
  fi
  echo "attempt $i failed, retrying in $D s"; sleep "$D"
done
echo "not healthy after $N attempts" >&2; exit 1
EOF
chmod +x scripts/smoke_test.sh
echo "Lab created in $(pwd)"

Part 1: Environment (5 points, 0:00 to 0:10)

Part 2: Dockerfile and image (25 points, 0:10 to 0:35)

Edit Dockerfile so that it:

Then:

Part 3: Image security scan (25 points, 0:35 to 1:00)

Scan the image you built in Part 2 for known vulnerabilities and record the results. You will use Trivy, a scanner that runs as a container and reads the local Docker image.

The first scan downloads the vulnerability database, so it needs network access. On Windows, use Docker Desktop with the Linux engine. If the pinned Trivy tag does not pull, use the nearest pinned release and note the version in SUMMARY.md.

Part 4: CI pipeline (25 points, 1:00 to 1:25)

Create .github/workflows/ci.yml with three jobs:

Validate the file's YAML with python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" .github/workflows/ci.yml. The grader does not run the pipeline in GitHub.

Part 5: Troubleshoot an unsafe pipeline (10 points, 1:25 to 1:45)

Read broken/ci.yml. It has three defects:

Write the corrected workflow to fixes/ci.yml. Tag images with ${{ github.sha }}, make deploy need build, and pass the secret only through an env: block to the script, never through echo.

Part 6: Build hygiene (10 points, 1:45 to 2:00)

The image currently copies everything in wms-lab, including git metadata and caches. Fix that:

Deliverables and grading

File (in wms-lab)Part
Dockerfile2
reports/trivy.json and reports/SUMMARY.md3
.github/workflows/ci.yml4
fixes/ci.yml5
.dockerignore6

Run the grader from the folder that contains grade.py:

python3 grade.py wms-lab

The grader prints PASS or FAIL for each check with a total score out of 100. Parts 2 and 3 run Docker, so keep Docker running and ports 8000 and 18000 free while it runs.


Appendix A: grader source (grade.py)

Save this as grade.py in the folder that holds the lab, or copy the file from the exam pack. Run it with python3 grade.py wms-lab.