Skip to content

Commit 28e6975

Browse files
committed
Fix deploy / restructure build process
1 parent d071b61 commit 28e6975

File tree

7 files changed

+89
-44
lines changed

7 files changed

+89
-44
lines changed

.github/workflows/deploy.yml

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,44 @@ on:
99
permissions:
1010
contents: write
1111

12+
env:
13+
IMAGE_TAG: exercism/java-test-runner-crac-checkpoint
14+
1215
jobs:
1316
build-and-push-image:
1417
if: github.repository_owner == 'exercism' # Stops this job from running on forks.
15-
uses: exercism/github-actions/.github/workflows/docker-build-push-image.yml@main
16-
secrets:
17-
AWS_ACCOUNT_ID: ${{secrets.AWS_ACCOUNT_ID}}
18-
AWS_REGION: ${{secrets.AWS_REGION}}
19-
AWS_ECR_ACCESS_KEY_ID: ${{secrets.AWS_ECR_ACCESS_KEY_ID}}
20-
AWS_ECR_SECRET_ACCESS_KEY: ${{secrets.AWS_ECR_SECRET_ACCESS_KEY}}
21-
DOCKERHUB_USERNAME: ${{secrets.DOCKERHUB_USERNAME}}
22-
DOCKERHUB_PASSWORD: ${{secrets.DOCKERHUB_PASSWORD}}
18+
steps:
19+
- name: Setup Java
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: 'temurin'
23+
java-version: 21
24+
- name: Setup Gradle
25+
uses: gradle/actions/setup-gradle@v4
26+
- name: Build with Gradle
27+
run: ./gradlew build
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
- name: Build and export to Docker
31+
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4
32+
with:
33+
context: .
34+
file: ./Dockerfile.createCheckpoint
35+
load: true
36+
cache-from: type=gha
37+
cache-to: type=gha,mode=max
38+
# build-args: ${{ secrets.DOCKER_BUILD_ARGS }}
39+
provenance: false
40+
platforms: linux/amd64
41+
tags: ${{ env.IMAGE_TAG }}
42+
- name: Create CRaC checkpoint
43+
run: bin/create-checkpoint.sh ${{ env.IMAGE_TAG }}
44+
- name: Build and push Docker image
45+
uses: exercism/github-actions/.github/workflows/docker-build-push-image.yml@main
46+
secrets:
47+
AWS_ACCOUNT_ID: ${{secrets.AWS_ACCOUNT_ID}}
48+
AWS_REGION: ${{secrets.AWS_REGION}}
49+
AWS_ECR_ACCESS_KEY_ID: ${{secrets.AWS_ECR_ACCESS_KEY_ID}}
50+
AWS_ECR_SECRET_ACCESS_KEY: ${{secrets.AWS_ECR_SECRET_ACCESS_KEY}}
51+
DOCKERHUB_USERNAME: ${{secrets.DOCKERHUB_USERNAME}}
52+
DOCKERHUB_PASSWORD: ${{secrets.DOCKERHUB_PASSWORD}}

Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
FROM bellsoft/liberica-runtime-container:jdk-21-crac-musl AS build
22

3-
WORKDIR /app
4-
COPY . /app
5-
RUN /app/gradlew -i --stacktrace clean build
6-
7-
FROM bellsoft/liberica-runtime-container:jdk-21-crac-musl
8-
93
WORKDIR /opt/test-runner
10-
COPY bin/run-to-create-crac-checkpoint.sh bin/run-to-create-crac-checkpoint.sh
4+
COPY build/libs/java-test-runner.jar /opt/test-runner/java-test-runner.jar
115
COPY bin/run-restore-from-checkpoint.sh bin/run-restore-from-checkpoint.sh
12-
COPY --from=build /app/build/libs/java-test-runner.jar .
6+
COPY --link build/cr /opt/test-runner/crac-checkpoint
137

14-
ENTRYPOINT ["sh", "/opt/test-runner/bin/run-to-create-crac-checkpoint.sh"]
8+
ENTRYPOINT ["sh", "/opt/test-runner/bin/run-restore-from-checkpoint.sh"]

Dockerfile.createCheckpoint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM bellsoft/liberica-runtime-container:jdk-21-crac-musl
2+
3+
WORKDIR /opt/test-runner
4+
COPY build/libs/java-test-runner.jar /opt/test-runner/java-test-runner.jar
5+
COPY bin/run-to-create-crac-checkpoint.sh bin/run-to-create-crac-checkpoint.sh
6+
7+
ENTRYPOINT ["sh", "/opt/test-runner/bin/run-to-create-crac-checkpoint.sh"]

bin/build-crac-checkpoint-image.sh

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,11 @@
77
# The final image is created by committing the containiner
88
# containing the checkpoint.
99

10-
docker build -t exercism/java-test-runner-crac-checkpoint .
10+
# build outside of Docker container, so we can copy jar into both images
11+
./gradlew build
1112

12-
# Copy all tests into one merged project, so we can warm up the JVM
13-
# TODO(FAP): this is missing some tests as most tests use the same filenames
14-
mkdir -p tests/merged
15-
for dir in tests/*; do
16-
if [ -d "$dir" ] && [ "$dir" != "tests/merged/" ]; then
17-
rsync -a "$dir"/ tests/merged/
18-
fi
19-
done
13+
docker build -t exercism/java-test-runner-crac-checkpoint -f Dockerfile.createCheckpoint .
2014

21-
slug="merged"
22-
solution_dir=$(realpath "tests/merged/")
23-
output_dir=$(realpath "tests/merged/")
15+
bin/create-checkpoint.sh
2416

25-
docker run --cap-add CHECKPOINT_RESTORE \
26-
--cap-add SYS_PTRACE \
27-
--name java-test-runner-crac \
28-
--network none \
29-
--mount type=bind,src="${solution_dir}",dst=/solution \
30-
--mount type=bind,src="${output_dir}",dst=/output \
31-
--mount type=tmpfs,dst=/tmp \
32-
exercism/java-test-runner-crac-checkpoint "${slug}" /solution /output
33-
34-
docker commit --change='ENTRYPOINT ["sh", "/opt/test-runner/bin/run-restore-from-checkpoint.sh"]' java-test-runner-crac exercism/java-test-runner-crac-restore
35-
36-
docker rm -f java-test-runner-crac
37-
rm -rf tests/merged/
17+
docker build -t exercism/java-test-runner -f Dockerfile .

bin/create-checkpoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env sh
2+
3+
# Copy all tests into one merged project, so we can warm up the JVM
4+
# TODO(FAP): this is missing some tests as most tests use the same filenames
5+
mkdir -p tests/merged
6+
for dir in tests/*; do
7+
if [ -d "$dir" ] && [ "$dir" != "tests/merged/" ]; then
8+
rsync -a "$dir"/ tests/merged/
9+
fi
10+
done
11+
12+
real_path() {
13+
echo "$(cd "$(dirname -- "$1")" >/dev/null; pwd -P)/$(basename -- "$1")";
14+
}
15+
16+
mkdir -p build/cr
17+
18+
image_tag="${1:-exercism/java-test-runner-crac-checkpoint}"
19+
slug="merged"
20+
solution_dir=$(realpath "tests/merged/")
21+
output_dir=$(realpath "tests/merged/")
22+
23+
docker run --cap-add CHECKPOINT_RESTORE \
24+
--cap-add SYS_PTRACE \
25+
--name java-test-runner-crac \
26+
--network none \
27+
--mount type=bind,src="${solution_dir}",dst=/solution \
28+
--mount type=bind,src="${output_dir}",dst=/output \
29+
--mount type=bind,src="$(real_path build/cr)",dst=/opt/test-runner/crac-checkpoint \
30+
--mount type=tmpfs,dst=/tmp \
31+
"${image_tag}" "${slug}" /solution /output
32+
33+
docker rm -f java-test-runner-crac
34+
rm -rf tests/merged/

bin/run-in-docker-without-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ docker run \
3737
--mount type=bind,src="${solution_dir}",dst=/solution \
3838
--mount type=bind,src="${output_dir}",dst=/output \
3939
--mount type=tmpfs,dst=/tmp \
40-
exercism/java-test-runner-crac-restore "${slug}" /solution /output
40+
exercism/java-test-runner "${slug}" /solution /output

bin/run-in-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ docker run \
4040
--mount type=bind,src="${solution_dir}",dst=/solution \
4141
--mount type=bind,src="${output_dir}",dst=/output \
4242
--mount type=tmpfs,dst=/tmp \
43-
exercism/java-test-runner-crac-restore "${slug}" /solution /output
43+
exercism/java-test-runner "${slug}" /solution /output

0 commit comments

Comments
 (0)