diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..eb94ff8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,60 @@ +name: "Docker reusable workflow" + +on: + workflow_call: + inputs: + with-push: + description: "determines if to push docker image to an image registry, otherwise will just build" + default: false + type: boolean + required: false + image-tag: + description: "docker image tag. Defaults to 'latest'" + default: "latest" + type: string + required: false + +env: + IMAGE_ARCHITECTURES: linux/amd64,linux/arm64 + IMAGE_REGISTRY: ghcr.io + DOCKERFILE_PATH: build/Dockerfile + IMAGE_DESCRIPTION: | + This Docker image is a CLI tool for evaluating the health and severity of various SSV client related metrics over time. + +jobs: + docker: + name: Build/Push Docker Image + runs-on: ubuntu-latest + permissions: + id-token: write + packages: write + contents: read + env: + IMAGE_TAG: ${{ inputs.image-tag }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: ${{ env.IMAGE_ARCHITECTURES }} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ env.DOCKERFILE_PATH }} + push: ${{ inputs.with-push }} + platforms: ${{ env.IMAGE_ARCHITECTURES }} + tags: | + ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}:${{ env.IMAGE_TAG }} + ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}:latest + outputs: | + type=image,name=target,annotation-index.org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} diff --git a/.github/workflows/workflow-feature.yml b/.github/workflows/workflow-feature.yml index 190470d..b9bbf93 100644 --- a/.github/workflows/workflow-feature.yml +++ b/.github/workflows/workflow-feature.yml @@ -52,3 +52,13 @@ jobs: - name: Test run: make test + + docker-build: + uses: ./.github/workflows/docker.yml + needs: ["go-lint", "go-build", "go-test"] + permissions: + id-token: write + packages: write + contents: read + with: + with-push: false \ No newline at end of file diff --git a/.github/workflows/workflow-main.yml b/.github/workflows/workflow-main.yml index 85ade06..21b20ac 100644 --- a/.github/workflows/workflow-main.yml +++ b/.github/workflows/workflow-main.yml @@ -35,39 +35,12 @@ jobs: body: ${{ steps.tag_version.outputs.changelog }} docker-build-push: - name: Build Push Docker Image - runs-on: ubuntu-latest - needs: publish-release + uses: ./.github/workflows/docker.yml permissions: id-token: write packages: write contents: read - env: - IMAGE_TAG: ${{ needs.publish-release.outputs.new_tag }} - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - platforms: ${{ env.IMAGE_ARCHITECTURES }} - - - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.IMAGE_REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - file: ${{ env.DOCKERFILE_PATH }} - push: true - platforms: ${{ env.IMAGE_ARCHITECTURES }} - tags: | - ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}:${{ env.IMAGE_TAG }} - ${{ env.IMAGE_REGISTRY }}/${{ github.repository }}:latest - outputs: | - type=image,name=target,annotation-index.org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} + needs: publish-release + with: + with-push: true + image-tag: ${{ needs.publish-release.outputs.new_tag }} \ No newline at end of file