Skip to content

Commit

Permalink
update gh workflows to build and publish docker images more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Edge committed Jul 3, 2024
1 parent c9df328 commit bce55c2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 85 deletions.
90 changes: 51 additions & 39 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,69 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build-image:
generate:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

outputs:
CALVER: ${{ steps.calculate-calver.outputs.calver }}
REGISTRY: ${{ env.REGISTRY }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Compute outputs
run: |
echo "REGISTRY=${{ env.REGISTRY }}" >> $GITHUB_OUTPUT
- name: Generate CalVer Tag
id: calver
run: echo "::set-output name=version::v$(date +'%y.%m.%d')"


- name: Build gatekeeper image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.gatekeeper
push: false
tags: |
${{ env.REGISTRY }}/keychainmdip/gatekeeper:${{ steps.calver.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
- name: Calculate Calver
id: calculate-calver
run: |
calver=$(date +'%Y.%m.%d')
echo "calver=$calver" >> $GITHUB_ENV
echo "::set-output name=calver::$calver"
build_test_images:
runs-on: ubuntu-latest
needs: generate
strategy:
fail-fast: false
matrix:
include:
- dockerfile: Dockerfile.gatekeeper
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/gatekeeper:${{ needs.generate.outputs.CALVER }}
- dockerfile: Dockerfile.keymaster
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/keymaster:${{ needs.generate.outputs.CALVER }}
- dockerfile: Dockerfile.hyperswarm
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/hyperswarm-mediator:${{ needs.generate.outputs.CALVER }}
- dockerfile: Dockerfile.tess
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/tess-mediator:${{ needs.generate.outputs.CALVER }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build keymaster image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
context: .
file: Dockerfile.keymaster
push: false
tags: |
${{ env.REGISTRY }}/keychainmdip/keymaster:${{ steps.calver.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build hyperswarm mediator image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
context: .
file: Dockerfile.hyperswarm
push: false
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
${{ env.REGISTRY }}/keychainmdip/hyperswarm-mediator:${{ steps.calver.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
${{ needs.generate.outputs.CALVER }}
release
- name: Build TESS mediator image
- name: Build Docker images
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.tess
file: ${{ matrix.dockerfile }}
push: false
tags: |
${{ env.REGISTRY }}/keychainmdip/tess-mediator:${{ steps.calver.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
93 changes: 47 additions & 46 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Build and publish Docker images
name: Build & Publish

on:
push:
Expand All @@ -18,20 +18,57 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
generate:
runs-on: ubuntu-latest
outputs:
CALVER: ${{ steps.calculate-calver.outputs.calver }}
REGISTRY: ${{ env.REGISTRY }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Compute outputs
run: |
echo "REGISTRY=${{ env.REGISTRY }}" >> $GITHUB_OUTPUT
- name: Calculate Calver
id: calculate-calver
run: |
calver=$(date +'%Y.%m.%d')
echo "calver=$calver" >> $GITHUB_ENV
echo "::set-output name=calver::$calver"
build_test_images:
runs-on: ubuntu-latest
needs: generate
strategy:
fail-fast: false
matrix:
include:
- dockerfile: Dockerfile.gatekeeper
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/gatekeeper:${{ needs.generate.outputs.CALVER }}
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/gatekeeper:release
- dockerfile: Dockerfile.keymaster
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/keymaster:${{ needs.generate.outputs.CALVER }}
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/keymaster:release
- dockerfile: Dockerfile.hyperswarm
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/hyperswarm-mediator:${{ needs.generate.outputs.CALVER }}
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/hyperswarm-mediator:release
- dockerfile: Dockerfile.tess
tags: |
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/tess-mediator:${{ needs.generate.outputs.CALVER }}
${{ needs.generate.outputs.REGISTRY }}/keychainmdip/tess-mediator:release
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Generate CalVer Tag
id: calver
run: echo "::set-output name=version::v$(date +'%y.%m.%d')"

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
Expand All @@ -45,49 +82,13 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
${{ steps.calver.outputs.version }}
${{ needs.generate.outputs.CALVER }}
release
- name: Build and push gatekeeper image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.gatekeeper
push: true
tags: |
${{ env.REGISTRY }}/keychainmdip/gatekeeper:${{ steps.calver.outputs.version }}
${{ env.REGISTRY }}/keychainmdip/gatekeeper:release
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push keymaster image
- name: Build and push Docker images
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.keymaster
file: ${{ matrix.dockerfile }}
push: true
tags: |
${{ env.REGISTRY }}/keychainmdip/keymaster:${{ steps.calver.outputs.version }}
${{ env.REGISTRY }}/keychainmdip/keymaster:release
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push hyperswarm mediator image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.hyperswarm
push: true
tags: |
${{ env.REGISTRY }}/keychainmdip/hyperswarm-mediator:${{ steps.calver.outputs.version }}
${{ env.REGISTRY }}/keychainmdip/hyperswarm-mediator:release
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push TESS mediator image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile.tess
push: true
tags: |
${{ env.REGISTRY }}/keychainmdip/tess-mediator:${{ steps.calver.outputs.version }}
${{ env.REGISTRY }}/keychainmdip/tess-mediator:release
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit bce55c2

Please sign in to comment.