Skip to content

Commit 271b1da

Browse files
authored
Merge pull request #1307 from hoyes/docker-arm64
Publish arm64 Docker images
2 parents 451cc12 + 58fdba6 commit 271b1da

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed

.github/workflows/docker.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on:
55
branches: [ master ]
66
tags:
77
- '*'
8+
release:
9+
types: [ released ]
10+
workflow_dispatch:
11+
12+
env:
13+
QEMU_PLATFORMS: arm64
14+
IMAGE_PLATFORMS: linux/amd64,linux/arm64
15+
IMAGE_PREFIX: ${{ secrets.DOCKERHUB_PREFIX }}
816

917
jobs:
1018
docker:
@@ -16,32 +24,27 @@ jobs:
1624
sudo apt install -yq python3-pip
1725
pip install --upgrade setuptools
1826
pip install setuptools_scm
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
with:
30+
platforms: ${QEMU_PLATFORMS}
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
1933
- name: Login to DockerHub
2034
uses: docker/login-action@v3
2135
with:
2236
username: ${{ secrets.DOCKERHUB_USERNAME }}
2337
password: ${{ secrets.DOCKERHUB_TOKEN }}
24-
- name: Build docker image
38+
- name: Build amd64 docker image and validate
2539
run: |
26-
./dockerfiles/build.sh
40+
./dockerfiles/build.sh --load
2741
docker-compose -f dockerfiles/staging/docker-compose.yml up --exit-code-from client client
2842
docker-compose -f dockerfiles/staging/docker-compose.yml down
2943
docker images
30-
- name: Tag latest images
31-
run: |
32-
docker tag labgrid-client ${{ secrets.DOCKERHUB_PREFIX }}client
33-
docker tag labgrid-exporter ${{ secrets.DOCKERHUB_PREFIX }}exporter
34-
docker tag labgrid-coordinator ${{ secrets.DOCKERHUB_PREFIX }}coordinator
35-
- name: Tag release image
44+
- name: Build, tag and push latest image for all platforms
45+
run: ./dockerfiles/build.sh --platform ${IMAGE_PLATFORMS} --push
46+
- name: Tag and push release image for all platforms
3647
if: startsWith(github.ref, 'refs/tags')
37-
run: |
38-
docker tag labgrid-client ${{ secrets.DOCKERHUB_PREFIX }}client:${GITHUB_REF_NAME}
39-
docker tag labgrid-exporter ${{ secrets.DOCKERHUB_PREFIX }}exporter:${GITHUB_REF_NAME}
40-
docker tag labgrid-coordinator ${{ secrets.DOCKERHUB_PREFIX }}coordinator:${GITHUB_REF_NAME}
41-
- name: Push to dockerhub
42-
run: |
43-
docker push --all-tags ${{ secrets.DOCKERHUB_PREFIX }}client
44-
docker push --all-tags ${{ secrets.DOCKERHUB_PREFIX }}exporter
45-
docker push --all-tags ${{ secrets.DOCKERHUB_PREFIX }}coordinator
46-
- name: Show images again
47-
run: docker images
48+
env:
49+
IMAGE_TAG: ${{ github.ref_name }}
50+
run: ./dockerfiles/build.sh --platform ${IMAGE_PLATFORMS} --push

dockerfiles/README.rst

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ Example showing how to build labgrid-client image:
2222

2323
.. code-block:: bash
2424
25-
$ docker build --target labgrid-client -t labgrid-client -f dockerfiles/Dockerfile .
25+
$ docker build --target labgrid-client -t docker.io/labgrid/client -f dockerfiles/Dockerfile .
2626
2727
Using `BuildKit <https://docs.docker.com/develop/develop-images/build_enhancements/>`_
2828
is recommended to reduce build times.
2929

30-
You can also choose to build all 3 images,
31-
with the included script.
30+
You can also choose to build all 3 images with the included script. The script
31+
will automatically use `docker buildx
32+
<https://docs.docker.com/engine/reference/commandline/buildx/>`` if available.
3233

3334
.. code-block:: bash
3435
@@ -43,15 +44,13 @@ The script supports ``podman`` as well.
4344
$ ./dockerfiles/build.sh
4445
4546
It builds for the native platform by default. However, building
46-
for foreign platforms is also supported using `docker buildx
47-
<https://docs.docker.com/build/building/multi-platform/>` or `podman
48-
buildx <https://docs.podman.io/en/latest/markdown/podman-build.1.html>`
49-
by passing the platform of choice, e.g. `linux/arm64`.
47+
for foreign platforms is also supported by passing the platform(s) of choice,
48+
e.g. `linux/arm64` as an additional argument.
5049

5150
.. code-block:: bash
5251
5352
$ pip install --upgrade setuptools_scm
54-
$ ./dockerfiles/build.sh linux/arm64
53+
$ ./dockerfiles/build.sh --platform linux/arm64
5554
5655
5756
Usage
@@ -77,7 +76,7 @@ so you can restart the service without loosing state.
7776
.. code-block:: bash
7877
7978
$ docker run -t -p 20408:20408 -v $HOME/crossbar:/opt/crossbar \
80-
labgrid-coordinator
79+
docker.io/labgrid/coordinator
8180
8281
8382
labgrid-client usage
@@ -90,14 +89,14 @@ ws://192.168.1.42:20408/ws
9089

9190
.. code-block:: bash
9291
93-
$ docker run -e LG_CROSSBAR=ws://192.168.1.42:20408/ws labgrid-client \
92+
$ docker run -e LG_CROSSBAR=ws://192.168.1.42:20408/ws docker.io/labgrid/client \
9493
labgrid-client places
9594
9695
Or running all pytest/labgrid tests at current directory:
9796

9897
.. code-block:: bash
9998
100-
$ docker run -e LG_CROSSBAR=ws://192.168.1.42:20408/ws labgrid-client \
99+
$ docker run -e LG_CROSSBAR=ws://192.168.1.42:20408/ws docker.io/labgrid/client \
101100
pytest
102101
103102
@@ -116,7 +115,7 @@ Start it with something like:
116115
117116
$ docker run -e LG_CROSSBAR=ws://192.168.1.42:20408/ws \
118117
-v $HOME/exporter-conf:/opt/conf \
119-
labgrid-exporter
118+
docker.io/labgrid/exporter
120119
121120
If using ser2net or if "exporting" e.g. a serial device, the devices needed must be added to Docker container
122121
(``docker run --device`` option).
@@ -136,14 +135,8 @@ create a setup with the following instances
136135
The environment serves both to allow checking if the environment still function after changes, and can act as an example
137136
how to configure the docker images needed to run a minimal setup.
138137

139-
To use the staging environment to conduct a smoke test first build the images as instructed below:
140-
141-
.. code-block:: bash
142-
143-
$ pip install --upgrade setuptools_scm
144-
$ ./dockerfiles/build.sh
145-
146-
Then use docker compose to start all services except the client:
138+
To use the staging environment to conduct a smoke test, first run docker compose to start all services except the
139+
client:
147140

148141
.. code-block:: bash
149142

dockerfiles/build.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22

33
export DOCKER_BUILDKIT=1
4+
: "${IMAGE_PREFIX:=docker.io/labgrid/}"
5+
: "${IMAGE_TAG:=latest}"
46

57
die () {
68
local msg
@@ -53,12 +55,14 @@ perform_regular_build() {
5355
docker_cmd="${1}"
5456
script_dir="${2}"
5557
version="${3}"
58+
extra_args=("${@:4}")
5659

5760
log_info "building for native platform only."
5861

5962
for t in client exporter coordinator; do
6063
"${docker_cmd}" build --build-arg VERSION="${version}" \
61-
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" .
64+
--target labgrid-${t} -t "${IMAGE_PREFIX}${t}:${IMAGE_TAG}" -f "${script_dir}/Dockerfile" \
65+
"${extra_args[@]}" .
6266
done
6367
}
6468

@@ -67,16 +71,17 @@ perform_docker_buildx_build() {
6771
docker_cmd="${1}"
6872
script_dir="${2}"
6973
version="${3}"
74+
extra_args=("${@:4}")
7075

7176
for t in client exporter coordinator; do
72-
"${docker_cmd}" buildx build --platform "${platform}" --build-arg VERSION="${version}" \
73-
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" .
77+
"${docker_cmd}" buildx build --build-arg VERSION="${version}" \
78+
--target labgrid-${t} -t "${IMAGE_PREFIX}${t}:${IMAGE_TAG}" -f "${script_dir}/Dockerfile" \
79+
"${extra_args[@]}" .
7480
done
7581
}
7682

7783
main() {
78-
local platform script_dir version
79-
platform="${1}"
84+
local script_dir version
8085

8186
if ! has_docker && ! has_podman; then
8287
die "Neither docker nor podman could be found."
@@ -88,11 +93,11 @@ main() {
8893

8994
cd "${script_dir}/.." || die "Could not cd into repo root dir"
9095

91-
if has_buildx "${docker_cmd}" && [ -n "${platform}" ]; then
92-
perform_docker_buildx_build "${docker_cmd}" "${script_dir}" "${version}" "${platform}"
96+
if has_buildx "${docker_cmd}"; then
97+
perform_docker_buildx_build "${docker_cmd}" "${script_dir}" "${version}" "${@}"
9398
else
94-
perform_regular_build "${docker_cmd}" "${script_dir}" "${version}"
99+
perform_regular_build "${docker_cmd}" "${script_dir}" "${version}" "${@}"
95100
fi
96101
}
97102

98-
main "${1}"
103+
main "${@}"

dockerfiles/staging/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
version: '3.3'
22
services:
33
coordinator:
4-
image: "labgrid-coordinator"
4+
image: "${IMAGE_PREFIX:-docker.io/labgrid/}coordinator"
55
volumes:
66
- "./crossbar:/home/root/crossbar"
77
tty: true
88
network_mode: "host"
99
command: bash -c "cp /home/root/crossbar/places_example.yaml /opt/crossbar/places.yaml &&
1010
/opt/labgrid/crossbar-venv/bin/crossbar start --config /opt/labgrid/.crossbar/config-anonymous.yaml"
1111
client:
12-
image: "labgrid-client"
12+
image: "${IMAGE_PREFIX:-docker.io/labgrid/}client"
1313
volumes:
1414
- "./client/simple-test:/simple-test"
1515
- "./client/.ssh:/root/.ssh"
@@ -33,7 +33,7 @@ services:
3333
- exporter
3434
- dut
3535
exporter:
36-
image: "labgrid-exporter"
36+
image: "${IMAGE_PREFIX:-docker.io/labgrid/}exporter"
3737
volumes:
3838
- "./exporter-conf:/opt/conf"
3939
- "/run/udev:/run/udev:ro"

0 commit comments

Comments
 (0)