Skip to content

Commit fb14b14

Browse files
authored
Build image now supports linux/arm64 as well (#4165)
* Modify build-image to support linux/{amd64,arm64} Added new Makefile target to build multi-arch build image. Signed-off-by: Peter Štibraný <[email protected]> * Don't push multiarch to tag-less image name. Signed-off-by: Peter Štibraný <[email protected]> * Remove downloaded hugo. Signed-off-by: Peter Štibraný <[email protected]> * Address review feedback. Signed-off-by: Peter Štibraný <[email protected]> * Added back checking of digest for shfmt. Also check digest of downloaded hugo. Signed-off-by: Peter Štibraný <[email protected]> * Build hugo from scratch again. We need 'extended' version, and binaries for this version are not available for our archs. Signed-off-by: Peter Štibraný <[email protected]> * Cleanup /root/.cache as well, to reduce image size. Signed-off-by: Peter Štibraný <[email protected]> * Build images for individual platforms separately. Signed-off-by: Peter Štibraný <[email protected]> * Use new image. Signed-off-by: Peter Štibraný <[email protected]> * Split tagging again. Signed-off-by: Peter Štibraný <[email protected]> * Update how-to-update-the-build-image.md doc. Signed-off-by: Peter Štibraný <[email protected]> * Add comment about BuildKit. Signed-off-by: Peter Štibraný <[email protected]> * Add comment about Buildx Signed-off-by: Peter Štibraný <[email protected]>
1 parent 79ce1d7 commit fb14b14

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
container:
13-
image: quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021
13+
image: quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6
1414
steps:
1515
- name: Checkout Repo
1616
uses: actions/checkout@v2
@@ -34,7 +34,7 @@ jobs:
3434
test:
3535
runs-on: ubuntu-latest
3636
container:
37-
image: quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021
37+
image: quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6
3838
services:
3939
cassandra:
4040
image: cassandra:3.11
@@ -55,7 +55,7 @@ jobs:
5555
build:
5656
runs-on: ubuntu-latest
5757
container:
58-
image: quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021
58+
image: quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6
5959
steps:
6060
- name: Checkout Repo
6161
uses: actions/checkout@v2
@@ -174,14 +174,14 @@ jobs:
174174
run: |
175175
touch build-image/.uptodate
176176
MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations
177-
make BUILD_IMAGE=quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021 TTY='' configs-integration-test
177+
make BUILD_IMAGE=quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6 TTY='' configs-integration-test
178178
179179
deploy_website:
180180
needs: [build, test]
181181
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex'
182182
runs-on: ubuntu-latest
183183
container:
184-
image: quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021
184+
image: quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6
185185
steps:
186186
- name: Checkout Repo
187187
uses: actions/checkout@v2
@@ -218,7 +218,7 @@ jobs:
218218
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex'
219219
runs-on: ubuntu-latest
220220
container:
221-
image: quay.io/cortexproject/build-image:2021w14_go1.16-afe06f021
221+
image: quay.io/cortexproject/build-image:build-image-multiarch-1d2497ff6
222222
steps:
223223
- name: Checkout Repo
224224
uses: actions/checkout@v2

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# WARNING: do not commit to a repository!
33
-include Makefile.local
44

5-
.PHONY: all test cover clean images protos exes dist doc clean-doc check-doc
5+
.PHONY: all test cover clean images protos exes dist doc clean-doc check-doc push-multiarch-build-image
66
.DEFAULT_GOAL := all
77

88
# Version number
@@ -40,8 +40,19 @@ SED ?= $(shell which gsed 2>/dev/null || which sed)
4040
@echo
4141
$(SUDO) docker build --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)$(shell basename $(@D)) $(@D)/
4242
$(SUDO) docker tag $(IMAGE_PREFIX)$(shell basename $(@D)) $(IMAGE_PREFIX)$(shell basename $(@D)):$(IMAGE_TAG)
43+
@echo
44+
@echo Please use push-multiarch-build-image to build and push build image for all supported architectures.
4345
touch $@
4446

47+
push-multiarch-build-image:
48+
@echo
49+
# Build image for each platform separately... it tends to generate fewer errors.
50+
$(SUDO) docker buildx build --platform linux/amd64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) build-image/
51+
$(SUDO) docker buildx build --platform linux/arm64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) build-image/
52+
# This command will run the same build as above, but it will reuse existing platform-specific images,
53+
# put them together and push to registry.
54+
$(SUDO) docker buildx build -o type=registry --platform linux/amd64,linux/arm64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)build-image:$(IMAGE_TAG) build-image/
55+
4556
# We don't want find to scan inside a bunch of directories, to accelerate the
4657
# 'make: Entering directory '/go/src/github.com/cortexproject/cortex' phase.
4758
DONT_FIND := -name vendor -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o -name packaging -prune -o

build-image/Dockerfile

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,43 @@ RUN npm install -g [email protected] [email protected]
1313
ENV HUGO_VERSION=v0.72.0
1414
RUN git clone https://github.com/gohugoio/hugo.git --branch ${HUGO_VERSION} --depth 1 && \
1515
cd hugo && go install --tags extended && cd ../ && \
16-
rm -rf hugo/ && rm -rf /go/pkg /go/src
17-
ENV SHFMT_VERSION=3.1.0
18-
RUN curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v${SHFMT_VERSION}/shfmt_v${SHFMT_VERSION}_linux_amd64 && \
19-
echo "cb91ea08a075a2f96b5230f09b4e211b7c108b1c97603caceb48d117d2ac5508 shfmt" | sha256sum -c && \
16+
rm -rf hugo/ && rm -rf /go/pkg /go/src /root/.cache
17+
18+
ENV SHFMT_VERSION=3.2.4
19+
RUN GOARCH=$(go env GOARCH) && \
20+
if [ "$GOARCH" = "amd64" ]; then \
21+
DIGEST=3f5a47f8fec27fae3e06d611559a2063f5d27e4b9501171dde9959b8c60a3538; \
22+
elif [ "$GOARCH" = "arm64" ]; then \
23+
DIGEST=6474d9cc08a1c9fe2ef4be7a004951998e3067d46cf55a011ddd5ff7bfab3de6; \
24+
fi && \
25+
URL=https://github.com/mvdan/sh/releases/download/v${SHFMT_VERSION}/shfmt_v${SHFMT_VERSION}_linux_${GOARCH}; \
26+
curl -fsSLo shfmt "${URL}" && \
27+
echo "$DIGEST shfmt" | sha256sum -c && \
2028
chmod +x shfmt && \
2129
mv shfmt /usr/bin
30+
2231
RUN curl -sfL https://github.com/raw/golangci/golangci-lint/master/install.sh| sh -s -- -b /usr/bin v1.27.0
23-
RUN GO111MODULE=on go get -tags netgo \
32+
33+
RUN GO111MODULE=on go get \
2434
github.com/client9/misspell/cmd/[email protected] \
2535
github.com/golang/protobuf/[email protected] \
2636
github.com/gogo/protobuf/[email protected] \
2737
github.com/gogo/protobuf/[email protected] \
28-
github.com/weaveworks/tools/cover@bdd647e92546027e12cdde3ae0714bb495e43013 && \
29-
rm -rf /go/pkg /go/src
38+
github.com/weaveworks/tools/cover@bdd647e92546027e12cdde3ae0714bb495e43013 \
39+
github.com/fatih/[email protected] \
40+
github.com/campoy/[email protected] \
41+
&& rm -rf /go/pkg /go/src /root/.cache
3042

31-
ENV KUBEVAL_VERSION=0.15.0
32-
RUN curl -Ls https://github.com/instrumenta/kubeval/releases/download/${KUBEVAL_VERSION}/kubeval-linux-amd64.tar.gz -o /tmp/kubeval-linux-amd64.tar.gz && \
33-
tar -xf /tmp/kubeval-linux-amd64.tar.gz -C /tmp && \
34-
cp /tmp/kubeval /usr/local/bin && \
35-
rm -f /tmp/kubeval*
43+
# Cannot get it to run together in above go get.
44+
RUN GO111MODULE=on go get \
45+
github.com/instrumenta/[email protected] \
46+
&& rm -rf /go/pkg /go/src /root/.cache
3647

3748
ENV NODE_PATH=/usr/lib/node_modules
3849
COPY build.sh /
3950
ENV GOCACHE=/go/cache
4051
ENTRYPOINT ["/build.sh"]
4152

42-
# Install faillint used to lint go imports in CI.
43-
ENV FAILLINT_VERSION=1.5.0
44-
RUN GO111MODULE=on go get github.com/fatih/faillint@v${FAILLINT_VERSION} && \
45-
rm -rf /go/pkg /go/src
46-
47-
# Install embedmd used to embed content into markdown files.
48-
ENV EMBEDMD_VERSION=1.0.0
49-
RUN GO111MODULE=on go get github.com/campoy/embedmd@v${EMBEDMD_VERSION} && \
50-
rm -rf /go/pkg /go/src
51-
5253
ARG revision
5354
LABEL org.opencontainers.image.title="build-image" \
5455
org.opencontainers.image.source="https://github.com/cortexproject/cortex/tree/master/build-image" \

docs/contributing/how-to-update-the-build-image.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ slug: how-to-update-the-build-image
77

88
The build image currently can only be updated by a Cortex maintainer. If you're not a maintainer you can still open a PR with the changes, asking a maintainer to assist you publishing the updated image. The procedure is:
99

10-
1. Update `build-image/Docker`
11-
2. Build the image running `make build-image/.uptodate`
12-
3. Publish the image to the repository running `docker push quay.io/cortexproject/build-image:TAG` (this can only be done by a maintainer)
13-
4. Replace the image tag in `.github/workflows/*` (_there may be multiple references_)
14-
5. Open a PR and make sure the CI with new build-image passes
10+
1. Update `build-image/Docker`.
11+
2. Build the and publish the image by using `make push-multiarch-build-image`. This will build and push multiplatform docker image (for linux/amd64 and linux/arm64). Pushing to `quay.io/cortexproject/build-image` repository can only be done by a maintainer. Running this step successfully requires [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/), but does not require a specific platform.
12+
3. Replace the image tag in `.github/workflows/*` (_there may be multiple references_)
13+
4. Open a PR and make sure the CI with new build-image passes

0 commit comments

Comments
 (0)