Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Arm Images #5041

Merged
merged 9 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/scripts/install-docker.sh
Expand Up @@ -4,4 +4,8 @@ set -x
VER="20.10.19"
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
mv /tmp/docker/* /usr/bin
docker run --privileged --rm tonistiigi/binfmt --install all
2 changes: 1 addition & 1 deletion .github/workflows/test-build-deploy.yml
Expand Up @@ -141,7 +141,7 @@ jobs:
run: |
export CORTEX_IMAGE_PREFIX="${IMAGE_PREFIX:-quay.io/cortexproject/}"
export IMAGE_TAG=$(make image-tag)
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:$IMAGE_TAG"
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:$IMAGE_TAG-amd64"
export CORTEX_CHECKOUT_DIR="/go/src/github.com/cortexproject/cortex"
echo "Running integration tests with image: $CORTEX_IMAGE"
go test -tags=requires_docker -timeout 2400s -v -count=1 ./integration/...
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
* [FEATURE] Query Frontend: Log query params in query frontend even if error happens. #5005
* [FEATURE] Ingester: Enable snapshotting of In-memory TSDB on disk during shutdown via `-blocks-storage.tsdb.memory-snapshot-on-shutdown`. #5011
* [FEATURE] Query Frontend/Scheduler: Add a new counter metric `cortex_request_queue_requests_total` for total requests going to queue. #5030
* [FEATURE] Build ARM docker images. #5041
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008

## 1.14.0 2022-12-02
Expand Down
26 changes: 19 additions & 7 deletions Makefile
Expand Up @@ -9,6 +9,9 @@
VERSION=$(shell cat "./VERSION" 2> /dev/null)
GOPROXY_VALUE=$(shell go env GOPROXY)

# ARCHS
ARCHS = amd64 arm64

# Boiler plate for building Docker containers.
# All this must go at top of file I'm afraid.
IMAGE_PREFIX ?= quay.io/cortexproject/
Expand Down Expand Up @@ -37,8 +40,9 @@ SED ?= $(shell which gsed 2>/dev/null || which sed)
# Dependencies (i.e. things that go in the image) still need to be explicitly
# declared.
%/$(UPTODATE): %/Dockerfile
@echo
$(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)/
for arch in $(ARCHS); do \
$(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)/ ; \
done
@echo
@echo Please use push-multiarch-build-image to build and push build image for all supported architectures.
touch $@
Expand Down Expand Up @@ -160,7 +164,11 @@ else
exes: $(EXES)

$(EXES):
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
@for arch in $(ARCHS); do \
echo "Building $@ for $$arch";\
CGO_ENABLED=0 GOARCH=$$arch GOOS=linux go build $(GO_FLAGS) -o $@-$$arch ./$(@D); \
done


protos: $(PROTO_GOS)

Expand Down Expand Up @@ -272,16 +280,20 @@ clean-protos:

save-images:
@mkdir -p docker-images
for image_name in $(IMAGE_NAMES); do \
@for image_name in $(IMAGE_NAMES); do \
if ! echo $$image_name | grep build; then \
docker save $$image_name:$(IMAGE_TAG) -o docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
for arch in $(ARCHS); do \
docker save $$image_name:$(IMAGE_TAG)-$$arch -o docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG)-$$arch; \
done;\
fi \
done

load-images:
for image_name in $(IMAGE_NAMES); do \
@for image_name in $(IMAGE_NAMES); do \
if ! echo $$image_name | grep build; then \
docker load -i docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG); \
for arch in $(ARCHS); do \
docker load -i docker-images/$$(echo $$image_name | tr "/" _):$(IMAGE_TAG)-$$arch; \
done;\
fi \
done

Expand Down
4 changes: 3 additions & 1 deletion cmd/cortex/Dockerfile
@@ -1,7 +1,9 @@
FROM alpine:3.14
ARG TARGETARCH

RUN apk add --no-cache ca-certificates
COPY migrations /migrations/
COPY cortex /bin/cortex
COPY cortex-$TARGETARCH /bin/cortex
EXPOSE 80
ENTRYPOINT [ "/bin/cortex" ]

Expand Down
4 changes: 3 additions & 1 deletion cmd/query-tee/Dockerfile
@@ -1,6 +1,8 @@
FROM alpine:3.14
ARG TARGETARCH

RUN apk add --no-cache ca-certificates
COPY query-tee /
COPY query-tee-$TARGETARCH /query-tee
ENTRYPOINT ["/query-tee"]

ARG revision
Expand Down
3 changes: 2 additions & 1 deletion cmd/test-exporter/Dockerfile
@@ -1,6 +1,7 @@
FROM alpine:3.14
ARG TARGETARCH
RUN apk add --no-cache ca-certificates
COPY test-exporter /
COPY test-exporter-$TARGETARCH /test-exporter
ENTRYPOINT ["/test-exporter"]

ARG revision
Expand Down
3 changes: 2 additions & 1 deletion cmd/thanosconvert/Dockerfile
@@ -1,6 +1,7 @@
FROM alpine:3.14
ARG TARGETARCH
RUN apk add --no-cache ca-certificates
COPY thanosconvert /
COPY thanosconvert-$TARGETARCH /thanosconvert
ENTRYPOINT ["/thanosconvert"]

ARG revision
Expand Down
23 changes: 18 additions & 5 deletions push-images
Expand Up @@ -29,19 +29,32 @@ done

push_image() {
local image="$1"
echo "Pushing ${image}:${IMAGE_TAG}"
docker push ${image}:${IMAGE_TAG}

for arch in amd64 arm64; do \
echo "Pushing ${image}-linux:${IMAGE_TAG}-$arch"
docker tag ${image}:${IMAGE_TAG}-$arch ${image}-linux:${IMAGE_TAG}-$arch
docker push ${image}-linux:${IMAGE_TAG}-$arch
done;

docker manifest create ${image}:${IMAGE_TAG} --amend ${image}-linux:${IMAGE_TAG}-amd64 --amend ${image}-linux:${IMAGE_TAG}-arm64
docker manifest push ${image}:${IMAGE_TAG}


if [ -n "${NO_QUAY}" ]; then
return
fi

# remove the quay prefix and push to docker hub
docker_hub_image=${image#$QUAY_PREFIX}
docker tag ${image}:${IMAGE_TAG} ${docker_hub_image}:${IMAGE_TAG}
for arch in amd64 arm64; do \
docker tag ${image}:${IMAGE_TAG}-$arch ${docker_hub_image}-linux:${IMAGE_TAG}-$arch

echo "Pushing ${docker_hub_image}-linux:${IMAGE_TAG}-$arch"
docker push ${docker_hub_image}-linux:${IMAGE_TAG}-$arch
done;

echo "Pushing ${docker_hub_image}:${IMAGE_TAG}"
docker push ${docker_hub_image}:${IMAGE_TAG}
docker manifest create ${docker_hub_image}:${IMAGE_TAG} --amend ${docker_hub_image}-linux:${IMAGE_TAG}-amd64 --amend ${docker_hub_image}-linux:${IMAGE_TAG}-arm64
docker manifest push ${docker_hub_image}:${IMAGE_TAG}
}

for image in ${IMAGES}; do
Expand Down