diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..b911125 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +name: Docker + +on: + push: + branches: [ "main" ] + paths-ignore: + - README.md + + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: gsa-tts/trestle + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: latest=true + tags: | + type=raw,value={{date 'YYYYMMDD'}},priority=850 + type=ref,event=branch + type=sha + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/arm64,linux/amd64 + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/Dockerfile b/Dockerfile index 20fd210..c7fb7f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ RUN adduser \ # RUN --mount=type=cache,target=/root/.cache/pip \ # --mount=type=bind,source=requirements.txt,target=requirements.txt \ # python -m pip install -r requirements.txt -ARG TRESTLE_VERSION=3.2.0 +ARG TRESTLE_VERSION=3.3.0 RUN --mount=type=cache,target=/root/.cache/pip \ python -m pip install "compliance-trestle==${TRESTLE_VERSION}" @@ -46,7 +46,7 @@ USER appuser COPY --chown=appuser:appuser --chmod=744 entrypoint.sh /app/entrypoint.sh COPY --chown=appuser:appuser templates /app/templates/ -COPY OSCAL_REFERENCE.md /app/ +COPY *.md /app/ COPY scripts /app/bin ENV PATH="/app/bin:${PATH}" diff --git a/README.md b/README.md index 62ed371..19490ac 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,12 @@ The `/app/docs` directory can be used as a scratch area for any temporary trestl ### Updating the Docker image: 1. Make required changes to the Dockerfile -1. Build the image: `docker build --platform linux/arm64,linux/amd64 -t ghcr.io/gsa-tts/trestle .` +1. Push to GitHub and create a PR +1. On merging to main, a new docker image will be built, tagged, and pushed to the github container registry. - > [!TIP] - > You may need to [enable containerd image store](https://docs.docker.com/desktop/containerd/#enable-the-containerd-image-store) to support mutli-platform builds. +Each published image will be tagged with: -1. Tag with a datestamp: `docker tag ghcr.io/gsa-tts/trestle ghcr.io/gsa-tts/trestle:YYYYMMDD` -1. Push the new tag to Docker Hub: `docker push ghcr.io/gsa-tts/trestle:YYYYMMDD` +1. `latest` +1. The publication date: `YYYYMMDD` +1. The branch it was created on: `main` +1. The short git sha: `sha-c9f60e2`