Skip to content

Commit 8f96d66

Browse files
Optimize CI by using a custom Docker container with pre-installed dependencies.
This change introduces a Docker container (`.ci/container/Dockerfile`) that pre-installs: - OpenJDK 8 (ZuluFX), 11, 17, 21, and 25 (Zulu). - Ant, Maven, Python 3. - Codename One binaries (`cn1-binaries`). - Required libraries for headless UI testing (xvfb, libgl1-mesa-dri). Updates `pr.yml`, `ant.yml`, and `scripts-android.yml` to run jobs inside this container, removing redundant setup steps (JDK download, tool installation) to improve build speed and reproducibility. Also updates `scripts/setup-workspace.sh` to respect the `CN1_BINARIES` environment variable and handle the pre-configured environment correctly.
1 parent 2a517c4 commit 8f96d66

File tree

6 files changed

+160
-61
lines changed

6 files changed

+160
-61
lines changed

.ci/container/Dockerfile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
FROM ubuntu:24.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
# Install basics and tools
6+
RUN apt-get update && apt-get install -y \
7+
curl \
8+
wget \
9+
gnupg \
10+
ca-certificates \
11+
git \
12+
unzip \
13+
zip \
14+
python3 \
15+
python3-pip \
16+
xvfb \
17+
libgl1-mesa-dri \
18+
libxtst6 \
19+
libxxf86vm1 \
20+
ant \
21+
maven \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
# Setup Azul Repo
25+
RUN curl -s https://repos.azul.com/azul-repo.key | gpg --dearmor -o /usr/share/keyrings/azul.gpg \
26+
&& echo "deb [signed-by=/usr/share/keyrings/azul.gpg] https://repos.azul.com/zulu/deb stable main" | tee /etc/apt/sources.list.d/zulu.list
27+
28+
# Install JDKs 11, 17, 21, 25
29+
RUN apt-get update && apt-get install -y \
30+
zulu11-jdk \
31+
zulu17-jdk \
32+
zulu21-jdk \
33+
zulu25-jdk \
34+
&& rm -rf /var/lib/apt/lists/*
35+
36+
# Install ZuluFX 8 (Tarball)
37+
# URL for Zulu 8 + FX (x64 Linux)
38+
# Using a fixed version to ensure reproducibility.
39+
RUN mkdir -p /usr/lib/jvm/zulu8-fx && \
40+
curl -L "https://cdn.azul.com/zulu/bin/zulu8.82.0.21-ca-fx-jdk8.0.432-linux_x64.tar.gz" -o /tmp/zulu8.tar.gz && \
41+
tar -xzf /tmp/zulu8.tar.gz -C /usr/lib/jvm/zulu8-fx --strip-components=1 && \
42+
rm /tmp/zulu8.tar.gz
43+
44+
# Clone cn1-binaries
45+
RUN git clone --depth=1 https://github.com/codenameone/cn1-binaries /opt/cn1-binaries
46+
47+
# Set Environment Variables
48+
ENV JAVA_HOME=/usr/lib/jvm/zulu8-fx
49+
ENV PATH=$JAVA_HOME/bin:$PATH
50+
51+
ENV JAVA8_HOME=/usr/lib/jvm/zulu8-fx
52+
ENV JDK8_HOME=/usr/lib/jvm/zulu8-fx
53+
54+
# Paths for apt installed JDKs (usually symlinked to /usr/lib/jvm/zulu-XX-amd64)
55+
ENV JAVA11_HOME=/usr/lib/jvm/zulu-11-amd64
56+
ENV JDK11_HOME=/usr/lib/jvm/zulu-11-amd64
57+
ENV JAVA17_HOME=/usr/lib/jvm/zulu-17-amd64
58+
ENV JDK17_HOME=/usr/lib/jvm/zulu-17-amd64
59+
ENV JAVA21_HOME=/usr/lib/jvm/zulu-21-amd64
60+
ENV JDK21_HOME=/usr/lib/jvm/zulu-21-amd64
61+
ENV JAVA25_HOME=/usr/lib/jvm/zulu-25-amd64
62+
ENV JDK25_HOME=/usr/lib/jvm/zulu-25-amd64
63+
64+
ENV CN1_BINARIES=/opt/cn1-binaries
65+
66+
# Verify installations
67+
RUN java -version && \
68+
$JAVA11_HOME/bin/java -version && \
69+
$JAVA17_HOME/bin/java -version && \
70+
$JAVA21_HOME/bin/java -version && \
71+
$JAVA25_HOME/bin/java -version && \
72+
ant -version && \
73+
mvn -version && \
74+
python3 --version

.github/workflows/ant.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ jobs:
1111
build-linux-jdk8:
1212

1313
runs-on: ubuntu-latest
14+
container:
15+
image: ghcr.io/${{ github.repository }}/ci-container:latest
1416

1517
steps:
1618
- uses: actions/checkout@v1
17-
- name: Set up JDK 8
18-
uses: actions/setup-java@v1
19-
with:
20-
java-version: 1.8
21-
java-package: jdk
22-
- name: Install dependencies
23-
run: sudo apt-get update && sudo apt-get install xvfb
2419
- name: Build with Maven
2520
run: |
2621
cd maven
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build CI Container
2+
3+
on:
4+
push:
5+
paths:
6+
- '.ci/container/**'
7+
- '.github/workflows/build-container.yml'
8+
workflow_dispatch:
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}/ci-container
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Log in to the Container registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ${{ env.REGISTRY }}
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Build and push Docker image
33+
uses: docker/build-push-action@v5
34+
with:
35+
context: .ci/container
36+
push: true
37+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

.github/workflows/pr.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ jobs:
3737
build-linux-jdk8-fx:
3838

3939
runs-on: ubuntu-latest
40+
container:
41+
image: ghcr.io/${{ github.repository }}/ci-container:latest
4042

4143
steps:
4244
- uses: actions/checkout@v1
43-
- name: Set up JDK 8
44-
uses: actions/setup-java@v1
45-
with:
46-
java-version: 1.8
47-
java-package: jdk+fx
4845
- name: Cache Maven dependencies
4946
uses: actions/cache@v4
5047
with:
@@ -57,15 +54,10 @@ jobs:
5754
cd maven
5855
mvn clean verify -DunitTests=true -pl core-unittests -am -Dmaven.javadoc.skip=true -Plocal-dev-javase
5956
cd ..
60-
- name: Prepare Codename One binaries for Maven plugin tests
61-
run: |
62-
set -euo pipefail
63-
rm -rf maven/target/cn1-binaries
64-
git clone --depth=1 --filter=blob:none https://github.com/codenameone/cn1-binaries maven/target/cn1-binaries
6557
- name: Run Maven plugin tests
6658
working-directory: maven
6759
env:
68-
CN1_BINARIES: ${{ github.workspace }}/maven/target/cn1-binaries
60+
CN1_BINARIES: /opt/cn1-binaries
6961
run: |
7062
mvn -B -Dmaven.javadoc.skip=true \
7163
-DunitTests=true \
@@ -211,12 +203,6 @@ jobs:
211203
script: |
212204
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
213205
await publishQualityComment({ github, context, core });
214-
- name: Install dependencies
215-
run: |
216-
sudo apt-get update && sudo apt-get install xvfb
217-
wget https://github.com/codenameone/cn1-binaries/archive/refs/heads/master.zip
218-
unzip master.zip -d ..
219-
mv ../cn1-binaries-master ../cn1-binaries
220206
- name: Build with Ant
221207
run: xvfb-run ant test-javase
222208
- name: Build CLDC11 JAR

.github/workflows/scripts-android.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ jobs:
9090
pull-requests: write
9191
issues: write
9292
runs-on: ubuntu-latest
93+
container:
94+
image: ghcr.io/${{ github.repository }}/ci-container:latest
95+
options: --privileged -v /dev/kvm:/dev/kvm
9396
env:
9497
GITHUB_TOKEN: ${{ secrets.CN1SS_GH_TOKEN }}
9598
GH_TOKEN: ${{ secrets.CN1SS_GH_TOKEN }}
@@ -98,19 +101,13 @@ jobs:
98101
- name: Free Disk Space
99102
if: matrix.id != 'default'
100103
run: |
101-
sudo rm -rf /usr/share/dotnet
102-
sudo rm -rf /usr/local/lib/android/sdk/ndk
103-
sudo rm -rf /opt/ghc
104-
sudo rm -rf /usr/share/swift
105-
- name: Setup JDK
106-
if: matrix.id != 'default'
107-
uses: actions/setup-java@v4
108-
with:
109-
java-version: ${{ matrix.java_version }}
110-
distribution: 'zulu'
104+
rm -rf /usr/share/dotnet
105+
rm -rf /usr/local/lib/android/sdk/ndk
106+
rm -rf /opt/ghc
107+
rm -rf /usr/share/swift
111108
- name: Set JDK_HOME
112109
if: matrix.id != 'default'
113-
run: echo "JDK_HOME=${JAVA_HOME}" >> $GITHUB_ENV
110+
run: echo "JDK_HOME=/usr/lib/jvm/zulu-${{ matrix.java_version }}-amd64" >> $GITHUB_ENV
114111
- name: Configure CN1SS options
115112
if: matrix.id != 'default'
116113
run: |

scripts/setup-workspace.sh

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ ENV_DIR="$DOWNLOAD_DIR/tools"
2222
mkdir -p "$DOWNLOAD_DIR"
2323
mkdir -p "$ENV_DIR"
2424
CN1_BINARIES_PARENT="$(cd .. && pwd -P)"
25-
CN1_BINARIES="${CN1_BINARIES_PARENT%/}/cn1-binaries"
26-
mkdir -p "$CN1_BINARIES_PARENT"
25+
CN1_BINARIES="${CN1_BINARIES:-${CN1_BINARIES_PARENT%/}/cn1-binaries}"
26+
if [[ "$CN1_BINARIES" != /* ]]; then
27+
CN1_BINARIES="$(cd "${CN1_BINARIES%/*}" && pwd -P)/${CN1_BINARIES##*/}"
28+
fi
29+
mkdir -p "$(dirname "$CN1_BINARIES")"
2730

2831
ENV_FILE="$ENV_DIR/env.sh"
2932

@@ -183,36 +186,43 @@ log "Maven version:"; "$MAVEN_HOME/bin/mvn" -version
183186
PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
184187

185188
log "Preparing cn1-binaries checkout"
186-
if [ -d "$CN1_BINARIES/.git" ]; then
189+
if [ "${CN1_SKIP_BINARIES_UPDATE:-0}" = "1" ]; then
190+
log "Skipping cn1-binaries update as requested"
191+
elif [ -d "$CN1_BINARIES/.git" ]; then
187192
log "Found existing cn1-binaries repository at $CN1_BINARIES"
188193
if git -C "$CN1_BINARIES" remote get-url origin >/dev/null 2>&1; then
189-
if git -C "$CN1_BINARIES" fetch --depth=1 origin; then
190-
remote_head=$(git -C "$CN1_BINARIES" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)
191-
if [ -z "$remote_head" ]; then
192-
current_branch=$(git -C "$CN1_BINARIES" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
193-
if [ -n "$current_branch" ] && [ "$current_branch" != "HEAD" ]; then
194-
remote_head="origin/$current_branch"
195-
else
196-
remote_head="origin/master"
197-
fi
198-
fi
199-
if ! git -C "$CN1_BINARIES" rev-parse --verify "$remote_head" >/dev/null 2>&1; then
200-
if git -C "$CN1_BINARIES" rev-parse --verify origin/main >/dev/null 2>&1; then
201-
remote_head="origin/main"
202-
elif git -C "$CN1_BINARIES" rev-parse --verify origin/master >/dev/null 2>&1; then
203-
remote_head="origin/master"
194+
# Check if directory is writable before attempting update
195+
if [ -w "$CN1_BINARIES" ] && [ -w "$CN1_BINARIES/.git" ]; then
196+
if git -C "$CN1_BINARIES" fetch --depth=1 origin; then
197+
remote_head=$(git -C "$CN1_BINARIES" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)
198+
if [ -z "$remote_head" ]; then
199+
current_branch=$(git -C "$CN1_BINARIES" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
200+
if [ -n "$current_branch" ] && [ "$current_branch" != "HEAD" ]; then
201+
remote_head="origin/$current_branch"
202+
else
203+
remote_head="origin/master"
204+
fi
205+
fi
206+
if ! git -C "$CN1_BINARIES" rev-parse --verify "$remote_head" >/dev/null 2>&1; then
207+
if git -C "$CN1_BINARIES" rev-parse --verify origin/main >/dev/null 2>&1; then
208+
remote_head="origin/main"
209+
elif git -C "$CN1_BINARIES" rev-parse --verify origin/master >/dev/null 2>&1; then
210+
remote_head="origin/master"
211+
else
212+
log "Unable to determine remote head for cached cn1-binaries; removing checkout"
213+
rm -rf "$CN1_BINARIES"
214+
fi
215+
fi
216+
if [ -d "$CN1_BINARIES/.git" ]; then
217+
log "Updating cn1-binaries to $remote_head"
218+
git -C "$CN1_BINARIES" reset --hard "$remote_head"
219+
fi
204220
else
205-
log "Unable to determine remote head for cached cn1-binaries; removing checkout"
221+
log "Failed to fetch updates for cached cn1-binaries; removing checkout"
206222
rm -rf "$CN1_BINARIES"
207223
fi
208-
fi
209-
if [ -d "$CN1_BINARIES/.git" ]; then
210-
log "Updating cn1-binaries to $remote_head"
211-
git -C "$CN1_BINARIES" reset --hard "$remote_head"
212-
fi
213224
else
214-
log "Failed to fetch updates for cached cn1-binaries; removing checkout"
215-
rm -rf "$CN1_BINARIES"
225+
log "cn1-binaries directory is not writable. Skipping update."
216226
fi
217227
else
218228
log "Cached cn1-binaries checkout missing origin remote; removing"

0 commit comments

Comments
 (0)