Skip to content

Commit 6a721aa

Browse files
Optimize PR CI with custom Docker image and pre-installed dependencies
1 parent 79bc59b commit 6a721aa

File tree

3 files changed

+107
-13
lines changed

3 files changed

+107
-13
lines changed

.ci/container/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM ubuntu:24.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
# Install common tools and dependencies
6+
RUN apt-get update && apt-get install -y \
7+
curl \
8+
wget \
9+
unzip \
10+
zip \
11+
git \
12+
python3 \
13+
xvfb \
14+
ant \
15+
maven \
16+
libncurses6 \
17+
sudo \
18+
openjdk-17-jdk \
19+
openjdk-21-jdk \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
# Install Java 8 (Zulu FX)
23+
RUN mkdir -p /usr/lib/jvm
24+
# Using a specific version of Zulu 8 with FX
25+
RUN wget -q https://cdn.azul.com/zulu/bin/zulu8.82.0.21-ca-fx-jdk8.0.432-linux_x64.tar.gz -O /tmp/java8.tar.gz \
26+
&& tar -xzf /tmp/java8.tar.gz -C /usr/lib/jvm \
27+
&& mv /usr/lib/jvm/zulu8.82.0.21-ca-fx-jdk8.0.432-linux_x64 /usr/lib/jvm/java-8-zulu-fx \
28+
&& rm /tmp/java8.tar.gz
29+
30+
# Download cn1-binaries
31+
# We download it to /opt/cn1-binaries so it can be reused
32+
RUN wget -q https://github.com/codenameone/cn1-binaries/archive/refs/heads/master.zip -O /tmp/cn1-binaries.zip \
33+
&& unzip -q /tmp/cn1-binaries.zip -d /opt \
34+
&& mv /opt/cn1-binaries-master /opt/cn1-binaries \
35+
&& rm /tmp/cn1-binaries.zip
36+
37+
# Set convenient env vars
38+
ENV JAVA_HOME_8=/usr/lib/jvm/java-8-zulu-fx
39+
ENV JAVA_HOME_17=/usr/lib/jvm/java-17-openjdk-amd64
40+
ENV JAVA_HOME_21=/usr/lib/jvm/java-21-openjdk-amd64
41+
42+
ENV CN1_BINARIES=/opt/cn1-binaries
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build Container
2+
3+
on:
4+
push:
5+
paths:
6+
- '.ci/container/Dockerfile'
7+
- '.github/workflows/build-container.yml'
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
20+
- name: Log in to the Container registry
21+
uses: docker/login-action@v2
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Build and push Docker image
28+
uses: docker/build-push-action@v4
29+
with:
30+
context: .ci/container
31+
push: true
32+
tags: ghcr.io/${{ github.repository }}/pr-ci-container:latest

.github/workflows/pr.yml

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,36 @@ permissions:
3232
contents: write
3333
pull-requests: write
3434
issues: write
35+
packages: read
3536

3637
jobs:
3738
build-test:
3839

3940
runs-on: ubuntu-latest
41+
container:
42+
image: ghcr.io/${{ github.repository }}/pr-ci-container:latest
43+
options: --privileged
4044
strategy:
4145
fail-fast: false
4246
matrix:
4347
java-version: [8, 17, 21, 25]
4448

4549
steps:
4650
- uses: actions/checkout@v1
47-
- name: Set up JDK 8
48-
if: matrix.java-version == 8
49-
uses: actions/setup-java@v1
50-
with:
51-
java-version: 1.8
52-
java-package: jdk+fx
53-
- name: Set up JDK
54-
if: matrix.java-version != 8
51+
- name: Configure Java
52+
run: |
53+
if [ "${{ matrix.java-version }}" == "8" ]; then
54+
echo "JAVA_HOME=$JAVA_HOME_8" >> $GITHUB_ENV
55+
echo "$JAVA_HOME_8/bin" >> $GITHUB_PATH
56+
elif [ "${{ matrix.java-version }}" == "17" ]; then
57+
echo "JAVA_HOME=$JAVA_HOME_17" >> $GITHUB_ENV
58+
echo "$JAVA_HOME_17/bin" >> $GITHUB_PATH
59+
elif [ "${{ matrix.java-version }}" == "21" ]; then
60+
echo "JAVA_HOME=$JAVA_HOME_21" >> $GITHUB_ENV
61+
echo "$JAVA_HOME_21/bin" >> $GITHUB_PATH
62+
fi
63+
- name: Set up JDK (Fallback/Java 25)
64+
if: matrix.java-version == 25
5565
uses: actions/setup-java@v4
5666
with:
5767
distribution: 'zulu'
@@ -76,7 +86,12 @@ jobs:
7686
run: |
7787
set -euo pipefail
7888
rm -rf maven/target/cn1-binaries
79-
git clone --depth=1 --filter=blob:none https://github.com/codenameone/cn1-binaries maven/target/cn1-binaries
89+
mkdir -p maven/target
90+
if [ -d "$CN1_BINARIES" ]; then
91+
ln -s "$CN1_BINARIES" maven/target/cn1-binaries
92+
else
93+
git clone --depth=1 --filter=blob:none https://github.com/codenameone/cn1-binaries maven/target/cn1-binaries
94+
fi
8095
- name: Run Maven plugin tests
8196
working-directory: maven
8297
env:
@@ -228,10 +243,15 @@ jobs:
228243
await publishQualityComment({ github, context, core });
229244
- name: Install dependencies
230245
run: |
231-
sudo apt-get update && sudo apt-get install xvfb
232-
wget https://github.com/codenameone/cn1-binaries/archive/refs/heads/master.zip
233-
unzip master.zip -d ..
234-
mv ../cn1-binaries-master ../cn1-binaries
246+
if [ -d "$CN1_BINARIES" ]; then
247+
echo "Using pre-installed cn1-binaries"
248+
ln -s "$CN1_BINARIES" ../cn1-binaries
249+
else
250+
sudo apt-get update && sudo apt-get install xvfb
251+
wget https://github.com/codenameone/cn1-binaries/archive/refs/heads/master.zip
252+
unzip master.zip -d ..
253+
mv ../cn1-binaries-master ../cn1-binaries
254+
fi
235255
- name: Build CLDC11 JAR
236256
run: |
237257
ANT_OPTS_ARGS=""

0 commit comments

Comments
 (0)