Skip to content

Commit 7486b38

Browse files
authored
Merge pull request #125 from nunnatsa/multi-arch-images
Support creating multi-arch images
2 parents 2f2ecfe + b21375f commit 7486b38

File tree

9 files changed

+218
-86
lines changed

9 files changed

+218
-86
lines changed

Dockerfile.aaq-controller

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
# Builder stage
2-
FROM docker.io/library/golang:1.22-alpine as builder
2+
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.24-alpine as builder
33

44
# Install make
55
RUN apk update && apk add make
66

7-
# Copy the source code from the host to the container
8-
COPY pkg /workdir/app/pkg
9-
COPY staging /workdir/app/staging
10-
COPY cmd /workdir/app/cmd
11-
COPY vendor /workdir/app/vendor
12-
COPY go.mod /workdir/app/go.mod
13-
COPY go.sum /workdir/app/go.sum
14-
COPY Makefile /workdir/app/Makefile
15-
167
WORKDIR /workdir/app
178

18-
RUN make aaq_controller
9+
# Copy the source code from the host to the container
10+
COPY cmd ./cmd
11+
COPY go.mod go.sum Makefile ./
12+
COPY pkg ./pkg
13+
COPY staging ./staging
14+
COPY vendor ./vendor
15+
16+
ARG TARGETARCH
17+
RUN GOOS=linux GOARCH=${TARGETARCH} make aaq_controller
1918

2019
# Final stage
21-
FROM docker.io/library/golang:1.22-alpine
22-
23-
# Copy the binary from the builder stage to the final image
24-
COPY --from=builder /workdir/app/aaq_controller /app/aaq_controller
20+
FROM docker.io/alpine:3.22.1
2521

2622
# Set the working directory to /app
2723
WORKDIR /app
28-
29-
RUN adduser -u 1001 -D -s /bin/sh -h /app/aaq_controller aaq_controller
24+
RUN adduser -u 1001 -D -s /bin/sh -h /app aaq_controller
3025
USER 1001
3126

3227
# Set the entrypoint to the binary
33-
ENTRYPOINT ["/app/aaq_controller"]
28+
ENTRYPOINT ["/app/aaq_controller"]
29+
30+
# Copy the binary from the builder stage to the final image
31+
COPY --from=builder --chown=1001 /workdir/app/aaq_controller /app/
32+
33+
ARG git_url=https://github.com/kubevirt/application-aware-quota.git
34+
ARG git_sha=unknown
35+
36+
# this line is used to prevent the caching of the multi.GIT_SHA label
37+
RUN echo "git_sha=${git_sha}"
38+
39+
LABEL multi.GIT_URL=${git_url} \
40+
multi.GIT_SHA=${git_sha} \
41+
app=aaq-controller

Dockerfile.aaq-operator

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
# Builder stage
2-
FROM docker.io/library/golang:1.22-alpine as builder
3-
2+
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.24-alpine as builder
43

54
# Install make
65
RUN apk update && apk add make
76

8-
# Copy the source code from the host to the container
9-
COPY pkg /workdir/app/pkg
10-
COPY tools /workdir/app/tools
11-
COPY staging /workdir/app/staging
12-
COPY cmd /workdir/app/cmd
13-
COPY vendor /workdir/app/vendor
14-
COPY go.mod /workdir/app/go.mod
15-
COPY go.sum /workdir/app/go.sum
16-
COPY Makefile /workdir/app/Makefile
17-
187
WORKDIR /workdir/app
198

20-
RUN make aaq_operator
21-
RUN make csv-generator
22-
23-
# Final stage
24-
FROM docker.io/library/golang:1.22-alpine
9+
# Copy the source code from the host to the container
10+
COPY cmd ./cmd
11+
COPY go.mod go.sum Makefile ./
12+
COPY pkg ./pkg
13+
COPY staging ./staging
14+
COPY vendor ./vendor
15+
COPY tools ./tools
2516

17+
ARG TARGETARCH
18+
RUN GOOS=linux GOARCH=${TARGETARCH} make aaq_operator
19+
RUN GOOS=linux GOARCH=${TARGETARCH} make csv-generator
2620

27-
# Copy the binary from the builder stage to the final image
28-
COPY --from=builder /workdir/app/aaq_operator /app/aaq_operator
29-
COPY --from=builder /workdir/app/bin/csv-generator /usr/bin/csv-generator
21+
# Final stage
22+
FROM docker.io/alpine:3.22.1
3023

3124
# Set the working directory to /app
3225
WORKDIR /app
33-
34-
RUN adduser -u 1001 -D -s /bin/sh -h /app/aaq_operator aaq_operator
26+
RUN adduser -u 1001 -D -s /bin/sh -h /app aaq_operator
3527
USER 1001
3628

3729
# Set the entrypoint to the binary
38-
ENTRYPOINT ["/app/aaq_operator"]
30+
ENTRYPOINT ["/app/aaq_operator"]
31+
32+
# Copy the binary from the builder stage to the final image
33+
COPY --from=builder --chown=1001 /workdir/app/aaq_operator /app/
34+
COPY --from=builder --chown=1001 /workdir/app/bin/csv-generator /usr/bin/
35+
36+
ARG git_url=https://github.com/kubevirt/application-aware-quota.git
37+
ARG git_sha=unknown
38+
39+
# this line is used to prevent the caching of the multi.GIT_SHA label
40+
RUN echo "git_sha=${git_sha}"
41+
42+
LABEL multi.GIT_URL=${git_url} \
43+
multi.GIT_SHA=${git_sha} \
44+
app=aaq-operator

Dockerfile.aaq-server

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
# Builder stage
2-
FROM docker.io/library/golang:1.22-alpine as builder
2+
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.24-alpine as builder
33

44
# Install make
55
RUN apk update && apk add make
66

7-
# Copy the source code from the host to the container
8-
COPY pkg /workdir/app/pkg
9-
COPY staging /workdir/app/staging
10-
COPY cmd /workdir/app/cmd
11-
COPY vendor /workdir/app/vendor
12-
COPY go.mod /workdir/app/go.mod
13-
COPY go.sum /workdir/app/go.sum
14-
COPY Makefile /workdir/app/Makefile
15-
167
WORKDIR /workdir/app
178

18-
RUN make aaq_server
9+
# Copy the source code from the host to the container
10+
COPY cmd ./cmd
11+
COPY go.mod go.sum Makefile ./
12+
COPY pkg ./pkg
13+
COPY staging ./staging
14+
COPY vendor ./vendor
15+
16+
ARG TARGETARCH
17+
RUN GOOS=linux GOARCH=${TARGETARCH} make aaq_server
1918

2019
# Final stage
21-
FROM docker.io/library/golang:1.22-alpine
22-
23-
# Copy the binary from the builder stage to the final image
24-
COPY --from=builder /workdir/app/aaq_server /app/aaq_server
20+
FROM docker.io/alpine:3.22.1
2521

2622
# Set the working directory to /app
2723
WORKDIR /app
28-
29-
RUN adduser -u 1001 -D -s /bin/sh -h /app/aaq_server aaq_server
24+
RUN adduser -u 1001 -D -s /bin/sh -h /app aaq_server
3025
USER 1001
3126

3227
# Set the entrypoint to the binary
33-
ENTRYPOINT ["/app/aaq_server"]
28+
ENTRYPOINT ["/app/aaq_server"]
29+
30+
# Copy the binary from the builder stage to the final image
31+
COPY --from=builder --chown=1001 /workdir/app/aaq_server /app/
32+
33+
ARG git_url=https://github.com/kubevirt/application-aware-quota.git
34+
ARG git_sha=unknown
35+
36+
# this line is used to prevent the caching of the multi.GIT_SHA label
37+
RUN echo "git_sha=${git_sha}"
38+
39+
LABEL multi.GIT_URL=${git_url} \
40+
multi.GIT_SHA=${git_sha} \
41+
app=aaq-server

Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#See the License for the specific language governing permissions and
1313
#limitations under the License.
1414

15+
GOARCH ?= $(shell go env GOARCH)
16+
1517
.PHONY: manifests \
1618
cluster-up cluster-down cluster-sync \
1719
test test-functional test-unit test-lint \
@@ -69,6 +71,9 @@ build-images:
6971

7072
push: build-images push-images
7173

74+
push-multi-arch:
75+
./hack/build/build-push-multiarch-images.sh
76+
7277
cluster-clean-aaq:
7378
./cluster-sync/clean.sh
7479

@@ -90,20 +95,20 @@ bootstrap-ginkgo:
9095
${DO_BAZ} ./hack/build/bootstrap-ginkgo.sh
9196

9297
aaq_controller:
93-
go build -o aaq_controller -v cmd/aaq-controller/*.go
94-
chmod 777 aaq_controller
98+
echo "Building aaq_controller for linux/${GOARCH}"
99+
go build -o aaq_controller ./cmd/aaq-controller
95100

96101
aaq_operator:
97-
go build -o aaq_operator -v cmd/aaq-operator/*.go
98-
chmod 777 aaq_operator
102+
echo "Building aaq_operator for linux/${GOARCH}"
103+
go build -o aaq_operator ./cmd/aaq-operator
99104

100105
aaq_server:
101-
go build -o aaq_server -v cmd/aaq-server/*.go
102-
chmod 777 aaq_server
106+
echo "Building aaq_server for linux/${GOARCH}"
107+
go build -o aaq_server ./cmd/aaq-server
103108

104109
csv-generator:
105-
go build -o bin/csv-generator -v tools/csv-generator/csv-generator.go
106-
chmod 777 bin/csv-generator
110+
echo "Building csv-generator for linux/${GOARCH}"
111+
go build -o bin/csv-generator ./tools/csv-generator/
107112

108113
release-description:
109114
./hack/build/release-description.sh ${RELREF} ${PREREF}

cluster-sync/sync.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ PULL_POLICY=${PULL_POLICY:-IfNotPresent}
3636
# have to refactor/rewrite any of the code that works currently.
3737
MANIFEST_REGISTRY=$DOCKER_PREFIX
3838

39+
insecure="false"
40+
3941
if [ "${KUBEVIRT_PROVIDER}" != "external" ]; then
4042
registry=${IMAGE_REGISTRY:-localhost:$(_port registry)}
4143
DOCKER_PREFIX=${registry}
4244
MANIFEST_REGISTRY="registry:5000"
45+
insecure="true"
4346
fi
4447

4548
if [ "${KUBEVIRT_PROVIDER}" == "external" ]; then
@@ -54,7 +57,7 @@ fi
5457
# Need to set the DOCKER_PREFIX appropriately in the call to `make docker push`, otherwise make will just pass in the default `kubevirt`
5558

5659
DOCKER_PREFIX=$MANIFEST_REGISTRY PULL_POLICY=$PULL_POLICY make manifests
57-
DOCKER_PREFIX=$DOCKER_PREFIX make push
60+
DOCKER_PREFIX=$DOCKER_PREFIX INSECURE_REGISTRY="${insecure}" make push-multi-arch
5861

5962

6063
function check_structural_schema {
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
# Builder stage
2-
FROM docker.io/library/golang:1.22-alpine as builder
2+
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.24-alpine as builder
33

44
# Install make
55
RUN apk update && apk add make
66

7-
# Copy the source code from the host to the container
8-
COPY cmd /workdir/app/cmd
9-
COPY vendor /workdir/app/vendor
10-
COPY go.mod /workdir/app/go.mod
11-
COPY go.sum /workdir/app/go.sum
12-
COPY Makefile /workdir/app/Makefile
13-
147
WORKDIR /workdir/app
158

16-
RUN make label_sidecar
9+
# Copy the source code from the host to the container
10+
COPY cmd ./cmd
11+
COPY vendor ./vendor
12+
COPY go.mod ./go.mod
13+
COPY go.sum ./go.sum
14+
COPY Makefile ./Makefile
1715

18-
# Final stage
19-
FROM docker.io/library/golang:1.22-alpine
16+
ARG TARGETARCH
17+
RUN GOOS=linux GOARCH=${TARGETARCH} make label_sidecar
2018

21-
# Copy the binary from the builder stage to the final image
22-
COPY --from=builder /workdir/app/label_sidecar /app/label_sidecar
19+
# Final stage
20+
FROM docker.io/alpine:3.22.1
2321

2422
# Set the working directory to /app
2523
WORKDIR /app
2624

27-
RUN adduser -u 1001 -D -s /bin/sh -h /app/label_sidecar label_sidecar
28-
USER 1001
25+
RUN adduser -u 1001 -D -s /bin/sh -h /app label_sidecar
2926

3027
# Set the entrypoint to the binary
31-
ENTRYPOINT ["/app/label_sidecar"]
28+
ENTRYPOINT ["/app/label_sidecar"]
29+
30+
# Copy the binary from the builder stage to the final image
31+
COPY --from=builder /workdir/app/label_sidecar /app/
32+
33+
USER 1001
34+
35+
ARG git_url=https://github.com/kubevirt/application-aware-quota.git
36+
ARG git_sha=unknown
37+
38+
# this line is used to prevent the caching of the multi.GIT_SHA label
39+
RUN echo "git_sha=${git_sha}"
40+
41+
LABEL multi.GIT_URL=${git_url} \
42+
multi.GIT_SHA=${git_sha} \
43+
app=label-sidecar
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
GOARCH ?= $(shell go env GOARCH)
12

23
label_sidecar:
3-
go build -o label_sidecar -v cmd/*.go
4-
chmod 777 label_sidecar
4+
echo "Building label_sidecar for linux/${GOARCH}"
5+
go build -o label_sidecar ./cmd/

0 commit comments

Comments
 (0)