Skip to content

Commit 2ac5e47

Browse files
committed
Allow installing Corretto JDK
1 parent f5fcd37 commit 2ac5e47

File tree

4 files changed

+86
-93
lines changed

4 files changed

+86
-93
lines changed

.github/workflows/pull_request.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install Make
3131
run: apt update && apt install -y make
3232
- name: Install JDK
33-
run: "./scripts/install_jdk.sh"
33+
run: "bash -x ./docker/install_jdk.sh"
3434
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
3535
# - uses: actions/setup-java@v4
3636
# with:
@@ -49,7 +49,7 @@ jobs:
4949
strategy:
5050
fail-fast: false
5151
matrix:
52-
swift_version: [ '6.0' ]
52+
swift_version: [ 'nightly-main' ]
5353
os_version: [ 'jammy' ]
5454
container:
5555
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
@@ -60,7 +60,7 @@ jobs:
6060
- name: Install Make
6161
run: apt update && apt install -y make
6262
- name: Install JDK
63-
run: "./scripts/install_jdk.sh"
63+
run: "bash -x ./docker/install_jdk.sh"
6464
- name: Generate sources (make) (Temporary)
6565
# TODO: this should be triggered by the respective builds
6666
run: "make jextract-run"

docker/Dockerfile

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,16 @@ ARG swift_version
77
ARG ubuntu_version
88

99
# set as UTF-8
10-
RUN apt-get update && apt-get install -y locales locales-all
10+
RUN apt-get update && apt-get install -y \
11+
locales locales-all \
12+
make \
13+
libc6-dev
1114
ENV LC_ALL=en_US.UTF-8
1215
ENV LANG=en_US.UTF-8
1316
ENV LANGUAGE=en_US.UTF-8
1417

15-
# Build dependencies
16-
RUN apt-get update && apt-get install -y make curl libc6-dev
17-
18-
# JDK dependency (we require JDK22+ which isn't distributed as package in Jammy)
19-
# We download the latest supported non-LTS version from OpenJDK: https://jdk.java.net
20-
RUN echo "Download JDK for: $(uname -m)"
21-
RUN if [ "$(uname -m)" = 'aarch64' ]; then \
22-
echo "Download JDK for: ARM64" && \
23-
curl https://download.java.net/java/GA/jdk23/3c5b90190c68498b986a97f276efd28a/37/GPL/openjdk-23_linux-aarch64_bin.tar.gz --output jdk.tar.gz && \
24-
EXPECT_JDK_SHA=076dcf7078cdf941951587bf92733abacf489a6570f1df97ee35945ffebec5b7; \
25-
else \
26-
echo "Download JDK for: x86" && \
27-
curl https://download.java.net/java/GA/jdk23/3c5b90190c68498b986a97f276efd28a/37/GPL/openjdk-23_linux-x64_bin.tar.gz --output jdk.tar.gz && \
28-
EXPECT_JDK_SHA=08fea92724127c6fa0f2e5ea0b07ff4951ccb1e2f22db3c21eebbd7347152a67; \
29-
fi
30-
# Verify the downlaoded JDK checksums
31-
RUN JDK_SHA=$(sha256sum jdk.tar.gz | cut -d ' ' -f 1)
32-
RUN if [ "$JDK_SHA" != "$EXPECT_JDK_SHA" ]; then \
33-
echo "Downloaded JDK SHA does not match expected!" && \
34-
exit 1; \
35-
else \
36-
echo "JDK SHA is correct."; \
37-
fi
38-
# Extract and verify the JDK installation
39-
RUN tar xzvf jdk.tar.gz && rm jdk.tar.gz && mv jdk-23 jdk
40-
RUN /jdk/bin/java -version
41-
ENV JAVA_HOME="/jdk"
42-
ENV PATH="$PATH:/jdk/bin"
18+
# JDK dependency
19+
COPY install_jdk.sh .
20+
RUN bash -x ./install_jdk.sh
21+
ENV JAVA_HOME="/usr/lib/jvm/default-jdk"
22+
ENV PATH="$PATH:/usr/lib/jvm/default-jdk/bin"

docker/install_jdk.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the Swift.org open source project
5+
##
6+
## Copyright (c) 2024 Apple Inc. and the Swift.org project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of Swift.org project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
set -euo pipefail
16+
17+
# Supported JDKs: Corretto or OpenJDK
18+
declare -r JDK_VENDOR=Corretto
19+
echo "Installing $JDK_VENDOR JDK..."
20+
21+
apt-get update && apt-get install -y wget
22+
23+
echo "Download JDK for: $(uname -m)"
24+
25+
if [ "$JDK_VENDOR" = 'OpenJDK' ]; then
26+
if [ "$(uname -m)" = 'aarch64' ]; then
27+
declare -r JDK_URL="https://download.java.net/java/GA/jdk23/3c5b90190c68498b986a97f276efd28a/37/GPL/openjdk-23_linux-aarch64_bin.tar.gz"
28+
declare -r EXPECT_JDK_SHA="076dcf7078cdf941951587bf92733abacf489a6570f1df97ee35945ffebec5b7"
29+
else
30+
declare -r JDK_URL="https://download.java.net/java/GA/jdk23/3c5b90190c68498b986a97f276efd28a/37/GPL/$JDK_NAME"
31+
declare -r EXPECT_JDK_SHA="08fea92724127c6fa0f2e5ea0b07ff4951ccb1e2f22db3c21eebbd7347152a67"
32+
fi
33+
34+
wget -q -O jdk.tar.gz "$JDK_URL"
35+
declare -r JDK_SHA="$(sha256sum jdk.tar.gz | cut -d ' ' -f 1)"
36+
if [ "$JDK_SHA" != "$EXPECT_JDK_SHA" ]; then
37+
echo "Downloaded JDK SHA does not match expected!"
38+
echo "Expected: $EXPECT_JDK_SHA"
39+
echo " Was: $JDK_SHA"
40+
exit 1;
41+
else
42+
echo "JDK SHA is correct.";
43+
fi
44+
elif [ "$JDK_VENDOR" = 'Corretto' ]; then
45+
if [ "$(uname -m)" = 'aarch64' ]; then
46+
declare -r JDK_URL="https://corretto.aws/downloads/latest/amazon-corretto-22-aarch64-linux-jdk.tar.gz"
47+
declare -r EXPECT_JDK_MD5="1ebe5f5229bb18bc784a1e0f54d3fe39"
48+
else
49+
declare -r JDK_URL="https://corretto.aws/downloads/latest/amazon-corretto-22-x64-linux-jdk.tar.gz"
50+
declare -r EXPECT_JDK_MD5="5bd7fe30eb063699a3b4db7a00455841"
51+
fi
52+
53+
wget -q -O jdk.tar.gz "$JDK_URL"
54+
declare -r JDK_MD5="$(md5sum jdk.tar.gz | cut -d ' ' -f 1)"
55+
if [ "$JDK_MD5" != "$EXPECT_JDK_MD5" ]; then
56+
echo "Downloaded JDK MD5 does not match expected!"
57+
echo "Expected: $EXPECT_JDK_MD5"
58+
echo " Was: $JDK_MD5"
59+
exit 1;
60+
else
61+
echo "JDK MD5 is correct.";
62+
fi
63+
fi
64+
65+
# Extract and verify the JDK installation
66+
67+
mkdir -p /usr/lib/jvm/ && cd /usr/lib/jvm/
68+
tar xzvf /jdk.tar.gz
69+
ls -lah
70+
mv "$(ls | head -n1)" default-jdk
71+
rm /jdk.tar.gz
72+
73+
echo "JAVA_HOME = /usr/lib/jvm/default-jdk"
74+
/usr/lib/jvm/default-jdk/bin/java -version

scripts/install_jdk.sh

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)