File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Docker Build and Trivy Scan
2+
3+ on :
4+ push :
5+ branches :
6+ - ' **'
7+
8+ jobs :
9+ build-and-scan :
10+ runs-on : ubuntu-latest
11+ env :
12+ DOCKER_CONTEXT : ' .'
13+ DOCKERFILE : ' Dockerfile'
14+ DOCKER_LOAD : ' true'
15+ TAGS : ' sample-python-app:${{ github.sha }}'
16+ steps :
17+ - name : Set up Docker Buildx
18+ uses : docker/setup-buildx-action@v3.12.0
19+ - name : Set up QEMU
20+ uses : docker/setup-qemu-action@v3.7.0
21+ - name : Build Docker Image
22+ id : build-image
23+ uses : docker/build-push-action@v6
24+ with :
25+ context : ${{ env.DOCKER_CONTEXT }}
26+ file : ${{ env.DOCKERFILE }}
27+ load : ${{ env.DOCKER_LOAD }}
28+ tags : ${{ env.TAGS }}
29+ - name : Run Trivy vulnerability scanner
30+ uses : aquasecurity/trivy-action@0.33.1
31+ with :
32+ image-ref : ${{ steps.build-image.outputs.digest }}
33+ format : ' table'
34+ exit-code : ' 1'
35+ ignore-unfixed : true
36+ vuln-type : ' os,library'
37+ severity : ' CRITICAL,HIGH'
Original file line number Diff line number Diff line change 1+ FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
2+ ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
3+
4+ ENV UV_NO_DEV=1
5+
6+ ENV UV_PYTHON_DOWNLOADS=0
7+
8+ WORKDIR /app
9+ RUN --mount=type=cache,target=/root/.cache/uv \
10+ --mount=type=bind,source=uv.lock,target=uv.lock \
11+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
12+ uv sync --locked --no-install-project
13+ COPY . /app
14+ RUN --mount=type=cache,target=/root/.cache/uv \
15+ uv sync --locked
16+
17+ FROM python:3.13-slim-bookworm
18+
19+ RUN apt-get update \
20+ && apt-get upgrade -y \
21+ && apt-get clean \
22+ && rm -rf /var/lib/apt/lists/*
23+
24+ RUN groupadd --system --gid 999 nonroot \
25+ && useradd --system --gid 999 --uid 999 --create-home nonroot
26+
27+ COPY --from=builder --chown=nonroot:nonroot /app /app
28+
29+ ENV PATH="/app/.venv/bin:$PATH"
30+
31+ USER nonroot
32+
33+ WORKDIR /app
34+
35+ USER nonroot
36+
37+ WORKDIR /app
38+
39+ CMD ["python" , "-m" ,"sample_python_app.main" ]
You can’t perform that action at this time.
0 commit comments