Skip to content

Use KO for building and pushing images #8

Use KO for building and pushing images

Use KO for building and pushing images #8

Workflow file for this run

name: Create and publish a Docker image to ghcr on main and nightly with ko
on:
push:
branches:
- main
- nightly
paths:
- "**.go"
pull_request:
paths:
- "**.yaml"
env:
REGISTRY: ghcr.io
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.platform }}
cancel-in-progress: true
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- uses: ko-build/[email protected]
- name: Build and push images
shell: bash
run: |
set -x
if [[ ${github.ref} == "refs/pull/*" ]]; then
tag=pr-$(echo ${{ github.head_ref }} | cut -c11-|sed 's,/merge,,)
else
tag=$(echo ${{ github.ref }} | cut -c11-)
fi
for image in cmd/*/main.go;do
ko build -t ${tag} --platform=${{ matrix.platform }} ${image}
done