diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml index 092f346..c5a3c58 100644 --- a/.github/workflows/build-images.yaml +++ b/.github/workflows/build-images.yaml @@ -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 }} - - - name: Format tags - id: format-tags - # prepends DOCKER_BASE_NAME to every entry in the string ${{ inputs.tags }} + go-version-file: src/go.mod + cache-dependency-path: src/go.sum + + + - 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 diff --git a/.github/workflows/workflow_full-test-suite.yaml b/.github/workflows/workflow_full-test-suite.yaml index 88e2a40..97132b9 100644 --- a/.github/workflows/workflow_full-test-suite.yaml +++ b/.github/workflows/workflow_full-test-suite.yaml @@ -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 diff --git a/.github/workflows/workflow_tagged-build.yaml b/.github/workflows/workflow_tagged-build.yaml index cd1566f..9aaf3d3 100644 --- a/.github/workflows/workflow_tagged-build.yaml +++ b/.github/workflows/workflow_tagged-build.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index fd2186d..0000000 --- a/Dockerfile +++ /dev/null @@ -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"] diff --git a/src/go.mod b/src/go.mod index f84e3cf..5aa8297 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,4 +1,4 @@ -module github.com/neoskop/cert-manager-webhook-dnsimple +module github.com/puzzle/cert-manager-webhook-dnsimple go 1.22