Skip to content

Commit dbc85b1

Browse files
authored
Merge pull request #28 from fluxcd/push-ghcr
Publish signed multi-arch container images to GHCR
2 parents 315cda4 + c26ec05 commit dbc85b1

File tree

7 files changed

+83
-14
lines changed

7 files changed

+83
-14
lines changed

.github/workflows/release.yaml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ permissions:
1010
id-token: write # needed for keyless signing
1111
packages: write # needed for ghcr access
1212

13+
env:
14+
CONTROLLER: ${{ github.event.repository.name }}
15+
1316
jobs:
1417
release:
1518
runs-on: ubuntu-latest
@@ -26,9 +29,47 @@ jobs:
2629
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
2730
restore-keys: |
2831
${{ runner.os }}-go-
32+
- uses: docker/setup-qemu-action@v1
33+
- uses: docker/setup-buildx-action@v1
2934
- uses: sigstore/cosign-installer@main
3035
- uses: anchore/sbom-action/download-syft@v0
31-
- uses: goreleaser/goreleaser-action@v2
36+
- name: Docker login ghcr.io
37+
uses: docker/login-action@v1
38+
with:
39+
registry: ghcr.io
40+
username: fluxcdbot
41+
password: ${{ secrets.GHCR_TOKEN }}
42+
- name: Docker login docker.io
43+
uses: docker/login-action@v1
44+
with:
45+
username: fluxcdbot
46+
password: ${{ secrets.DOCKER_FLUXCD_PASSWORD }}
47+
- name: Docker meta
48+
id: meta
49+
uses: docker/metadata-action@v3
50+
with:
51+
images: |
52+
fluxcd/${{ env.CONTROLLER }}
53+
ghcr.io/fluxcd/${{ env.CONTROLLER }}
54+
tags: |
55+
type=raw,value={{tag}}
56+
- name: Docker push
57+
uses: docker/build-push-action@v2
58+
with:
59+
push: true
60+
builder: ${{ steps.buildx.outputs.name }}
61+
context: .
62+
file: ./Dockerfile
63+
platforms: linux/amd64,linux/arm/v7,linux/arm64
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
- name: Cosign sign ghcr.io
67+
env:
68+
COSIGN_EXPERIMENTAL: 1
69+
run: |
70+
cosign sign --recursive ghcr.io/fluxcd/${{ env.CONTROLLER }}:${GITHUB_REF/refs\/tags\//}
71+
- name: GoReleaser publish signed SBOM
72+
uses: goreleaser/goreleaser-action@v2
3273
with:
3374
version: latest
3475
args: release --rm-dist

.goreleaser.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ builds:
55

66
release:
77
prerelease: auto
8+
footer: |
9+
## Signed images
10+
11+
Verify and pull the container image:
12+
13+
```
14+
COSIGN_EXPERIMENTAL=1 cosign verify ghcr.io/fluxcd/{{.ProjectName}}:{{.Tag}}
15+
docker pull ghcr.io/fluxcd/{{.ProjectName}}:{{.Tag}}
16+
```
17+
18+
Supported architectures: `linux/amd64`, `linux/arm64` and `linux/arm/v7`.
819
920
changelog:
1021
use: github-native

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ meeting](https://docs.google.com/document/d/1l_M0om0qUEN_NNiGgpqJ2tvsF2iioHkaARD
4040
### How to run the test suite
4141

4242
Prerequisites:
43-
* go >= 1.16
44-
* kubebuilder >= 3.0
45-
* kustomize >= 4.0
43+
* go >= 1.17
44+
* docker >= 20.10
45+
* kustomize >= 4.4
4646

4747
You can run the unit tests by simply doing
4848

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
FROM golang:1.17-alpine as builder
1+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine as builder
2+
3+
# Copy the build utilities.
4+
COPY --from=xx / /
5+
6+
ARG TARGETPLATFORM
27

38
WORKDIR /workspace
49

10+
# copy api submodule
11+
COPY api/ api/
12+
513
# copy modules manifests
614
COPY go.mod go.mod
715
COPY go.sum go.sum
@@ -14,7 +22,8 @@ COPY main.go main.go
1422
COPY controllers/ controllers/
1523

1624
# build
17-
RUN CGO_ENABLED=0 go build -a -o source-watcher main.go
25+
ENV CGO_ENABLED=0
26+
RUN xx-go build -a -o source-watcher main.go
1827

1928
FROM alpine:3.15
2029

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
# Image URL to use all building/pushing image targets
3-
IMG ?= controller:latest
2+
IMG ?= fluxcd/source-watcher:latest
43
# Produce CRDs that work back to Kubernetes 1.16
54
CRD_OPTIONS ?= crd:crdVersions=v1
65

@@ -11,6 +10,11 @@ else
1110
GOBIN=$(shell go env GOBIN)
1211
endif
1312

13+
# Allows for defining additional Docker buildx arguments, e.g. '--push'.
14+
BUILD_ARGS ?=
15+
# Architectures to build images for.
16+
BUILD_PLATFORMS ?= linux/amd64
17+
1418
# Architecture to use envtest with
1519
ENVTEST_ARCH ?= amd64
1620

@@ -63,8 +67,12 @@ generate: controller-gen
6367
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
6468

6569
# Build the docker image
66-
docker-build: test
67-
docker build . -t ${IMG}
70+
docker-build:
71+
docker buildx build \
72+
--platform=$(BUILD_PLATFORMS) \
73+
-t ${IMG} \
74+
--load \
75+
${BUILD_ARGS} .
6876

6977
# Push the docker image
7078
docker-push:

config/manager/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
terminationGracePeriodSeconds: 10
2121
containers:
2222
- name: manager
23-
image: source-watcher
23+
image: ghcr.io/fluxcd/source-watcher
2424
imagePullPolicy: IfNotPresent
2525
securityContext:
2626
allowPrivilegeEscalation: false

config/manager/kustomization.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ kind: Kustomization
33
resources:
44
- deployment.yaml
55
images:
6-
- name: source-watcher
7-
newName: source-watcher
8-
newTag: v0.2.0
6+
- name: ghcr.io/fluxcd/source-watcher
7+
newName: ghcr.io/fluxcd/source-watcher
8+
newTag: v0.10.0

0 commit comments

Comments
 (0)