Skip to content

Commit cba8e36

Browse files
committed
ZSWatch: Optimize to keep container small to work with Github hosted runners.
Create a zswatch-ci Docker image that is optimized for CI usage on Github hosted runners. Based on the same base image as the zephyr ci-base image, but with only the necessary toolchains and dependencies installed to keep the image size small.
1 parent 0917f3b commit cba8e36

File tree

4 files changed

+130
-11
lines changed

4 files changed

+130
-11
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
name: CI
1+
name: Upstream CI (disabled in fork)
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- v*-branch
8-
tags:
9-
- v*
10-
pull_request:
11-
branches:
12-
- main
13-
- v*-branch
4+
# Disabled in this fork to avoid relying on Zephyr's
5+
# self-hosted runners and DockerHub credentials.
6+
# Kept only for reference and manual runs.
7+
workflow_dispatch:
148

159
permissions:
1610
packages: write
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and publish ZSWatch CI image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- zswatch_*
8+
paths:
9+
- Dockerfile.base
10+
- Dockerfile.ci
11+
- .github/workflows/zswatch-ci-image.yml
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
jobs:
19+
build-and-push-ci:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Log in to GitHub Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Build and push base image
37+
uses: docker/build-push-action@v5
38+
with:
39+
context: .
40+
file: ./Dockerfile.base
41+
push: true
42+
tags: |
43+
ghcr.io/zswatch/ci-base:${{ github.ref_name }}
44+
ghcr.io/zswatch/ci-base:latest
45+
46+
- name: Build and push CI image
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
file: ./Dockerfile.zswatch-ci
51+
push: true
52+
tags: |
53+
ghcr.io/zswatch/zswatch-ci:latest
54+
ghcr.io/zswatch/zswatch-ci:${{ github.ref_name }}
55+
build-args: |
56+
BASE_IMAGE=ghcr.io/zswatch/ci-base:${{ github.ref_name }}

Dockerfile.zswatch-ci

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ZSWatch CI Image
2+
# Based on ci-base, with only the extra bits needed for ZSWatch builds.
3+
4+
ARG BASE_IMAGE
5+
FROM ${BASE_IMAGE:-ghcr.io/zswatch/ci-base:latest}
6+
7+
ARG USERNAME=user
8+
ARG WGET_ARGS="-q --show-progress --progress=bar:force:noscroll"
9+
ARG UBUNTU_MIRROR_ARCHIVE=archive.ubuntu.com/ubuntu
10+
ARG UBUNTU_MIRROR_SECURITY=security.ubuntu.com/ubuntu
11+
ARG UBUNTU_MIRROR_PORTS=ports.ubuntu.com/ubuntu-ports
12+
13+
ARG ZSDK_VERSION=0.17.4
14+
ENV ZSDK_VERSION=$ZSDK_VERSION
15+
16+
# Install minimal extra APT packages required for ZSWatch CI
17+
RUN <<EOF
18+
apt-get update -y
19+
apt-get install --no-install-recommends -y \
20+
clang-format
21+
22+
# Clean up local repository
23+
apt-get clean -y
24+
rm -rf /var/lib/apt/lists/*
25+
EOF
26+
27+
# Install Zephyr SDK
28+
RUN <<EOF
29+
mkdir -p /opt/toolchains
30+
cd /opt/toolchains
31+
wget ${WGET_ARGS} https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZSDK_VERSION}/zephyr-sdk-${ZSDK_VERSION}_linux-${HOSTTYPE}.tar.xz
32+
tar xf zephyr-sdk-${ZSDK_VERSION}_linux-${HOSTTYPE}.tar.xz
33+
zephyr-sdk-${ZSDK_VERSION}/setup.sh -t all -h -c
34+
rm zephyr-sdk-${ZSDK_VERSION}_linux-${HOSTTYPE}.tar.xz
35+
EOF
36+
37+
# Run the Zephyr SDK setup script as 'user' in order to ensure that the
38+
# `Zephyr-sdk` CMake package is located in the package registry under the
39+
# user's home directory.
40+
USER $USERNAME
41+
42+
RUN <<EOF
43+
sudo -E -- bash -c '
44+
/opt/toolchains/zephyr-sdk-${ZSDK_VERSION}/setup.sh -c &&
45+
chown -R $USERNAME:$USERNAME /home/$USERNAME/.cmake
46+
'
47+
EOF
48+
49+
USER root
50+
51+
# Set build environment variables
52+
ENV ZEPHYR_TOOLCHAIN_VARIANT=zephyr
53+
ENV PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig
54+
ENV OVMF_FD_PATH=/usr/share/ovmf/OVMF.fd

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ This repository contains the Dockerfiles for the following images:
77
- **Developer Image (_zephyr-build_):** includes additional tools that can be useful for Zephyr
88
development.
99

10+
## ZSWatch CI usage
11+
12+
For the ZSWatch project, a trimmed CI image is built from `Dockerfile.zswatch-ci` and published to GitHub Container Registry using the workflow `.github/workflows/zswatch-ci-image.yml` in this repository.
13+
14+
- Updating the CI image:
15+
- Edit `Dockerfile.base` and/or `Dockerfile.zswatch-ci`.
16+
- Push to a branch matching `zswatch_*` (or `main`).
17+
- The `Build and publish ZSWatch CI image` workflow builds `ci-base` and `zswatch-ci` and pushes them to `ghcr.io/<namespace>/ci-base:<tag>` and `ghcr.io/<namespace>/zswatch-ci:<tag>`.
18+
- Using the image in ZSWatch:
19+
- In the `ZSWatch` repo, set the job container to the published image, for example:
20+
```yaml
21+
container: ghcr.io/<namespace>/zswatch-ci:<tag>
22+
```
23+
- The `build.yml` workflow in `ZSWatch` can then reuse this image without rebuilding toolchains on every run.
24+
1025
## Developer Docker Image
1126

1227
### Overview

0 commit comments

Comments
 (0)