Skip to content

Commit

Permalink
Separate docker CI job, build image from feature branches
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-ssvlabs committed Oct 4, 2024
1 parent cfe4e88 commit 4058330
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 10 additions & 0 deletions .github/workflows/workflow-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 5 additions & 32 deletions .github/workflows/workflow-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 4058330

Please sign in to comment.