-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create reusable workflow for building images
- Loading branch information
Showing
2 changed files
with
72 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Reusable workflow for building the docker images | ||
# | ||
# Reference docs: | ||
# - https://docs.github.com/en/actions/using-workflows/reusing-workflows | ||
|
||
on: | ||
# Define workflow as reusable | ||
workflow_call: | ||
inputs: | ||
image_name: | ||
required: true | ||
type: string | ||
context_path: | ||
required: true | ||
type: string | ||
file_path: | ||
required: true | ||
type: string | ||
|
||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- # https://github.com/marketplace/actions/checkout | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- # https://github.com/marketplace/actions/docker-metadata-action | ||
name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
# list of Docker images to use as base name for tags | ||
images: | | ||
${{ inputs.image_name }} | ||
# generate Docker tags based on the following events/attributes | ||
tags: | | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} | ||
type=ref,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'test') }} | ||
type=ref,event=tag | ||
type=sha | ||
- # https://github.com/marketplace/actions/docker-setup-qemu | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- # https://github.com/marketplace/actions/docker-setup-buildx | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- # https://github.com/marketplace/actions/docker-login | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- # https://github.com/marketplace/actions/build-and-push-docker-images | ||
name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ${{ inputs.context_path }} | ||
file: ${{ inputs.file_path }} | ||
# push: true | ||
push: ${{ github.event_name == 'push' }} | ||
# tags: user/app:latest | ||
tags: ${{ steps.meta.outputs.tags }} |