mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-01 22:35: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
|
||||
|
||||
env:
|
||||
DOCKER_BASE_NAME: 'ghcr.io/${{ github.repository_owner }}/cert-manager-webhook-dnsimple'
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
|
@ -20,30 +17,32 @@ jobs:
|
|||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v3
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
registry: ghcr.io
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
username: ${{ github.repository_owner }}
|
||||
go-version-file: src/go.mod
|
||||
cache-dependency-path: src/go.sum
|
||||
|
||||
- name: Format tags
|
||||
id: format-tags
|
||||
# prepends DOCKER_BASE_NAME to every entry in the string ${{ inputs.tags }}
|
||||
|
||||
- name: Get go dependencies
|
||||
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
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.format-tags.outputs.TAGS }}
|
||||
|
||||
- name: Setup ko
|
||||
# KO is a tool for building go container images https://ko.build/
|
||||
uses: ko-build/setup-ko@v0.6
|
||||
# KO is configured to use GHCR as the registry
|
||||
|
||||
|
||||
- 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
|
||||
uses: ./.github/workflows/build-images.yaml
|
||||
with:
|
||||
tags: >
|
||||
tags: >-
|
||||
commit-${{ github.sha }}
|
||||
latest
|
||||
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
|
||||
uses: ./.github/workflows/build-images.yaml
|
||||
with:
|
||||
tags: >
|
||||
tags: >-
|
||||
${{ github.ref_name }}
|
||||
commit-${{ github.sha }}
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue