Skip to content

Commit 20901f8

Browse files
committed
Building Arm Images (#5041)
* wip Signed-off-by: Alan Protasio <[email protected]> * est Signed-off-by: Alan Protasio <[email protected]> * quay Signed-off-by: Alan Protasio <[email protected]> * using different repository for the archteture specific images Signed-off-by: Alan Protasio <[email protected]> * testing linux repos Signed-off-by: Alan Protasio <[email protected]> * testing manifes on both platforms Signed-off-by: Alan Protasio <[email protected]> * enabling deploy stage only on master Signed-off-by: Alan Protasio <[email protected]> * changelog Signed-off-by: Alan Protasio <[email protected]> * using amd64 image for e2e teests Signed-off-by: Alan Protasio <[email protected]> Signed-off-by: Alan Protasio <[email protected]> Signed-off-by: Alan Protasio <[email protected]>
1 parent 65bbbc6 commit 20901f8

File tree

9 files changed

+53
-17
lines changed

9 files changed

+53
-17
lines changed

.github/workflows/scripts/install-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ set -x
44
VER="20.10.19"
55
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
66
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
7+
mkdir -vp ~/.docker/cli-plugins/
8+
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
9+
chmod a+x ~/.docker/cli-plugins/docker-buildx
710
mv /tmp/docker/* /usr/bin
11+
docker run --privileged --rm tonistiigi/binfmt --install all

.github/workflows/test-build-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
run: |
140140
export CORTEX_IMAGE_PREFIX="${IMAGE_PREFIX:-quay.io/cortexproject/}"
141141
export IMAGE_TAG=$(make image-tag)
142-
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:$IMAGE_TAG"
142+
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:$IMAGE_TAG-amd64"
143143
export CORTEX_CHECKOUT_DIR="/go/src/github.com/cortexproject/cortex"
144144
echo "Running integration tests with image: $CORTEX_IMAGE"
145145
go test -tags=requires_docker -timeout 2400s -v -count=1 ./integration/...

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
* [CHANGE] Alertmanager: Local file disclosure vulnerability in OpsGenie configuration has been fixed. #5045
77
* [BUGFIX] Fix panic when otel and xray tracing is enabled. #5044
8+
* [FEATURE] Build ARM docker images. #5041
89

910
## 1.14.0 2022-12-02
1011

Makefile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
VERSION=$(shell cat "./VERSION" 2> /dev/null)
1010
GOPROXY_VALUE=$(shell go env GOPROXY)
1111

12+
# ARCHS
13+
ARCHS = amd64 arm64
14+
1215
# Boiler plate for building Docker containers.
1316
# All this must go at top of file I'm afraid.
1417
IMAGE_PREFIX ?= quay.io/cortexproject/
@@ -37,8 +40,9 @@ SED ?= $(shell which gsed 2>/dev/null || which sed)
3740
# Dependencies (i.e. things that go in the image) still need to be explicitly
3841
# declared.
3942
%/$(UPTODATE): %/Dockerfile
40-
@echo
41-
$(SUDO) docker build --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)$(shell basename $(@D)) -t $(IMAGE_PREFIX)$(shell basename $(@D)):$(IMAGE_TAG) $(@D)/
43+
for arch in $(ARCHS); do \
44+
$(SUDO) docker buildx build --platform linux/$$arch --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)$(shell basename $(@D)) -t $(IMAGE_PREFIX)$(shell basename $(@D)):$(IMAGE_TAG)-$$arch $(@D)/ ; \
45+
done
4246
@echo
4347
@echo Please use push-multiarch-build-image to build and push build image for all supported architectures.
4448
touch $@
@@ -160,7 +164,11 @@ else
160164
exes: $(EXES)
161165

162166
$(EXES):
163-
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
167+
@for arch in $(ARCHS); do \
168+
echo "Building $@ for $$arch";\
169+
CGO_ENABLED=0 GOARCH=$$arch GOOS=linux go build $(GO_FLAGS) -o $@-$$arch ./$(@D); \
170+
done
171+
164172

165173
protos: $(PROTO_GOS)
166174

@@ -272,16 +280,20 @@ clean-protos:
272280

273281
save-images:
274282
@mkdir -p docker-images
275-
for image_name in $(IMAGE_NAMES); do \
283+
@for image_name in $(IMAGE_NAMES); do \
276284
if ! echo $$image_name | grep build; then \
277-
docker save $$image_name:$(IMAGE_TAG) -o docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
285+
for arch in $(ARCHS); do \
286+
docker save $$image_name:$(IMAGE_TAG)-$$arch -o docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG)-$$arch; \
287+
done;\
278288
fi \
279289
done
280290

281291
load-images:
282-
for image_name in $(IMAGE_NAMES); do \
292+
@for image_name in $(IMAGE_NAMES); do \
283293
if ! echo $$image_name | grep build; then \
284-
docker load -i docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
294+
for arch in $(ARCHS); do \
295+
docker load -i docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG)-$$arch; \
296+
done;\
285297
fi \
286298
done
287299

cmd/cortex/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
FROM alpine:3.14
2+
ARG TARGETARCH
3+
24
RUN apk add --no-cache ca-certificates
35
COPY migrations /migrations/
4-
COPY cortex /bin/cortex
6+
COPY cortex-$TARGETARCH /bin/cortex
57
EXPOSE 80
68
ENTRYPOINT [ "/bin/cortex" ]
79

cmd/query-tee/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM alpine:3.14
2+
ARG TARGETARCH
3+
24
RUN apk add --no-cache ca-certificates
3-
COPY query-tee /
5+
COPY query-tee-$TARGETARCH /query-tee
46
ENTRYPOINT ["/query-tee"]
57

68
ARG revision

cmd/test-exporter/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM alpine:3.14
2+
ARG TARGETARCH
23
RUN apk add --no-cache ca-certificates
3-
COPY test-exporter /
4+
COPY test-exporter-$TARGETARCH /test-exporter
45
ENTRYPOINT ["/test-exporter"]
56

67
ARG revision

cmd/thanosconvert/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM alpine:3.14
2+
ARG TARGETARCH
23
RUN apk add --no-cache ca-certificates
3-
COPY thanosconvert /
4+
COPY thanosconvert-$TARGETARCH /thanosconvert
45
ENTRYPOINT ["/thanosconvert"]
56

67
ARG revision

push-images

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,32 @@ done
2929

3030
push_image() {
3131
local image="$1"
32-
echo "Pushing ${image}:${IMAGE_TAG}"
33-
docker push ${image}:${IMAGE_TAG}
32+
33+
for arch in amd64 arm64; do \
34+
echo "Pushing ${image}-linux:${IMAGE_TAG}-$arch"
35+
docker tag ${image}:${IMAGE_TAG}-$arch ${image}-linux:${IMAGE_TAG}-$arch
36+
docker push ${image}-linux:${IMAGE_TAG}-$arch
37+
done;
38+
39+
docker manifest create ${image}:${IMAGE_TAG} --amend ${image}-linux:${IMAGE_TAG}-amd64 --amend ${image}-linux:${IMAGE_TAG}-arm64
40+
docker manifest push ${image}:${IMAGE_TAG}
41+
3442

3543
if [ -n "${NO_QUAY}" ]; then
3644
return
3745
fi
3846

3947
# remove the quay prefix and push to docker hub
4048
docker_hub_image=${image#$QUAY_PREFIX}
41-
docker tag ${image}:${IMAGE_TAG} ${docker_hub_image}:${IMAGE_TAG}
49+
for arch in amd64 arm64; do \
50+
docker tag ${image}:${IMAGE_TAG}-$arch ${docker_hub_image}-linux:${IMAGE_TAG}-$arch
51+
52+
echo "Pushing ${docker_hub_image}-linux:${IMAGE_TAG}-$arch"
53+
docker push ${docker_hub_image}-linux:${IMAGE_TAG}-$arch
54+
done;
4255

43-
echo "Pushing ${docker_hub_image}:${IMAGE_TAG}"
44-
docker push ${docker_hub_image}:${IMAGE_TAG}
56+
docker manifest create ${docker_hub_image}:${IMAGE_TAG} --amend ${docker_hub_image}-linux:${IMAGE_TAG}-amd64 --amend ${docker_hub_image}-linux:${IMAGE_TAG}-arm64
57+
docker manifest push ${docker_hub_image}:${IMAGE_TAG}
4558
}
4659

4760
for image in ${IMAGES}; do

0 commit comments

Comments
 (0)