Skip to content

Commit 1ccf69f

Browse files
author
Akash Satheesan
authored
chore: cross-compile docker images with buildx (#3503)
1 parent 8e92dd6 commit 1ccf69f

File tree

6 files changed

+39
-43
lines changed

6 files changed

+39
-43
lines changed

.github/workflows/ci.yaml

+10-26
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ jobs:
386386
- name: Remove release packages and test artifacts
387387
run: rm -rf ./release-packages ./test/test-results
388388

389-
docker-amd64:
389+
# Builds both amd64 and arm64 images
390+
docker-images:
390391
runs-on: ubuntu-latest
391-
needs: package-linux-amd64
392+
needs: [package-linux-amd64, package-linux-arm64]
392393
steps:
393394
- uses: actions/checkout@v2
394395

@@ -398,42 +399,24 @@ jobs:
398399
name: release-packages
399400
path: ./release-packages
400401

401-
- name: Run ./ci/steps/build-docker-image.sh
402-
run: ./ci/steps/build-docker-image.sh
402+
- name: Set up QEMU
403+
uses: docker/setup-qemu-action@v1
403404

404-
- name: Upload release image
405-
uses: actions/upload-artifact@v2
406-
with:
407-
name: release-images
408-
path: ./release-images
409-
410-
# TODO: this is the last place where we use our self-hosted arm64 runner.
411-
# In the future, consider switching to docker buildx + qemu,
412-
# thus removing the requirement for us to maintain the runner.
413-
docker-arm64:
414-
runs-on: ubuntu-arm64-latest
415-
needs: package-linux-arm64
416-
steps:
417-
- uses: actions/checkout@v2
418-
419-
- name: Download release package
420-
uses: actions/download-artifact@v2
421-
with:
422-
name: release-packages
423-
path: ./release-packages
405+
- name: Set up Docker Buildx
406+
uses: docker/setup-buildx-action@v1
424407

425408
- name: Run ./ci/steps/build-docker-image.sh
426409
run: ./ci/steps/build-docker-image.sh
427410

428-
- name: Upload release image
411+
- name: Upload release images
429412
uses: actions/upload-artifact@v2
430413
with:
431414
name: release-images
432415
path: ./release-images
433416

434417
trivy-scan-image:
435418
runs-on: ubuntu-20.04
436-
needs: docker-amd64
419+
needs: docker-images
437420
# NOTE@jsjoeio: disabling due to a memory issue upstream
438421
# See: https://github.com/github/codeql-action/issues/528
439422
if: 1 == 2
@@ -466,6 +449,7 @@ jobs:
466449
uses: github/codeql-action/upload-sarif@v1
467450
with:
468451
sarif_file: "trivy-image-results.sarif"
452+
469453
# We have to use two trivy jobs
470454
# because GitHub only allows
471455
# codeql/upload-sarif action per job

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ VS Code v0.00.0
5454

5555
### Development
5656

57-
- item
57+
- chore: cross-compile docker images with buildx #3166 @oxy
5858

5959
## 3.10.2
6060

ci/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ You can disable minification by setting `MINIFY=`.
100100

101101
This directory contains the release docker container image.
102102

103-
- [./release-image/build.sh](./release-image/build.sh)
104-
- Builds the release container with the tag `codercom/code-server-$ARCH:$VERSION`.
103+
- [./ci/steps/build-docker-image.sh](./ci/steps/build-docker-image.sh)
104+
- Builds the release containers with tags `codercom/code-server-$ARCH:$VERSION` for amd64 and arm64 with `docker buildx`.
105105
- Assumes debian releases are ready in `./release-packages`.
106106

107107
## images

ci/release-image/build.sh

-11
This file was deleted.

ci/release-image/docker-bake.hcl

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this file from the top of the repo, with `-f ci/release-image/docker-bake.hcl`
2+
3+
# Uses env var VERSION if set;
4+
# normally, this is set by ci/lib.sh
5+
variable "VERSION" {
6+
default = "latest"
7+
}
8+
9+
group "default" {
10+
targets = ["code-server-amd64", "code-server-arm64"]
11+
}
12+
13+
target "code-server-amd64" {
14+
dockerfile = "ci/release-image/Dockerfile"
15+
tags = ["docker.io/codercom/code-server-amd64:${VERSION}"]
16+
platforms = ["linux/amd64"]
17+
output = ["type=tar,dest=./release-images/code-server-amd64-${VERSION}.tar"]
18+
}
19+
20+
target "code-server-arm64" {
21+
dockerfile = "ci/release-image/Dockerfile"
22+
tags = ["docker.io/codercom/code-server-arm64:${VERSION}"]
23+
platforms = ["linux/arm64"]
24+
output = ["type=tar,dest=./release-images/code-server-arm64-${VERSION}.tar"]
25+
}

ci/steps/build-docker-image.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ main() {
55
cd "$(dirname "$0")/../.."
66
source ./ci/lib.sh
77

8-
./ci/release-image/build.sh
9-
108
mkdir -p release-images
11-
docker save "codercom/code-server-$ARCH:$VERSION" >"release-images/code-server-$ARCH-$VERSION.tar"
9+
docker buildx bake -f ci/release-image/docker-bake.hcl
1210
}
1311

1412
main "$@"

0 commit comments

Comments
 (0)