Skip to content

Commit aed5fcb

Browse files
Making toxic multi-platform (#38)
1 parent 8f0a3a6 commit aed5fcb

File tree

4 files changed

+100
-26
lines changed

4 files changed

+100
-26
lines changed

.github/workflows/toxic.yml

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,51 @@ env:
1414

1515
jobs:
1616

17-
build_and_publish:
17+
dry_run:
18+
if: ${{ github.event_name == 'pull_request' || ( github.event_name == 'release' && startsWith( github.ref, 'refs/tags/tx') && github.event.release.prerelease ) }}
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v3
1823

24+
- # Add QEMU to allow building non-native containers as
25+
# part of multi-platform container builds.
26+
name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- # Setup buildx so we can do multi-platform container builds.
30+
name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: build
34+
run: cd ${{ env.IMAGE_NAME }} && docker buildx build --platform linux/arm64,linux/amd64 .
35+
36+
release:
37+
if: ${{ github.event_name == 'release' && startsWith( github.ref, 'refs/tags/tx' ) && !github.event.release.prerelease }}
1938
runs-on: ubuntu-latest
2039

2140
steps:
2241
- uses: actions/checkout@v3
2342

24-
- name: process event
25-
id: process_event
26-
uses: olegtarasov/[email protected]
43+
- # Add QEMU to allow building non-native containers as
44+
# part of multi-platform container builds.
45+
name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
48+
- # Setup buildx so we can do multi-platform container builds.
49+
name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
52+
- name: Login to GHCR
53+
uses: docker/login-action@v2
2754
with:
28-
tagRegex: "(${{ env.IMAGE_VERSION_PREFIX }}).*"
29-
- name: dryrun-build
30-
if: ${{ github.event_name == 'pull_request' || ( github.event_name == 'release' && startsWith( steps.process_event.outputs.tag, env.IMAGE_VERSION_PREFIX ) && github.event.release.prerelease ) }}
31-
run: docker build ./${{ env.IMAGE_NAME }}
55+
registry: ghcr.io
56+
username: ${{ github.repository_owner }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: form image tag
60+
id: image_tag
61+
uses: olegtarasov/[email protected]
62+
3263
- name: build-and-push
33-
if: ${{ github.event_name == 'release' && startsWith( steps.process_event.outputs.tag, env.IMAGE_VERSION_PREFIX ) && !github.event.release.prerelease }}
34-
uses: macbre/push-to-ghcr@master
35-
with:
36-
context: ./${{ env.IMAGE_NAME }}
37-
dockerfile: ./${{ env.IMAGE_NAME }}/Dockerfile
38-
image_name: ${{ env.ORG_NAMESPACE }}/${{ env.IMAGE_NAME }}
39-
github_token: ${{ secrets.GITHUB_TOKEN }}
40-
repository: ghcr.io
64+
run: cd ${{ env.IMAGE_NAME }} && docker buildx build --platform linux/arm64,linux/amd64 --push -t ghcr.io/${{ env.ORG_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ steps.image_tag.outputs.tag }} .

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ is based on Ubuntu and provides all modern Python3 distributions, pip, tox, and
7979
| tag | Base Python | Python Versions | Tox | Nox | pip | Platforms | Other Utilities |
8080
|----------|-------------|-----------------|-----|-----|-----|-----------|-----------------|
8181
| [tx20.4.1](https://github.com/OpenCyphal/docker_toolchains/pkgs/container/toxic) | 3.8 | 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 | 4.4.5 | (not available) | 20.0.2 | <ul><li>linux/amd64</li></ul> | <ul><li>sonar-scanner</li></ul> |
82-
| [tx22.4.1](https://github.com/OpenCyphal/docker_toolchains/pkgs/container/toxic) | 3.8 | 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 | 4.4.5 | (not available) | 20.0.2 | <ul><li>linux/amd64</li></ul> | |
82+
| [tx22.4.1](https://github.com/OpenCyphal/docker_toolchains/pkgs/container/toxic) | 3.8 | 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 | 4.4.5 | 2023.4.22 | 20.0.2 | <ul><li>linux/amd64</li></ul> | |
83+
| [tx22.4.2](https://github.com/OpenCyphal/docker_toolchains/pkgs/container/toxic) | 3.10 | 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 | 4.13.0 | 2023.4.22 | 20.0.2 | <ul><li>linux/amd64</li><li>linux/arm64</li></ul> | |
8384

8485
You can use this in your workflow yaml like this:
8586

toolshed/llvm-install.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ usage() {
2020
exit 1;
2121
}
2222

23-
CURRENT_LLVM_STABLE=17
23+
CURRENT_LLVM_STABLE=18
2424
BASE_URL="http://apt.llvm.org"
2525

2626
# Check for required tools
@@ -126,7 +126,8 @@ LLVM_VERSION_PATTERNS[14]="-14"
126126
LLVM_VERSION_PATTERNS[15]="-15"
127127
LLVM_VERSION_PATTERNS[16]="-16"
128128
LLVM_VERSION_PATTERNS[17]="-17"
129-
LLVM_VERSION_PATTERNS[18]=""
129+
LLVM_VERSION_PATTERNS[18]="-18"
130+
LLVM_VERSION_PATTERNS[19]=""
130131

131132
if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then
132133
echo "This script does not support LLVM version $LLVM_VERSION"
@@ -173,4 +174,4 @@ if [[ $ALL -eq 1 ]]; then
173174
PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev"
174175
fi
175176
fi
176-
apt-get install -y $PKG
177+
apt-get install -y $PKG

toxic/README.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,70 @@ export FGP = (fine-grained permission for OpenCyphal organization)
2929
echo $FGP | docker login ghcr.io -u (github username) --password-stdin
3030
```
3131

32-
... now build (where x is the next version number for the container):
32+
... build a multi-platform image following the instructions [here](https://docs.docker.com/build/building/multi-platform/#multiple-native-nodes):
3333

3434
```bash
35-
docker build -t ghcr.io/opencyphal/toxic:tx22.4.x .
35+
docker buildx create --use --name cyphalbuild
3636
```
3737

38-
... and finally, push.
38+
If you already created the `cyphalbuild` builder then just use it instead of creating it:
3939

4040
```bash
41-
docker push ghcr.io/opencyphal/toxic:tx22.4.x
41+
docker buildx use cyphalbuild
4242
```
4343

44-
## Testing out the container
44+
... then build the container:
4545

46-
To login to an interactive session do:
46+
```bash
47+
docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/opencyphal/toxic:tx22.4.x .
48+
```
49+
50+
(where x is the next version number for the container)
51+
52+
53+
When the build completes you'll see the following warning:
54+
55+
> WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
56+
57+
It's important you don't restart your docker build container before you load and/or push since it may blow away the cache you need to push or load from.
58+
59+
### Load
60+
Currently you can't use --load with docker desktop so the only way to test the container is to rebuild for one platform only:
61+
62+
```bash
63+
docker buildx build --platform linux/arm64 --load -t ghcr.io/opencyphal/toxic:tx22.4.x .
64+
```
65+
66+
This will be operating off of the cache so it shouldn't take very long to complete. After it does you'll see your image using the classic `docker images` command. Now you can login to the container to test it out:
4767

4868
```bash
4969
docker run --rm -it -v ${PWD}:/repo ghcr.io/opencyphal/toxic:tx22.4.x
70+
```
71+
72+
### Push
73+
74+
As with load, you need to re-build with a `--push` argument but you'll be using the cache so the build should be a no-op:
75+
76+
```bash
77+
docker buildx build --platform linux/amd64,linux/arm64 --push -t ghcr.io/opencyphal/toxic:tx22.4.x .
78+
```
79+
80+
## More on Multi-Platform Builders
81+
82+
The two commands above make some assumptions about defaults and capabilities that we haven't verified on all build hosts. First, the `buildx create` command is assumed to target the correct Docker context. You can see your contexts by doing:
83+
84+
```
85+
docker context ls
86+
```
87+
88+
... then target a specific context by adding it as an additional argument to the builder create command:
89+
90+
```
91+
docker buildx create --use --name cyphalbuild desktop-linux
92+
```
93+
94+
We also assume you are using a build that has our two supported host platforms `linux/amd64` and `linux/arm64`. You can verify this after creating the builder using the inspect command. This should also verify that your builder is now in effect:
95+
96+
```
97+
docker buildx inspect --bootstrap
5098
```

0 commit comments

Comments
 (0)