-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
166 lines (134 loc) · 6.78 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# syntax=docker/dockerfile:1.6
# Intermediate image used to prune cruft from JDKs and squash them all.
FROM cimg/base:current-22.04 AS all-jdk
COPY --from=eclipse-temurin:8-jdk-jammy /opt/java/openjdk /usr/lib/jvm/8
COPY --from=eclipse-temurin:11-jdk-jammy /opt/java/openjdk /usr/lib/jvm/11
COPY --from=eclipse-temurin:17-jdk-jammy /opt/java/openjdk /usr/lib/jvm/17
COPY --from=eclipse-temurin:21-jdk-jammy /opt/java/openjdk /usr/lib/jvm/21
COPY --from=azul/zulu-openjdk:7 /usr/lib/jvm/zulu7 /usr/lib/jvm/7
COPY --from=azul/zulu-openjdk:8 /usr/lib/jvm/zulu8 /usr/lib/jvm/zulu8
COPY --from=azul/zulu-openjdk:11 /usr/lib/jvm/zulu11 /usr/lib/jvm/zulu11
COPY --from=ibmjava:8-sdk /opt/ibm/java /usr/lib/jvm/ibm8
COPY --from=ibm-semeru-runtimes:open-8-jdk-jammy /opt/java/openjdk /usr/lib/jvm/semeru8
COPY --from=ibm-semeru-runtimes:open-11-jdk-jammy /opt/java/openjdk /usr/lib/jvm/semeru11
COPY --from=ibm-semeru-runtimes:open-17-jdk-jammy /opt/java/openjdk /usr/lib/jvm/semeru17
COPY --from=ghcr.io/graalvm/native-image-community:17-ol9 /usr/lib64/graalvm/graalvm-community-java17 /usr/lib/jvm/graalvm17
COPY --from=ghcr.io/graalvm/native-image-community:21-ol9 /usr/lib64/graalvm/graalvm-community-java21 /usr/lib/jvm/graalvm21
RUN sudo apt-get -y update && sudo apt-get -y install curl
# See: https://gist.github.com/wavezhang/ba8425f24a968ec9b2a8619d7c2d86a6
RUN <<-EOT
set -eux
sudo mkdir -p /usr/lib/jvm/oracle8
curl -L --fail "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=246284_165374ff4ea84ef0bbd821706e29b123" | sudo tar -xvzf - -C /usr/lib/jvm/oracle8 --strip-components 1
EOT
# Install Ubuntu's OpenJDK 17 and fix broken symlinks:
# some files in /usr/lib/jvm/ubuntu17 are symlinks to /etc/java-17-openjdk/, so we just copy all symlinks targets.
RUN <<-EOT
set -eux
sudo apt-get install openjdk-17-jdk
sudo mv /usr/lib/jvm/java-17-openjdk-amd64 /usr/lib/jvm/ubuntu17
sudo cp -rf --remove-destination /etc/java-17-openjdk/* /usr/lib/jvm/ubuntu17/conf/
sudo cp -rf --remove-destination /etc/java-17-openjdk/* /usr/lib/jvm/ubuntu17/lib/
sudo cp -f --remove-destination /etc/java-17-openjdk/jvm-amd64.cfg /usr/lib/jvm/ubuntu17/lib/
EOT
# Remove cruft from JDKs that is not used in the build process.
RUN <<-EOT
sudo rm -rf \
/usr/lib/jvm/*/man \
/usr/lib/jvm/*/lib/src.zip \
/usr/lib/jvm/*/demo \
/usr/lib/jvm/*/sample \
/usr/lib/jvm/graalvm*/lib/installer
EOT
FROM scratch AS default-jdk
COPY --from=all-jdk /usr/lib/jvm/8 /usr/lib/jvm/8
COPY --from=all-jdk /usr/lib/jvm/11 /usr/lib/jvm/11
COPY --from=all-jdk /usr/lib/jvm/17 /usr/lib/jvm/17
COPY --from=all-jdk /usr/lib/jvm/21 /usr/lib/jvm/21
# Base image with minimunm requirenents to build the project.
# Based on CircleCI Base Image with Ubuntu 22.04.3 LTS, present in most runners.
FROM cimg/base:current-22.04 AS base
# https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package
LABEL org.opencontainers.image.source=https://github.com/DataDog/dd-trace-java-docker-build
# Replace Docker Compose and yq versions by latest and remove docker-switch from CircleCI Base Image for security purposes
RUN <<-EOT
set -eu
dockerPluginDir=/usr/local/lib/docker/cli-plugins
sudo curl -sSL "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" -o $dockerPluginDir/docker-compose
sudo chmod +x $dockerPluginDir/docker-compose
sudo sudo update-alternatives --remove docker-compose /usr/local/bin/compose-switch
sudo rm -f /usr/local/bin/compose-switch
sudo rm /usr/local/bin/{install-man-page.sh,yq*}
curl -sSL "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$(dpkg --print-architecture).tar.gz" | sudo tar -xz -C /usr/local/bin --wildcards --no-anchored 'yq_linux_*'
sudo mv /usr/local/bin/yq{_linux_*,}
sudo chown root:root /usr/local/bin/yq
EOT
COPY --from=default-jdk /usr/lib/jvm /usr/lib/jvm
COPY autoforward.py /usr/local/bin/autoforward
# Install the following tools
# - awscli: AWS CLI
# - autoforward dependencies: tool to forward request to a remote Docker deamon
# - datadog-ci: Datadog CI tool
RUN <<-EOT
set -eux
sudo apt-get update
sudo apt-get install --no-install-recommends apt-transport-https socat
sudo apt-get install --no-install-recommends vim less debian-goodies
sudo apt-get install --no-install-recommends autossh
sudo apt-get install ca-certificates-java
sudo apt install python3-pip
sudo apt-get -y clean
sudo rm -rf /var/lib/apt/lists/*
pip3 install awscli
pip3 install requests requests-unixsocket2
pip3 cache purge
sudo chmod +x /usr/local/bin/autoforward
sudo curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_linux-x64" --output "/usr/local/bin/datadog-ci"
sudo chmod +x /usr/local/bin/datadog-ci
EOT
# IBM specific env variables
ENV IBM_JAVA_OPTIONS="-XX:+UseContainerSupport"
#Set some odd looking variables, since their default values are wrong and it is unclear how they are used
ENV JAVA_DEBIAN_VERSION=unused
ENV JAVA_VERSION=unused
# Setup environment variables to point to all jvms we have
ENV JAVA_8_HOME=/usr/lib/jvm/8
ENV JAVA_11_HOME=/usr/lib/jvm/11
ENV JAVA_17_HOME=/usr/lib/jvm/17
ENV JAVA_21_HOME=/usr/lib/jvm/21
ENV JAVA_HOME=${JAVA_8_HOME}
ENV PATH=${JAVA_HOME}/bin:${PATH}
FROM base AS variant
ARG VARIANT_LOWER
ARG VARIANT_UPPER
COPY --from=all-jdk /usr/lib/jvm/${VARIANT_LOWER} /usr/lib/jvm/${VARIANT_LOWER}
ENV JAVA_${VARIANT_UPPER}_HOME=/usr/lib/jvm/${VARIANT_LOWER}
ENV JAVA_${VARIANT_LOWER}_HOME=/usr/lib/jvm/${VARIANT_LOWER}
# Full image for debugging, contains all JDKs.
FROM base AS full
COPY --from=all-jdk /usr/lib/jvm/7 /usr/lib/jvm/7
COPY --from=all-jdk /usr/lib/jvm/zulu8 /usr/lib/jvm/zulu8
COPY --from=all-jdk /usr/lib/jvm/zulu11 /usr/lib/jvm/zulu11
COPY --from=all-jdk /usr/lib/jvm/oracle8 /usr/lib/jvm/oracle8
COPY --from=all-jdk /usr/lib/jvm/ibm8 /usr/lib/jvm/ibm8
COPY --from=all-jdk /usr/lib/jvm/semeru8 /usr/lib/jvm/semeru8
COPY --from=all-jdk /usr/lib/jvm/semeru11 /usr/lib/jvm/semeru11
COPY --from=all-jdk /usr/lib/jvm/semeru17 /usr/lib/jvm/semeru17
COPY --from=all-jdk /usr/lib/jvm/ubuntu17 /usr/lib/jvm/ubuntu17
COPY --from=all-jdk /usr/lib/jvm/graalvm17 /usr/lib/jvm/graalvm17
COPY --from=all-jdk /usr/lib/jvm/graalvm21 /usr/lib/jvm/graalvm21
ENV JAVA_7_HOME=/usr/lib/jvm/7
ENV JAVA_ZULU7_HOME=/usr/lib/jvm/7
ENV JAVA_ZULU8_HOME=/usr/lib/jvm/zulu8
ENV JAVA_ZULU11_HOME=/usr/lib/jvm/zulu11
ENV JAVA_ORACLE8_HOME=/usr/lib/jvm/oracle8
ENV JAVA_IBM8_HOME=/usr/lib/jvm/ibm8
# Temporarily set these aliases for backwards compatibility.
ENV JAVA_IBM11_HOME=/usr/lib/jvm/semeru11
ENV JAVA_IBM17_HOME=/usr/lib/jvm/semeru17
ENV JAVA_SEMERU8_HOME=/usr/lib/jvm/semeru8
ENV JAVA_SEMERU11_HOME=/usr/lib/jvm/semeru11
ENV JAVA_SEMERU17_HOME=/usr/lib/jvm/semeru17
ENV JAVA_UBUNTU17_HOME=/usr/lib/jvm/ubuntu17
ENV JAVA_GRAALVM17_HOME=/usr/lib/jvm/graalvm17
ENV JAVA_GRAALVM21_HOME=/usr/lib/jvm/graalvm21