Skip to content

Commit

Permalink
♻️ ci extract build image to separate action
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhir committed Sep 2, 2024
1 parent 2d898a5 commit 0b0b861
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 25 deletions.
59 changes: 59 additions & 0 deletions .github/actions/build-image/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build-image
description: "Builds and pushes a docker image"

inputs:
registry:
description: "Image registry to push image to"
required: true
registry-username:
description: "Username to authenticate against image registry"
required: true
registry-password:
description: "Password to authenticate against image registry"
required: true
path:
description: "Path to the Dockerfile to build image from"
required: true
image-name:
description: "Name to give the image"
required: true
image-tags:
description: "Tags to tag image with"
required: false
default: |
type=raw,value=latest
image-labels:
description: "Labels to add to image"
required: false
default: |
org.opencontainers.image.description=See ${{ github.server_url }}/${{ github.repository }}
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Download a single artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: target
- name: Login to Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry-username }}
password: ${{ inputs.registry-password }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: "${{ inputs.registry }}/${{ github.repository }}/${{ inputs.image-name }}"
tags: ${{inputs.image-tags}}
labels: ${{inputs.image-labels}}
- name: Build and push image
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
context: ./${{ inputs.path }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
34 changes: 9 additions & 25 deletions .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
});
console.log(`Pull Request created: ${pullResult.data.html_url}`);
build-images:
if: inputs.build-images == true && inputs.module == matrix.module
build-images-gateway:
if: inputs.build-images == true
needs: build-maven
runs-on: ubuntu-latest
strategy:
Expand All @@ -110,30 +110,14 @@ jobs:
path: ./refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-service
module: refarch-integrations
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Download target artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: target
- name: Login to Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
- uses: ./.github/actions/build-image
if: matrix.module == inputs.module
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for image
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: "${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.name }}"
tags: |
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
path: ${{ matrix.path }}
image-name: ${{ matrix.name }}
image-tags: |
type=raw,value=${{ inputs.release-version }}
type=raw,value=latest,enable=${{ inputs.snapshot-release == false }}
- name: Build and push image
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
context: ${{ matrix.path }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 0b0b861

Please sign in to comment.