Skip to content

Commit

Permalink
reusable image build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CubicrootXYZ committed Aug 3, 2024
1 parent 1249802 commit 2aad0ff
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/build_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
workflow_call:
inputs:
docker_build_args:
required: false
type: string
docker_file_path:
required: false
default: "./"
type: string
image_name:
required: true
type: string
secrets:
dockerhub_user:
required: true
dockerhub_token:
required: true

jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Build the image
run: docker build -t ${{ inputs.image_name }}:${{ github.sha }} --build-arg VERSION=${{ github.ref_name }} ${{ inputs.docker_build_args }} ${{ inputs.docker_file_path }}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.dockerhub_user }}
password: ${{ secrets.dockerhub_token }}
- name: Push image with commit SHA
run: docker push ${{ inputs.image_name }}:${{ github.sha }}
- name: Push image with release tag
if: "github.event_name == 'release' && github.event.action == 'created'"
run: docker tag ${{ inputs.image_name }}:${{ github.sha }} ${{ inputs.image_name }}:${{ github.event.release.tag_name }} && \
docker push ${{ inputs.image_name }}:${{ github.event.release.tag_name }}

20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# Workflows
Collection of commonly used GitHubWorkflows

Collection of commonly used GitHub workflows.

## Building images

This workflow will build and push images to Dockerhub. For any change an image with the commit SHA as tag will be published. For releases the release tag will be used to tag the image.

```yaml
jobs:
build_image:
uses: CubicrootXYZ/Workflows/.github/workflows/[email protected]
with:
docker_build_args: "--no-cache"
docker_file_path: "./"
image_name: "example/image"
secrets:
dockerhub_user: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
```

0 comments on commit 2aad0ff

Please sign in to comment.