mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-02 06:45:49 +02:00
use ko to build images (#34)
This commit is contained in:
parent
97de643226
commit
1f64cdf705
5 changed files with 28 additions and 54 deletions
49
.github/workflows/build-images.yaml
vendored
49
.github/workflows/build-images.yaml
vendored
|
@ -1,8 +1,5 @@
|
||||||
name: Build docker images
|
name: Build docker images
|
||||||
|
|
||||||
env:
|
|
||||||
DOCKER_BASE_NAME: 'ghcr.io/${{ github.repository_owner }}/cert-manager-webhook-dnsimple'
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
|
@ -20,30 +17,32 @@ jobs:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Setup Go
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: actions/setup-go@v5
|
||||||
|
|
||||||
- name: Login to GHCR
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
go-version-file: src/go.mod
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
cache-dependency-path: src/go.sum
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
|
|
||||||
- name: Format tags
|
|
||||||
id: format-tags
|
- name: Get go dependencies
|
||||||
# prepends DOCKER_BASE_NAME to every entry in the string ${{ inputs.tags }}
|
|
||||||
run: |
|
run: |
|
||||||
echo "TAGS=$(printf '${{ env.DOCKER_BASE_NAME }}:%s,' ${{ inputs.tags }})" >> $GITHUB_OUTPUT
|
cd src
|
||||||
|
go mod download
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
uses: docker/build-push-action@v5
|
- name: Setup ko
|
||||||
with:
|
# KO is a tool for building go container images https://ko.build/
|
||||||
context: .
|
uses: ko-build/setup-ko@v0.6
|
||||||
file: ./Dockerfile
|
# KO is configured to use GHCR as the registry
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.format-tags.outputs.TAGS }}
|
- name: Format tags with a comma
|
||||||
|
id: format-tags
|
||||||
|
run: echo "TAGS=$(echo ${{ inputs.tags }} | tr ' ' ',')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
|
||||||
|
- name: Build images
|
||||||
|
run: |
|
||||||
|
cd src
|
||||||
|
ko build --tags="${{ steps.format-tags.outputs.TAGS }}" --platform=linux/amd64,linux/arm64 --bare --sbom=none
|
||||||
|
|
|
@ -19,7 +19,7 @@ jobs:
|
||||||
name: Build Docker image
|
name: Build Docker image
|
||||||
uses: ./.github/workflows/build-images.yaml
|
uses: ./.github/workflows/build-images.yaml
|
||||||
with:
|
with:
|
||||||
tags: >
|
tags: >-
|
||||||
commit-${{ github.sha }}
|
commit-${{ github.sha }}
|
||||||
latest
|
latest
|
||||||
needs: code-test
|
needs: code-test
|
||||||
|
|
2
.github/workflows/workflow_tagged-build.yaml
vendored
2
.github/workflows/workflow_tagged-build.yaml
vendored
|
@ -10,7 +10,7 @@ jobs:
|
||||||
name: Build tagged Docker image
|
name: Build tagged Docker image
|
||||||
uses: ./.github/workflows/build-images.yaml
|
uses: ./.github/workflows/build-images.yaml
|
||||||
with:
|
with:
|
||||||
tags: >
|
tags: >-
|
||||||
${{ github.ref_name }}
|
${{ github.ref_name }}
|
||||||
commit-${{ github.sha }}
|
commit-${{ github.sha }}
|
||||||
latest
|
latest
|
||||||
|
|
25
Dockerfile
25
Dockerfile
|
@ -1,25 +0,0 @@
|
||||||
FROM golang:1.22-alpine AS build_deps
|
|
||||||
|
|
||||||
RUN apk add --no-cache git
|
|
||||||
|
|
||||||
WORKDIR /workspace
|
|
||||||
ENV GO111MODULE=on
|
|
||||||
|
|
||||||
COPY src/go.mod .
|
|
||||||
COPY src/go.sum .
|
|
||||||
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
FROM build_deps AS build
|
|
||||||
|
|
||||||
COPY src .
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 go build -o webhook -ldflags '-w -extldflags "-static"' .
|
|
||||||
|
|
||||||
FROM alpine:3.17
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
|
||||||
|
|
||||||
COPY --from=build /workspace/webhook /usr/local/bin/webhook
|
|
||||||
|
|
||||||
ENTRYPOINT ["webhook"]
|
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/neoskop/cert-manager-webhook-dnsimple
|
module github.com/puzzle/cert-manager-webhook-dnsimple
|
||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue