diff options
author | Joris Roovers <joris.roovers@gmail.com> | 2023-02-21 10:52:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-21 10:52:25 +0000 |
commit | 250c1ff0eed35bdd3df6000cdc41698952189388 (patch) | |
tree | 80758546ce050168d1618d5555bfe6eeca81c08d | |
parent | 0426bb6915be1767ddb8ef8518312cb5efd2eb22 (diff) |
GHA: publish-docker workflow improvements (#452)
- Support for pushing to dockerhub
- Testing of docker image post release
- Separation of gitlint_version from docker_image_tag. This allows
for pushing latest and latest_dev images.
- Auto publish latest_dev image on every commit on main
-rw-r--r-- | .github/workflows/publish-docker.yml | 55 | ||||
-rw-r--r-- | .github/workflows/publish-release.yml | 10 |
2 files changed, 58 insertions, 7 deletions
diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 2ed6090..092b6b3 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -8,8 +8,12 @@ on: description: "Gitlint version to build docker image for" required: true type: string + docker_image_tag: + description: "Docker image tag" + required: true + type: string push_to_dockerhub: - description: "Whether to push to dockerhub.com" + description: "Push to dockerhub.com" required: false type: boolean default: false @@ -18,9 +22,17 @@ on: gitlint_version: description: "Gitlint version to build docker image for" type: string - default: "main" + docker_image_tag: + description: "Docker image tag" + required: true + type: choice + options: + - "latest_dev" + - "latest" + - "Use $gitlint_version" + default: "Use $gitlint_version" push_to_dockerhub: - description: "Whether to push to dockerhub.com" + description: "Push to dockerhub.com" required: false type: boolean default: false @@ -29,10 +41,39 @@ jobs: publish_docker: runs-on: "ubuntu-latest" steps: - - name: Build and push + - name: Determine docker tag + id: set_tag + run: | + if [[ "${{ inputs.docker_image_tag }}" == "Use $gitlint_version" ]]; then + echo "docker_image_tag=${{ inputs.gitlint_version }}" >> $GITHUB_OUTPUT + else + echo "docker_image_tag=${{ inputs.docker_image_tag }}" >> $GITHUB_OUTPUT + fi + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: jorisroovers + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build docker image + uses: docker/build-push-action@v4 + with: + build-args: GITLINT_VERSION=${{ inputs.gitlint_version }} + tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }} + + - name: Test docker image + run: | + gitlint_version=$(docker run --ulimit nofile=1024 -v $(pwd):/repo jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }} --version) + [ "$gitlint_version" == "gitlint, version ${{ inputs.gitlint_version }}" ] + + + # This won't actually rebuild the docker image, but just push the previously built and cached image + - name: Push docker image uses: docker/build-push-action@v4 with: push: ${{ inputs.push_to_dockerhub }} - build-args: - - GITLINT_VERSION=${{ inputs.gitlint_version }} - tags: jorisroovers/gitlint:${{ inputs.gitlint_version }}
\ No newline at end of file + build-args: GITLINT_VERSION=${{ inputs.gitlint_version }} + tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }} + if: inputs.push_to_dockerhub +
\ No newline at end of file diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 18f2af8..9c32f08 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -157,3 +157,13 @@ jobs: gitlint_version: ${{ needs.publish.outputs.gitlint_version }} pypi_source: ${{ inputs.pypi_target }} repo_test_ref: ${{ inputs.repo_release_ref }} + + publish-docker: + needs: + - publish + - test-release + uses: ./.github/workflows/publish-docker.yml + with: + gitlint_version: ${{ needs.publish.outputs.gitlint_version }} + docker_image_tag: "latest_dev" + push_to_dockerhub: true |