Skip to content

Commit

Permalink
Merge pull request #52 from GSA-TTS/gitlab-ci-image
Browse files Browse the repository at this point in the history
Build a `-glr` variant for use with gitlab-runner-cloudgov.
  • Loading branch information
rahearn authored Dec 17, 2024
2 parents 351189a + ca13bf0 commit 1c19863
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 11 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Docker

on:
pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: gsa-tts/trestle

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: latest=false
tags: type=sha

- name: Build Docker image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Extract Docker metadata - glr variant
id: meta-glr
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: latest=false
tags: type=raw,value=${{ github.sha }}-glr

- name: Build and push Docker image - glr variant
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: Dockerfile.glr
build-args: BASE_IMAGE=${{ fromJson(steps.meta.outputs.json).tags[0] }}
push: false
tags: ${{ steps.meta-glr.outputs.tags }}
labels: ${{ steps.meta-glr.outputs.labels }}
86 changes: 75 additions & 11 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@ on:
paths-ignore:
- README.md

pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: gsa-tts/trestle


jobs:
build:

publish:
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

outputs:
base_image: ${{ fromJson(steps.meta.outputs.json).tags[2] }} # tags[2] should be the sha tag
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'
Expand All @@ -46,7 +41,6 @@ jobs:
# 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 }}
Expand All @@ -73,7 +67,7 @@ jobs:
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand All @@ -86,11 +80,81 @@ jobs:
# 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}


publish-glr:
needs: publish
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
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 }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata - glr variant
id: meta-glr
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: latest=false
tags: |
type=raw,value={{date 'YYYYMMDD'}}-glr,priority=850
type=raw,value={{branch}}-glr,priority=600
type=raw,value={{sha}}-glr,priority=100
type=raw,value=latest-glr,priority=90
- name: Build and push Docker image - glr variant
id: build-and-push-glr
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: Dockerfile.glr
build-args: BASE_IMAGE=${{ needs.publish.outputs.base_image }}
push: true
tags: ${{ steps.meta-glr.outputs.tags }}
labels: ${{ steps.meta-glr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/arm64,linux/amd64

- name: Sign the published Docker image - glr
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta-glr.outputs.tags }}
DIGEST: ${{ steps.build-and-push-glr.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}
13 changes: 13 additions & 0 deletions Dockerfile.glr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file builds docker-trestle for use within a GitLab Runner
ARG BASE_IMAGE=ghcr.io/gsa-tts/trestle:latest
FROM ${BASE_IMAGE} AS base

# Use the root user so we can run our install_dependencies scripts from runner manager
USER root

# install known glr dependencies to speed up test runs
RUN apt-get update && apt-get install -y git git-lfs curl && apt-get clean

# entrypoint and command that allow starting the image without a volume in place and keep it running
COPY --chmod=755 entrypoint-glr.sh /app/entrypoint.sh
CMD [ "bash" ]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This repository contains the source code for the `ghcr.io/gsa-tts/trestle` Docke
1. [Update non-OSCAL SSP sections](#update-non-oscal-ssp-files)
1. [Render a human-readable SSPP (TODO: within a CI workflow)](#render-ssp)

### Use in a GitLab Runner

(beta) We're working on a `-glr` variant image for use within [gitlab-runner-cloudgov](https://github.com/gsa-tts/gitlab-runner-cloudgov)

### Pull down the trestle image and initialize a compliance trestle project

Prerequisite: `$(pwd)/compliance` directory exists and is where you want to store all compliance artifacts
Expand Down
6 changes: 6 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ services:
- ./working_dir:/app/docs
- ./templates:/app/templates

# a helper glr variant to help debug any issues
glr:
build:
context: .
dockerfile: Dockerfile.glr

# a helper pandoc just to easily properly set the volume for local testing.
# use with `docker compose run --rm pandoc <insert pandoc args here>`
pandoc:
Expand Down
6 changes: 6 additions & 0 deletions entrypoint-glr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /usr/bin/env bash

# get PATH set properly in gitlab-ci
echo 'export PATH="/app/bin:${PATH}"' > /etc/profile.d/trestle-scripts-path.sh

exec "$@"

0 comments on commit 1c19863

Please sign in to comment.