-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
192 lines (162 loc) · 6.33 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
ARG MINIZINC_VERSION=2.8.3
ARG MINIZINC_HOME=/usr/local/share/minizinc
ARG ORTOOLS_VERSION=9.7
ARG ORTOOLS_BUILD=2996
ARG ORTOOLS_HOME=/opt/ortools
ARG USER_UID=1000
ARG USER_GID=1000
ARG USER_NAME=dev
# ********************************************************
# Dotnet SDK
# ********************************************************
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim as dotnet-sdk
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
# Add nonroot user
ARG USER_NAME
ARG USER_GID
ARG USER_UID
RUN groupadd --gid ${USER_GID} ${USER_NAME} \
&& useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USER_NAME} \
&& apt-get update \
&& apt-get install -y sudo \
&& echo ${USER_NAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER_NAME} \
&& chmod 0440 /etc/sudoers.d/${USER_NAME}
# ********************************************************
# MiniZinc Builder
#
# This layer installs MiniZinc into the $MINIZINC_HOME
# directory which is later copied to other images.
#
# Google OR-Tools solver for MiniZinc is also installed
#
# ********************************************************
FROM minizinc/minizinc:${MINIZINC_VERSION} as minizinc-builder
ARG DEBIAN_FRONTEND=noninteractive
# Install required packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install OR-Tools
ARG DEBIAN_VERSION=11
ARG MINIZINC_HOME
ARG ORTOOLS_VERSION
ARG ORTOOLS_BUILD
ARG ORTOOLS_HOME
ARG ORTOOLS_VERSION_BUILD=${ORTOOLS_VERSION}.${ORTOOLS_BUILD}
ARG ORTOOLS_TAR_NAME=or-tools_amd64_debian-11_cpp_v${ORTOOLS_VERSION_BUILD}.tar.gz
ARG ORTOOLS_TAR_URL=https://github.com/google/or-tools/releases/download/v${ORTOOLS_VERSION}/${ORTOOLS_TAR_NAME}
ARG ORTOOLS_DIR_NAME=or-tools_x86_64_Debian-${DEBIAN_VERSION}_cpp_v${ORTOOLS_VERSION_BUILD}
# Download and unpack the C++ build for this OS
RUN wget -c ${ORTOOLS_TAR_URL} && \
tar -xzvf ${ORTOOLS_TAR_NAME}
# Move the files to the correct location
RUN mv ${ORTOOLS_DIR_NAME} ${ORTOOLS_HOME} && \
cp ${ORTOOLS_HOME}/share/minizinc/solvers/* ${MINIZINC_HOME}/solvers \
&& cp -r ${ORTOOLS_HOME}/share/minizinc/ortools ${MINIZINC_HOME}/ortools \
&& ln -s ${ORTOOLS_HOME}/bin/fzn-ortools /usr/local/bin/fzn-ortools
# Test installation
RUN echo "var 1..9: x; constraint x > 5; solve satisfy;" \
| minizinc --solver com.google.or-tools --input-from-stdin
# ********************************************************
# Development environment
# ********************************************************
FROM dotnet-sdk as dev
ARG DEBIAN_FRONTEND=noninteractive
ARG MINIZINC_HOME
ARG ORTOOLS_HOME
# Install core packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg2 \
locales \
lsb-release \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install Docker CE CLI
RUN curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - 2>/dev/null \
&& echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y --no-install-recommends \
docker-ce-cli \
&& rm -rf /var/lib/apt/lists/*
# Install Docker Compose
RUN LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")') \
&& curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
# Install Github CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt update \
&& apt install gh -y \
&& rm -rf /var/lib/apt/lists/*
# Install Developer packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
autojump \
fonts-powerline \
openssh-client \
make \
micro \
less \
inotify-tools \
iputils-ping \
htop \
git \
tree \
zsh \
&& rm -rf /var/lib/apt/lists/*
# Install D2
RUN curl -fsSL https://d2lang.com/install.sh | sh -s --
# Install MiniZinc + ORTools from the build layer
COPY --from=minizinc-builder $MINIZINC_HOME $MINIZINC_HOME
COPY --from=minizinc-builder /usr/local/bin/ /usr/local/bin/
COPY --from=minizinc-builder $ORTOOLS_HOME $ORTOOLS_HOME
# Install ZSH
USER ${USER_NAME}
WORKDIR /home/${USER_NAME}
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
-p git \
-p docker \
-p autojump \
-p https://github.com/zsh-users/zsh-autosuggestions \
-p https://github.com/zsh-users/zsh-completions
COPY .devcontainer/.p10k.zsh .devcontainer/.zshrc /home/${USER_NAME}
# ------------------------------------
# test
# ------------------------------------
FROM dotnet-sdk as test
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBIAN_FRONTEND
ARG MINIZINC_HOME
ARG ORTOOLS_HOME
ARG USER_NAME
ARG USER_GID
ARG USER_UID
USER ${USER_NAME}
WORKDIR /app
# Install MiniZinc + ORTools
COPY --from=minizinc-builder $MINIZINC_HOME $MINIZINC_HOME
COPY --from=minizinc-builder /usr/local/bin/ /usr/local/bin/
COPY global.json Directory.Build.props ./
COPY --chown=$USER_UID src ./src
COPY --chown=$USER_UID test/libminizinc test/libminizinc
COPY --chown=$USER_UID test/ParserTests test/ParserTests
COPY --chown=$USER_UID test/ProcessTests test/ProcessTests
COPY --chown=$USER_UID test/TestUtils test/TestUtils
RUN dotnet new sln \
&& dotnet sln add src/**/*.csproj \
&& dotnet sln add test/**/*.csproj
CMD [ "dotnet","test" ]
# ------------------------------------
# Toolkit
# ------------------------------------
FROM mcr.microsoft.com/dotnet/nightly/sdk:8.0-jammy-aot as toolkit-builder
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBIAN_FRONTEND
WORKDIR /app
COPY global.json Directory.Build.props ./
COPY src ./src
RUN dotnet publish src/MiniZinc.Toolkit/MiniZinc.Toolkit.csproj -c Release -o build