Skip to content

Commit

Permalink
ci: use reusable workflow (#35)
Browse files Browse the repository at this point in the history
* ci: use `reusable workflow`
* ci(pre-commit): add `hadolint-docker` hook
* docs(readme): add `docker-publish` badge
  • Loading branch information
DeadNews committed Sep 19, 2023
1 parent 0252d60 commit b718e3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 72 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ on:
pull_request:
branches: [main]

permissions:
security-events: write

jobs:
codeql:
name: CodeQL analyze
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- uses: actions/checkout@v4

Expand Down
76 changes: 8 additions & 68 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,13 @@ on:

permissions:
contents: read

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
id-token: write
packages: write
security-events: write

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Install the cosign tool except on PR.
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2

# Add support for more platforms with QEMU.
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

# Using it to be able to build multi-platform images, export cache, etc.
- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR.
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker.
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR).
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64

# Sign the resulting Docker image digest except on PRs.
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
docker:
name: Docker
uses: deadnews/deadnews-template-docker/.github/workflows/docker-reusable.yml@latest
with:
build-platforms: linux/amd64
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autofix_commit_msg: "chore: auto fixes from `pre-commit` hooks"
autoupdate_commit_msg: "chore(pre-commit): autoupdate"
autoupdate_schedule: quarterly
skip: [golangci-lint]
skip: [golangci-lint, hadolint-docker]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -47,3 +47,8 @@ repos:
rev: v1.54.2
hooks:
- id: golangci-lint

- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
[![Main](https://github.com/DeadNews/deadnews-template-go/actions/workflows/main.yml/badge.svg)](https://github.com/DeadNews/deadnews-template-go/actions/workflows/main.yml)
[![pre-commit.ci](https://results.pre-commit.ci/badge/github/DeadNews/deadnews-template-go/main.svg)](https://results.pre-commit.ci/latest/github/DeadNews/deadnews-template-go/main)
[![codecov](https://codecov.io/gh/DeadNews/deadnews-template-go/branch/main/graph/badge.svg?token=OCZDZIYPMC)](https://codecov.io/gh/DeadNews/deadnews-template-go)
[![image_version](https://ghcr-badge.egpl.dev/DeadNews/deadnews-template-go/latest_tag?trim=major&ignore=sha256*)](https://github.com/DeadNews/deadnews-template-go/pkgs/container/deadnews-template-go)

[![Docker](https://github.com/DeadNews/deadnews-template-go/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/DeadNews/deadnews-template-go/actions/workflows/docker-publish.yml)
[![image_version](https://ghcr-badge.egpl.dev/DeadNews/deadnews-template-go/latest_tag?label=image+version&trim=major&ignore=sha256*)](https://github.com/DeadNews/deadnews-template-go/pkgs/container/deadnews-template-go)
[![image_size](https://ghcr-badge.egpl.dev/DeadNews/deadnews-template-go/size)](https://github.com/DeadNews/deadnews-template-go/pkgs/container/deadnews-template-go)

0 comments on commit b718e3f

Please sign in to comment.