forked from oss-review-toolkit/ort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
456 lines (367 loc) · 14.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# syntax=docker/dockerfile:1.4
# Copyright (C) 2020 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE
# Set this to the Java version to use in the base image (and to build and run ORT with).
ARG JAVA_VERSION=17
# Use OpenJDK Eclipe Temurin Ubuntu LTS
FROM eclipse-temurin:$JAVA_VERSION-jdk-jammy as ort-base-image
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# Check and set apt proxy
COPY docker/set_apt_proxy.sh /etc/scripts/set_apt_proxy.sh
RUN /etc/scripts/set_apt_proxy.sh
# Base package set
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
coreutils \
cvs \
curl \
dirmngr \
gcc \
git \
g++ \
gnupg2 \
iproute2 \
libarchive-tools \
libffi-dev \
libgmp-dev \
libz-dev \
locales \
lzma \
make \
netbase \
openssh-client \
openssl \
procps \
rsync \
sudo \
tzdata \
uuid-dev \
unzip \
wget \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
RUN echo $LANG > /etc/locale.gen \
&& locale-gen $LANG \
&& update-locale LANG=$LANG
ARG USERNAME=ort
ARG USER_ID=1000
ARG USER_GID=$USER_ID
ARG HOMEDIR=/home/ort
ENV HOME=$HOMEDIR
ENV USER=$USERNAME
# Non privileged user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd \
--uid $USER_ID \
--gid $USER_GID \
--shell /bin/bash \
--home-dir $HOMEDIR \
--create-home $USERNAME
RUN chgrp $USER /opt \
&& chmod g+wx /opt
# sudo support
RUN echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
# Copy certificates scripts only.
COPY scripts/*_certificates.sh /etc/scripts/
# Set this to a directory containing CRT-files for custom certificates that ORT and all build tools should know about.
ARG CRT_FILES="*.crt"
COPY "$CRT_FILES" /tmp/certificates/
RUN /etc/scripts/export_proxy_certificates.sh /tmp/certificates/ \
&& /etc/scripts/import_certificates.sh /tmp/certificates/
ENTRYPOINT [ "/bin/bash" ]
#------------------------------------------------------------------------
# PYTHON - Build Python as a separate component with pyenv
FROM ort-base-image as pythonbuild
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
libreadline-dev \
libgdbm-dev \
libsqlite3-dev \
libssl-dev \
libbz2-dev \
liblzma-dev \
tk-dev \
&& sudo rm -rf /var/lib/apt/lists/*
ARG PYTHON_VERSION=3.10.8
ARG PYENV_GIT_TAG=v2.3.7
ENV PYENV_ROOT=/opt/python
ENV PATH=$PATH:${PYENV_ROOT}/shims:${PYENV_ROOT}/bin
RUN curl -kSs https://pyenv.run | bash \
&& pyenv install -v ${PYTHON_VERSION} \
&& pyenv global ${PYTHON_VERSION}
ARG CONAN_VERSION=1.53.0
ARG PYTHON_INSPECTOR_VERSION=0.9.2
ARG PYTHON_PIPENV_VERSION=2022.9.24
ARG PYTHON_POETRY_VERSION=1.2.2
ARG PIPTOOL_VERSION=22.2.2
ARG SCANCODE_VERSION=31.2.1
RUN pip install --no-cache-dir -U \
pip=="${PIPTOOL_VERSION}" \
wheel \
&& pip install --no-cache-dir -U \
Mercurial \
conan=="${CONAN_VERSION}" \
pipenv=="${PYTHON_PIPENV_VERSION}" \
poetry=="${PYTHON_POETRY_VERSION}" \
python-inspector=="${PYTHON_INSPECTOR_VERSION}"
RUN arch=$(arch | sed s/aarch64/arm64/) \
&& if [ "$arch" != "arm64" ]; then \
curl -Os https://raw.githubusercontent.com/nexB/scancode-toolkit/v$SCANCODE_VERSION/requirements.txt; \
pip install -U --constraint requirements.txt scancode-toolkit==$SCANCODE_VERSION; \
rm requirements.txt; \
fi
FROM scratch AS python
COPY --from=pythonbuild /opt/python /opt/python
#------------------------------------------------------------------------
# RUBY - Build Ruby as a separate component with rbenv
FROM ort-base-image AS rubybuild
# hadolint ignore=DL3004
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
libreadline6-dev \
libssl-dev \
libz-dev \
make \
xvfb \
zlib1g-dev \
&& sudo rm -rf /var/lib/apt/lists/*
ARG COCOAPODS_VERSION=1.11.2
ARG RUBY_VERSION=3.1.2
ENV RBENV_ROOT=/opt/rbenv
ENV PATH=${RBENV_ROOT}/bin:${RBENV_ROOT}/shims/:${RBENV_ROOT}/plugins/ruby-build/bin:$PATH
RUN git clone --depth 1 https://github.com/rbenv/rbenv.git ${RBENV_ROOT}
RUN git clone --depth 1 https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
WORKDIR ${RBENV_ROOT}
RUN src/configure \
&& make -C src
RUN rbenv install ${RUBY_VERSION} -v \
&& rbenv global ${RUBY_VERSION} \
&& gem install bundler cocoapods:${COCOAPODS_VERSION}
FROM scratch AS ruby
COPY --from=rubybuild ${RBENV_ROOT} ${RBENV_ROOT}
#------------------------------------------------------------------------
# NODEJS - Build NodeJS as a separate component with nvm
FROM ort-base-image AS nodebuild
ARG BOWER_VERSION=1.8.12
ARG NODEJS_VERSION=18.12.1
ARG NPM_VERSION=8.15.1
ARG PNPM_VERSION=7.8.0
ARG YARN_VERSION=1.22.17
ENV NVM_DIR=/opt/nvm
ENV PATH=$PATH:$NVM_DIR/versions/node/v$NODEJS_VERSION/bin
RUN git clone --depth 1 https://github.com/nvm-sh/nvm.git $NVM_DIR
RUN . $NVM_DIR/nvm.sh \
&& nvm install "${NODEJS_VERSION}" \
&& nvm alias default "${NODEJS_VERSION}" \
&& nvm use default \
&& npm install --global npm@$NPM_VERSION bower@$BOWER_VERSION pnpm@$PNPM_VERSION yarn@$YARN_VERSION
FROM scratch AS node
COPY --from=nodebuild ${NVM_DIR} ${NVM_DIR}
#------------------------------------------------------------------------
# RUST - Build as a separate component
FROM ort-base-image AS rustbuild
ARG RUST_HOME=/opt/rust
ARG CARGO_HOME=${RUST_HOME}/cargo
ARG RUSTUP_HOME=${RUST_HOME}/rustup
ARG RUST_VERSION=1.64.0
RUN curl -ksSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${RUST_VERSION}
FROM scratch AS rust
COPY --from=rustbuild /opt/rust /opt/rust
#------------------------------------------------------------------------
# GOLANG - Build as a separate component
FROM ort-base-image AS gobuild
ARG GO_DEP_VERSION=0.5.4
ARG GO_VERSION=1.18.3
ENV GOBIN=/opt/go/bin
ENV PATH=$PATH:/opt/go/bin
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) \
&& curl -L https://dl.google.com/go/go${GO_VERSION}.linux-${arch}.tar.gz | tar -C /opt -xz \
&& curl -ksS https://raw.githubusercontent.com/golang/dep/v$GO_DEP_VERSION/install.sh | bash
FROM scratch AS golang
COPY --from=gobuild /opt/go /opt/go
#------------------------------------------------------------------------
# HASKELL STACK
FROM ort-base-image AS haskellbuild
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
zlib1g-dev \
&& sudo rm -rf /var/lib/apt/lists/*
ARG HASKELL_STACK_VERSION=2.7.5
ENV HASKELL_HOME=/opt/haskell
ENV PATH=$PATH:${HASKELL_HOME}/bin
RUN curl -sSL https://get.haskellstack.org/ | bash -s -- -d ${HASKELL_HOME}/bin
FROM scratch AS haskell
COPY --from=haskellbuild ${HASKELL_HOME} ${HASKELL_HOME}
#------------------------------------------------------------------------
# REPO / ANDROID SDK
FROM ort-base-image AS androidbuild
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
unzip \
&& sudo rm -rf /var/lib/apt/lists/*
ARG ANDROID_CMD_VERSION=8512546
ENV ANDROID_HOME=/opt/android-sdk
RUN --mount=type=tmpfs,target=/android \
cd /android \
&& curl -Os https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_CMD_VERSION}_latest.zip \
&& unzip -q commandlinetools-linux-${ANDROID_CMD_VERSION}_latest.zip -d $ANDROID_HOME \
&& PROXY_HOST_AND_PORT=${https_proxy#*://} \
&& if [ -n "$PROXY_HOST_AND_PORT" ]; then \
# While sdkmanager uses HTTPS by default, the proxy type is still called "http".
SDK_MANAGER_PROXY_OPTIONS="--proxy=http --proxy_host=${PROXY_HOST_AND_PORT%:*} --proxy_port=${PROXY_HOST_AND_PORT##*:}"; \
fi \
&& yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager $SDK_MANAGER_PROXY_OPTIONS --sdk_root=$ANDROID_HOME "platform-tools" "cmdline-tools;latest"
RUN curl -ksS https://storage.googleapis.com/git-repo-downloads/repo | tee $ANDROID_HOME/cmdline-tools/bin/repo > /dev/null 2>&1 \
&& sudo chmod a+x $ANDROID_HOME/cmdline-tools/bin/repo
FROM scratch AS android
COPY --from=androidbuild ${ANDROID_HOME} ${ANDROID_HOME}
#------------------------------------------------------------------------
# Dart
FROM ort-base-image AS dartbuild
ARG DART_VERSION=2.18.4
WORKDIR /opt/
ENV DART_SDK=/opt/dart-sdk
ENV PATH=$PATH:${DART_SDK}/bin
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=tmpfs,target=/dart \
arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/x64/) \
&& curl -o /dart/dart.zip -L https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-${arch}-release.zip \
&& unzip /dart/dart.zip
FROM scratch AS dart
COPY --from=dartbuild ${DART_SDK} ${DART_SDK}
#------------------------------------------------------------------------
# SBT
FROM ort-base-image AS sbtbuild
ARG SBT_VERSION=1.6.1
ENV SBT_HOME=/opt/sbt
ENV PATH=$PATH:${SBT_HOME}/bin
RUN curl -L https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz | tar -C /opt -xz
FROM scratch AS sbt
COPY --from=sbtbuild ${DART_SDK} ${DART_SDK}
#------------------------------------------------------------------------
# ORT
FROM ort-base-image as ortbuild
# Set this to the version ORT should report.
ARG ORT_VERSION="DOCKER-SNAPSHOT"
WORKDIR ${HOME}/src/ort
# Prepare Gradle
RUN --mount=type=cache,target=/var/tmp/gradle \
--mount=type=bind,target=${HOME}/src/ort,rw \
export GRADLE_USER_HOME=/var/tmp/gradle \
&& scripts/export_proxy_certificates.sh /tmp/certificates/ \
&& scripts/import_certificates.sh /tmp/certificates/ \
&& scripts/set_gradle_proxy.sh \
&& ./gradlew --no-daemon --stacktrace \
-Pversion=$ORT_VERSION \
:cli:installDist \
:helper-cli:startScripts \
&& mkdir /opt/ort \
&& cp -a ${HOME}/src/ort/cli/build/install/ort /opt/ \
&& cp -a ${HOME}/src/ort/scripts/*.sh /opt/ort/bin/ \
&& cp -a ${HOME}/src/ort/helper-cli/build/scripts/orth /opt/ort/bin/ \
&& cp -a ${HOME}/src/ort/helper-cli/build/libs/helper-cli-*.jar /opt/ort/lib/
FROM scratch AS ort
COPY --from=ortbuild /opt/ort /opt/ort
#------------------------------------------------------------------------
# Components container
FROM ort-base-image as components
# Remove ort build scripts
RUN [ -d /etc/scripts ] && sudo rm -rf /etc/scripts
# Apt install commands.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
php \
subversion \
&& rm -rf /var/lib/apt/lists/*
# Python
ENV PYENV_ROOT=/opt/python
ENV PATH=$PATH:${PYENV_ROOT}/shims:${PYENV_ROOT}/bin
COPY --from=python ${PYENV_ROOT} ${PYENV_ROOT}
#RUN sudo chown -R ${USER}.${USER} ${PYENV_ROOT}
# Ruby
ENV RBENV_ROOT=/opt/rbenv/
ENV GEM_HOME=/var/tmp/gem
ENV PATH=$PATH:${RBENV_ROOT}/bin:${RBENV_ROOT}/shims:${RBENV_ROOT}/plugins/ruby-install/bin
COPY --from=ruby ${RBENV_ROOT} ${RBENV_ROOT}
# NodeJS
ARG NODEJS_VERSION=18.12.1
ENV NVM_DIR=/opt/nvm
ENV NODE_PATH $NVM_DIR/v$NODEJS_VERSION/lib/node_modules
ENV PATH=$PATH:$NVM_DIR/versions/node/v$NODEJS_VERSION/bin
COPY --from=node ${NVM_DIR} ${NVM_DIR}
# Rust
ENV RUST_HOME=/opt/rust
ENV CARGO_HOME=${RUST_HOME}/cargo
ENV RUSTUP_HOME=${RUST_HOME}/rustup
ENV PATH=$PATH:${CARGO_HOME}/bin:${RUSTUP_HOME}/bin
COPY --chown=$USER:$USER --from=rust /opt/rust /opt/rust
RUN chmod o+rwx ${CARGO_HOME}
# Golang
ENV PATH=$PATH:/opt/go/bin
COPY --from=golang /opt/go /opt/go
# Haskell
ENV HASKELL_HOME=/opt/haskell
ENV PATH=$PATH:${HASKELL_HOME}/bin
COPY --from=haskell ${HASKELL_HOME} ${HASKELL_HOME}
# Repo and Android
ENV ANDROID_HOME=/opt/android-sdk
ENV ANDROID_USER_HOME=${HOME}/.android
ENV PATH=$PATH:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/cmdline-tools/bin
ENV PATH=$PATH:${ANDROID_HOME}/platform-tools
COPY --from=android ${ANDROID_HOME} ${ANDROID_HOME}
RUN chmod -R o+rw ${ANDROID_HOME}
# Dart
ENV DART_SDK=/opt/dart-sdk
ENV PATH=$PATH:${DART_SDK}/bin
COPY --from=dart ${DART_SDK} ${DART_SDK}
# SBT
ENV SBT_HOME=/opt/sbt
ENV PATH=$PATH:${SBT_HOME}/bin
COPY --from=sbt ${SBT_HOME} ${SBT_HOME}
# PHP composer
ARG COMPOSER_VERSION=2.2
RUN curl -ksS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --$COMPOSER_VERSION
ENTRYPOINT ["/bin/bash"]
#------------------------------------------------------------------------
# Main Runtime container
FROM components AS run
# ORT
COPY --from=ort /opt/ort /opt/ort
ENV PATH=$PATH:/opt/ort/bin
USER $USERNAME
WORKDIR $HOMEDIR
# Ensure that the ORT data directory exists to be able to mount the config into it with correct permissions.
RUN mkdir -p "$HOMEDIR/.ort"
ENTRYPOINT ["/opt/ort/bin/ort"]