Skip to content

Commit

Permalink
Use separate build and publish workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rahearn committed Dec 16, 2024
1 parent 053add3 commit a13c750
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 16 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Docker

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

# 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

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

# Build Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/myimage.tar

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: trestle-base-img
path: /tmp/myimage.tar


build-glr:
needs: 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

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: trestle-base-img
path: /tmp

- name: Load image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
# 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

- 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=latest-glr
- name: Build and push Docker image - glr variant
id: build-glr
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: Dockerfile.glr
build-args: BASE_VERSION=latest
push: false
tags: ${{ steps.meta-glr.outputs.tags }}
labels: ${{ steps.meta-glr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
26 changes: 10 additions & 16 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ on:
branches: [ "main" ]
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
Expand All @@ -28,7 +26,6 @@ jobs:
# 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 @@ -42,7 +39,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 Down Expand Up @@ -73,7 +69,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,7 +82,6 @@ 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 }}
Expand All @@ -96,8 +91,8 @@ jobs:
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}


build-glr:
needs: build
publish-glr:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -112,7 +107,6 @@ jobs:
# 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 @@ -126,7 +120,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 @@ -144,25 +137,26 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: latest=false
tags: |
type=raw,value=${{ steps.today.outputs.date }}-glr,priority=840
type=raw,value=latest-glr
type=raw,value=${{ steps.today.outputs.date }}-glr,priority=850
type=raw,value=latest-glr,priority=900
type=raw,value={{branch}}-glr,priority=600
type=raw,value={{sha}}-glr,priority=100
- 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_VERSION=${{ github.event_name != 'pull_request' && steps.today.outputs.date || 'latest' }}
push: ${{ github.event_name != 'pull_request' }}
build-args: BASE_VERSION=${{ steps.today.outputs.date }}
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
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-glr.outputs.tags }}
Expand Down

0 comments on commit a13c750

Please sign in to comment.