diff --git a/.github/workflows/build_image.yaml b/.github/workflows/build_image.yaml index 1884e5a..95afa41 100644 --- a/.github/workflows/build_image.yaml +++ b/.github/workflows/build_image.yaml @@ -11,6 +11,10 @@ on: image_name: required: true type: string + static_tag: + required: false + type: string + default: "" secrets: dockerhub_user: required: true @@ -38,4 +42,10 @@ jobs: - name: Push image with tag if: "startsWith(github.ref, 'refs/tags/')" run: docker push ${{ inputs.image_name }}:${{ github.ref_name }} + - name: Tag image with static tag + if: "${{ inputs.static_tag != '' && github.ref == 'refs/heads/main'}}" + run: docker tag ${{ inputs.image_name }}:${{ github.sha }} ${{ inputs.image_name }}:${{ inputs.static_tag }} + - name: Push image with static tag + if: "${{ inputs.static_tag != '' && github.ref == 'refs/heads/main'}}" + run: docker push ${{ inputs.image_name }}:${{ inputs.static_tag }} \ No newline at end of file diff --git a/.github/workflows/build_image_test.yaml b/.github/workflows/build_image_test.yaml new file mode 100644 index 0000000..82a4acf --- /dev/null +++ b/.github/workflows/build_image_test.yaml @@ -0,0 +1,12 @@ +on: push + +jobs: + build_image_test: + uses: ./.github/workflows/build_image.yaml + with: + docker_file_path: "tests/build_image/" + image_name: cubicrootxyz/workflows-test + static_tag: beta + secrets: + dockerhub_user: "${{ secrets.DOCKERHUB_USERNAME }}" + dockerhub_token: "${{ secrets.DOCKERHUB_TOKEN }}" \ No newline at end of file diff --git a/README.md b/README.md index d070040..d7ed3fa 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Collection of commonly used GitHub workflows. 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. +Provide a `static_tag` so any commit on `main` branch will result in an image pushed with that tag. Can be used to provide a `beta` or `main` tagged image. + ```yaml jobs: build_image: diff --git a/tests/build_image/Dockerfile b/tests/build_image/Dockerfile new file mode 100644 index 0000000..449fd74 --- /dev/null +++ b/tests/build_image/Dockerfile @@ -0,0 +1 @@ +FROM scratch \ No newline at end of file