Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build from feature branches #23

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "Docker reusable workflow"

on:
workflow_call:
inputs:
with-push:
description: "determines if to push docker image to an image registry. Defaults to 'false'"
default: false
type: boolean
required: false
image-tag:
description: "docker image tag. Defaults to 'latest'"
default: "latest"
type: string
required: false
image-architectures:
description: "comma separated list of architectures. Defaults to 'linux/amd64,linux/arm64'"
required: false
type: string
default: linux/amd64,linux/arm64

env:
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: ${{ inputs.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: ${{ inputs.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 }}
11 changes: 11 additions & 0 deletions .github/workflows/workflow-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ 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
image-architectures: linux/amd64
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 }}
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################
FROM --platform=$BUILDPLATFORM golang:1.23@sha256:2fe82a3f3e006b4f2a316c6a21f62b66e1330ae211d039bb8d1128e12ed57bf1 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23@sha256:adee809c2d0009a4199a11a1b2618990b244c6515149fe609e2788ddf164bd10 AS builder

WORKDIR /app

Expand Down