Skip to content

Commit 6dd64fc

Browse files
authored
Build image in github actions (#6026)
* Build image in github actions Signed-off-by: Friedrich Gonzalez <[email protected]> * Bug fixes Signed-off-by: Friedrich Gonzalez <[email protected]> * Target master Signed-off-by: Friedrich Gonzalez <[email protected]> * Fix save-multiarch-build-image Signed-off-by: Friedrich Gonzalez <[email protected]> * Include QEMU and buildx action Signed-off-by: Friedrich Gonzalez <[email protected]> * Let's simplify and tests first Signed-off-by: Friedrich Gonzalez <[email protected]> * test push Signed-off-by: Friedrich Gonzalez <[email protected]> * Push intermediate images Signed-off-by: Friedrich Gonzalez <[email protected]> * Re-enable full build, update docs and make sure push is only possible from master Signed-off-by: Friedrich Gonzalez <[email protected]> * Fetch tags and use Makefile in build-image Signed-off-by: Friedrich Gonzalez <[email protected]> --------- Signed-off-by: Friedrich Gonzalez <[email protected]>
1 parent 057313a commit 6dd64fc

File tree

6 files changed

+98
-13
lines changed

6 files changed

+98
-13
lines changed

.github/workflows/build-image.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build Image
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- 'build-image/**'
8+
- '.github/workflows/build-image.yml'
9+
pull_request:
10+
branches: [ master ]
11+
paths:
12+
- 'build-image/**'
13+
- '.github/workflows/build-image.yml'
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- uses: actions/checkout@v4
20+
name: Checkout
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up QEMU
25+
uses: docker/setup-qemu-action@v3
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Save image
31+
run: make save-multiarch-build-image
32+
33+
- name: Upload Docker Images Artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: build-image
37+
path: |
38+
./build-image-amd64.tar
39+
./build-image-arm64.tar
40+
if-no-files-found: error
41+
42+
push:
43+
needs: build
44+
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex'
45+
runs-on: ubuntu-24.04
46+
steps:
47+
- uses: actions/checkout@v4
48+
name: Checkout
49+
with:
50+
fetch-depth: 0
51+
52+
- name: Download Docker Images Artifacts
53+
uses: actions/download-artifact@v4
54+
with:
55+
name: build-image
56+
57+
- name: Load image
58+
run: make load-multiarch-build-image
59+
60+
- name: Login to Quay.io
61+
uses: docker/login-action@v3
62+
with:
63+
registry: quay.io
64+
username: ${{secrets.QUAY_REGISTRY_USER}}
65+
password: ${{secrets.QUAY_REGISTRY_PASSWORD}}
66+
67+
- name: Push image
68+
run: make push-multiarch-build-image

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

+6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ on:
55
branches: [master]
66
tags:
77
- v[0-9]+.[0-9]+.[0-9]+** # Tag filters not as strict due to different regex system on Github Actions
8+
paths-ignore:
9+
- 'build-image/**'
10+
- '.github/workflows/build-image.yml'
811
pull_request:
12+
paths-ignore:
13+
- 'build-image/**'
14+
- '.github/workflows/build-image.yml'
915

1016
jobs:
1117
lint:

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ Makefile.local
2727
.vscode
2828
compose
2929
compose-simple
30+
31+
/build-image-arm64.tar
32+
/build-image-amd64.tar

Makefile

+1-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ fetch-build-image:
5353
docker tag $(BUILD_IMAGE):$(LATEST_BUILD_IMAGE_TAG) $(BUILD_IMAGE):latest
5454
touch build-image/.uptodate
5555

56-
push-multiarch-build-image:
57-
@echo
58-
# Build image for each platform separately... it tends to generate fewer errors.
59-
$(SUDO) docker buildx build --platform linux/amd64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) build-image/
60-
$(SUDO) docker buildx build --platform linux/arm64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) build-image/
61-
# This command will run the same build as above, but it will reuse existing platform-specific images,
62-
# put them together and push to registry.
63-
$(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/
56+
-include build-image/Makefile
6457

6558
# We don't want find to scan inside a bunch of directories, to accelerate the
6659
# 'make: Entering directory '/go/src/github.com/cortexproject/cortex' phase.

build-image/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
save-multiarch-build-image:
2+
@echo
3+
# Build image for each platform separately... it tends to generate fewer errors.
4+
$(SUDO) docker buildx build --platform linux/amd64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)build-image:$(IMAGE_TAG)-amd64 --output type=docker,dest=./build-image-amd64.tar build-image/
5+
$(SUDO) docker buildx build --platform linux/arm64 --build-arg=revision=$(GIT_REVISION) --build-arg=goproxyValue=$(GOPROXY_VALUE) -t $(IMAGE_PREFIX)build-image:$(IMAGE_TAG)-arm64 --output type=docker,dest=./build-image-arm64.tar build-image/
6+
7+
load-multiarch-build-image:
8+
$(SUDO) docker load -i build-image-amd64.tar
9+
$(SUDO) docker load -i build-image-arm64.tar
10+
11+
push-multiarch-build-image:
12+
# This command will run the same build as multiarch-build-image, but it will reuse existing platform-specific images,
13+
# put them together and push to registry.
14+
$(SUDO) docker push $(IMAGE_PREFIX)build-image:${IMAGE_TAG}-amd64
15+
$(SUDO) docker push $(IMAGE_PREFIX)build-image:${IMAGE_TAG}-arm64
16+
$(SUDO) docker manifest create $(IMAGE_PREFIX)build-image:$(IMAGE_TAG) --amend $(IMAGE_PREFIX)build-image:${IMAGE_TAG}-amd64 --amend $(IMAGE_PREFIX)build-image:${IMAGE_TAG}-arm64
17+
$(SUDO) docker manifest push $(IMAGE_PREFIX)build-image:$(IMAGE_TAG)

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ weight: 5
55
slug: how-to-update-the-build-image
66
---
77

8-
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:
8+
The procedure is:
99

1010
1. Update `build-image/Dockerfile`
11-
1. Run `go env` and make sure `GOPROXY=https://proxy.golang.org,direct` (Go's default). Some environment may required `GOPROXY=direct`, and if you push a build image with this, build workflow on GitHub will take a lot longer to download modules.
12-
1. `docker login quay.io`. Note that pushing to `quay.io/cortexproject/build-image` repository can only be done by a maintainer.
13-
1. Build the and publish the image by using `make push-multiarch-build-image`. This will build and push multi-platform docker image (for linux/amd64 and linux/arm64). Running this step successfully requires [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/), but does not require a specific platform.
14-
1. Replace the image tag in `.github/workflows/*` (_there may be multiple references_) and Makefile (variable `LATEST_BUILD_IMAGE_TAG`).
11+
1. Create a PR to master with that changed, after the PR is merged to master, the new build image is available in the quay.io repository. Check github action logs [here](https://github.com/cortexproject/cortex/actions/workflows/build-image.yml) for to find the image tag.
12+
1. Create another PR to replace the image tag in `.github/workflows/*` (_there may be multiple references_) and Makefile (variable `LATEST_BUILD_IMAGE_TAG`).
1513
1. If you are updating Go's runtime version be sure to change `actions/setup-go`'s `go-version` in ``.github/workflows/*`.
1614
1. Open a PR and make sure the CI with new build-image passes

0 commit comments

Comments
 (0)