verify base, sign images #81
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
tags: | |
- 'v*' | |
pull_request: | |
branches: | |
- master | |
- develop | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Install cosign | |
uses: sigstore/[email protected] | |
- name: Verify distroless base image | |
run: make verify || exit 1 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
tags: sholdee/adguardexporter:test-${{ github.sha }} | |
platforms: linux/amd64,linux/arm64 | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
build-args: | | |
DISTROLESS_IMAGE=$(cat image.env | grep DISTROLESS_IMAGE | cut -d '=' -f2) | |
push: | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/[email protected] | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
sholdee/adguardexporter | |
ghcr.io/${{ github.repository_owner }}/adguard-exporter | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} | |
type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }} | |
type=ref,event=branch | |
type=ref,event=tag | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
build-args: | | |
DISTROLESS_IMAGE=$(cat image.env | grep DISTROLESS_IMAGE | cut -d '=' -f2) | |
- name: Sign the images with GitHub OIDC Token | |
if: github.event_name != 'pull_request' | |
env: | |
COSIGN_EXPERIMENTAL: 1 | |
run: | | |
echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | while read -r image; do | |
cosign sign --yes "${image}" | |
done | |
- name: Verify Docker manifest | |
run: | | |
docker buildx imagetools inspect sholdee/adguardexporter:latest | |
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:latest | |
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then | |
docker buildx imagetools inspect sholdee/adguardexporter:develop | |
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:develop | |
fi |