From bce55c2106de00ca407f7c234c7cffdc27ec19e6 Mon Sep 17 00:00:00 2001 From: Shawn Edge Date: Wed, 3 Jul 2024 10:53:37 -0400 Subject: [PATCH 1/2] update gh workflows to build and publish docker images more efficiently --- .github/workflows/docker-build.yml | 90 +++++++++++++++------------ .github/workflows/docker-publish.yml | 93 ++++++++++++++-------------- 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index f3d7fb46..cbe2195e 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 976f6e01..6ee15571 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -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: @@ -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: @@ -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 }} \ No newline at end of file From 4aa2654bb0ca7ff59271dc54fdc43b6613796cde Mon Sep 17 00:00:00 2001 From: Shawn Edge Date: Wed, 3 Jul 2024 11:06:29 -0400 Subject: [PATCH 2/2] bump gh action versions to remove warnings --- .github/workflows/docker-build.yml | 10 +++++----- .github/workflows/docker-publish.yml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index cbe2195e..b33869f6 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -24,7 +24,7 @@ jobs: REGISTRY: ${{ env.REGISTRY }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Compute outputs run: | @@ -58,10 +58,10 @@ jobs: ${{ needs.generate.outputs.REGISTRY }}/keychainmdip/tess-mediator:${{ needs.generate.outputs.CALVER }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -69,7 +69,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -77,7 +77,7 @@ jobs: release - name: Build Docker images - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@1a162644f9a7e87d8f4b053101d1d9a712edc18c with: context: . file: ${{ matrix.dockerfile }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 6ee15571..b8543dd9 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -25,7 +25,7 @@ jobs: REGISTRY: ${{ env.REGISTRY }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Compute outputs run: | @@ -67,10 +67,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -78,7 +78,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -86,7 +86,7 @@ jobs: release - name: Build and push Docker images - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@1a162644f9a7e87d8f4b053101d1d9a712edc18c with: context: . file: ${{ matrix.dockerfile }}