|
1 | | -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build |
| 1 | +# Use build arguments to control user creation |
| 2 | +ARG NON_ROOT_USER=false |
| 3 | +ARG USERNAME=root |
| 4 | +ARG USERID=0 |
2 | 5 |
|
| 6 | +FROM ubuntu:20.04 |
| 7 | + |
| 8 | +# Install .NET |
| 9 | +RUN apt-get update && apt-get install -y wget apt-transport-https && \ |
| 10 | + wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \ |
| 11 | + dpkg -i packages-microsoft-prod.deb && \ |
| 12 | + apt-get update && apt-get install -y dotnet-sdk-9.0 |
| 13 | + |
| 14 | +# Install system dependencies |
3 | 15 | RUN set -xe \ |
4 | 16 | && DEBIAN_FRONTEND=noninteractive apt-get update -y \ |
5 | | - && apt-get install -y libfontconfig libdbus-1-3 libx11-6 libx11-xcb-dev cppcheck htop \ |
6 | | - python3 python3-distutils gcc g++ make nuget libgit2-dev libssl-dev \ |
| 17 | + && apt-get install -y libfontconfig libdbus-1-3 libx11-6 libx11-xcb-dev cppcheck htop \ |
| 18 | + python3 python3-distutils gcc g++ make nuget libgit2-dev libssl-dev curl wget git unzip zip \ |
7 | 19 | && rm -rf /var/lib/apt/lists/* \ |
8 | 20 | && apt-get purge --auto-remove \ |
9 | 21 | && apt-get clean |
10 | 22 |
|
11 | | -# this SHELL command is needed to allow using source |
12 | | -SHELL ["/bin/bash", "-c"] |
13 | | -# Install dependencies for scala backend |
14 | | -RUN apt-get update -y \ |
15 | | - && apt-get install -y curl wget unzip zip \ |
16 | | - && curl -s "https://get.sdkman.io" | bash \ |
17 | | - && chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh" \ |
18 | | - && source "$HOME/.sdkman/bin/sdkman-init.sh" \ |
19 | | - && sdk install java 17.0.9-oracle \ |
20 | | - && sdk install scala 3.3.0 \ |
21 | | - && sdk install sbt 1.9.0 |
22 | | - |
23 | | -# Install GNAT AND SPARK from AdaCore |
24 | | -WORKDIR /gnat_tmp/ |
| 23 | +# Conditionally create non-root user and set permissions |
| 24 | +RUN if [ "$NON_ROOT_USER" = "true" ]; then \ |
| 25 | + adduser --disabled-password --gecos '' --uid $USERID $USERNAME && \ |
| 26 | + mkdir -p /workdir /app && \ |
| 27 | + chown -R $USERNAME:$USERNAME /workdir /app; \ |
| 28 | +fi |
25 | 29 |
|
26 | | -# The ADD instruction will always download the file and the cache will be invalidated if the checksum of the file no longer matches |
27 | | -# On the other hand, the RUN instruction will not invalidate the cache unless its text changes. |
28 | | -# So if the remote file is updated, you won't get it. Docker will use the cached layer. |
29 | | -# In our case, the gnat-2021-20210519-x86_64-linux-bin will not change. So, it is preferable to ADD |
30 | | -#ADD https://community.download.adacore.com/v1/f3a99d283f7b3d07293b2e1d07de00e31e332325?filename=gnat-2021-20210519-x86_64-linux-bin ./gnat-2021-20210519-x86_64-linux-bin |
31 | | - |
32 | | -RUN wget -O gnat-2021-20210519-x86_64-linux-bin https://community.download.adacore.com/v1/f3a99d283f7b3d07293b2e1d07de00e31e332325?filename=gnat-2021-20210519-x86_64-linux-bin \ |
33 | | - && git clone https://github.com/AdaCore/gnat_community_install_script.git \ |
34 | | - && chmod +x gnat_community_install_script/install_package.sh \ |
35 | | - && chmod +x gnat-2021-20210519-x86_64-linux-bin \ |
36 | | - && gnat_community_install_script/install_package.sh ./gnat-2021-20210519-x86_64-linux-bin /opt/GNAT/gnat-x86-2021 \ |
37 | | - && cd \ |
38 | | - && rm -rf /gnat_tmp/ \ |
39 | | - && sed -i 's/# alias l=/alias l=/' ~/.bashrc \ |
40 | | - && sed -i 's/# export LS_OPTIONS/export LS_OPTIONS/' ~/.bashrc |
| 30 | +# Switch to the appropriate user |
| 31 | +USER $USERNAME |
41 | 32 |
|
42 | | -WORKDIR /app/ |
| 33 | +# Install SDKMAN |
| 34 | +RUN curl -s "https://get.sdkman.io" | bash && \ |
| 35 | + echo "source $HOME/.sdkman/bin/sdkman-init.sh" >> $HOME/.bashrc && \ |
| 36 | + bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && sdk install java 17.0.9-oracle && sdk install scala 3.3.0 && sdk install sbt 1.9.0" |
43 | 37 |
|
| 38 | +# Install GNAT and SPARK (temporarily switch back to root) |
| 39 | +USER root |
| 40 | +WORKDIR /gnat_tmp/ |
| 41 | +RUN wget -O gnat-2021-x86_64-linux-bin https://community.download.adacore.com/v1/f3a99d283f7b3d07293b2e1d07de00e31e332325?filename=gnat-2021-20210519-x86_64-linux-bin \ |
| 42 | + && git clone https://github.com/AdaCore/gnat_community_install_script.git \ |
| 43 | + && chmod +x gnat_community_install_script/install_package.sh \ |
| 44 | + && chmod +x gnat-2021-x86_64-linux-bin \ |
| 45 | + && gnat_community_install_script/install_package.sh ./gnat-2021-x86_64-linux-bin /opt/GNAT/gnat-x86-2021 \ |
| 46 | + && rm -rf /gnat_tmp/ |
| 47 | + |
| 48 | +# Set back to the appropriate user |
| 49 | +USER $USERNAME |
| 50 | +WORKDIR /app/ |
44 | 51 | ENV PATH="/opt/GNAT/gnat-x86-2021/bin:${PATH}" |
45 | | -#ENTRYPOINT ["/bin/bash"] |
|
0 commit comments