Skip to content

Docker

Docker #216

name: Docker
on:
workflow_dispatch:
push:
branches:
- main
tags:
- "v*.*.*"
# pull_request:
# branches:
# - main
schedule:
- cron: "0 4 * * 6"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
name: Build, push & sign
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Go - Setup
uses: actions/setup-go@v5
with:
go-version: "1.22.5"
- name: Go - Install dependencies
run: go mod download
- name: Go - Build
run: CGO_ENABLED=0 go build -o build/vault-bootstrap
- name: Docker - Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Docker - Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker - Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
latest
type=sha,prefix=
- name: Docker - Build and push image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Docker - Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
- name: Docker - Sign the published image
if: github.event_name != 'pull_request'
run: |
cosign sign --yes \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}