forked from SINTEF/dlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
179 lines (153 loc) · 4.92 KB
/
Copy pathDockerfile
File metadata and controls
179 lines (153 loc) · 4.92 KB
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
#
# Build this docker with
#
# docker build -t dlite .
#
# To run this docker in an interactive bash shell, do
#
# docker run -i -t dlite
#
# A more realistic way to use this docker is to put the following
# into a shell script (called dlite)
#
# #!/bin/sh
# docker run --rm -it --user="$(id -u):$(id -g)" --net=none \
# -v "$PWD":/data dlite "$@"
#
# To run the getuuid tool inside the docker image, you could then do
#
# dlite dlite-getuuid <string>
#
# To run a python script in current directory inside the docker image
#
# dlite python /data/script.py
#
##########################################
# Stage: install dependencies
##########################################
FROM ubuntu:20.04 AS dependencies
RUN apt-get -qq update --fix-missing
# Default cmake is 3.10.2. We need at least 3.11...
# Install tools for adding cmake
RUN apt-get install -qq -y \
apt-transport-https \
ca-certificates \
gnupg \
software-properties-common \
wget
# Obtain signing key
RUN wget -O - \
https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
apt-key add -
# Add Kitware repo
RUN apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal bionic main'
RUN apt update
# Ensure that our keyring stays up to date
RUN apt-get install kitware-archive-keyring
# Install dependencies
RUN apt-get install -qq -y --fix-missing \
cmake \
cmake-curses-gui \
cppcheck \
doxygen \
gcc \
gdb \
gfortran \
git \
g++ \
libhdf5-dev \
libjansson-dev \
librdf0-dev \
librasqal3-dev \
libraptor2-dev \
make \
python3-dev \
python3-pip \
swig4.0 \
rpm \
librpmbuild8 \
dpkg \
&& rm -rf /var/lib/apt/lists/*
# Install Python packages
COPY requirements.txt .
RUN pip3 install --trusted-host files.pythonhosted.org \
--upgrade pip -r requirements.txt
##########################################
# Stage: build
##########################################
FROM dependencies AS build
# Create and become a normal user
RUN useradd -ms /bin/bash user
USER user
# Setup dlite
RUN mkdir -p /home/user/sw/dlite
COPY --chown=user:user bindings /home/user/sw/dlite/bindings
COPY --chown=user:user cmake /home/user/sw/dlite/cmake
COPY --chown=user:user doc /home/user/sw/dlite/doc
COPY --chown=user:user examples /home/user/sw/dlite/examples
COPY --chown=user:user src /home/user/sw/dlite/src
COPY --chown=user:user storages /home/user/sw/dlite/storages
COPY --chown=user:user tools /home/user/sw/dlite/tools
COPY --chown=user:user CMakeLists.txt LICENSE README.md /home/user/sw/dlite/
WORKDIR /home/user/sw/dlite
# Perform static code checking
# FIXME - test_tgen.c produce a lot of false positives
RUN cppcheck . \
--language=c -q --force --error-exitcode=2 --inline-suppr -i build \
-i src/utils/tests/test_tgen.c
# Build dlite
RUN mkdir build
WORKDIR /home/user/sw/dlite/build
RUN cmake .. -DFORCE_EXAMPLES=ON -DALLOW_WARNINGS=ON -DWITH_FORTRAN=ON \
-DCMAKE_INSTALL_PREFIX=/tmp/dlite-install
RUN make
# Create distributable packages
RUN cpack
RUN cpack -G DEB
RUN cpack -G RPM
# Install
USER root
RUN make install
# Skip postgresql tests since we haven't set up the server and
# static-code-analysis since it is already done.
# TODO - set up postgresql server and run the postgresql tests...
USER user
RUN ctest -E "(postgresql|static-code-analysis)" || \
ctest -E "(postgresql|static-code-analysis)" \
--rerun-failed --output-on-failure -VV
# Set DLITE_USE_BUILD_ROOT in case we want to test dlite from the build dir
ENV DLITE_USE_BUILD_ROOT=YES
#########################################
# Stage: develop
#########################################
FROM build AS develop
ENV PATH=/tmp/dlite-install/bin:$PATH
ENV LD_LIBRARY_PATH=/tmp/dlite-install/lib:$LD_LIBRARY_PATH
ENV DLITE_ROOT=/tmp/dlite-install
ENV PYTHONPATH=/tmp/dlite-install/lib/python3.8/site-packages:$PYTHONPATH
##########################################
# Stage: final slim image
##########################################
FROM python:3.8.3-slim-buster AS production
RUN apt -qq update \
&& apt install -y -qq --fix-missing librdf0 \
&& rm -rf /var/lib/apt/lists/*
# Copy needed dlite files and libraries to slim image
COPY --from=build /tmp/dlite-install /usr/local
COPY --from=build /usr/lib/x86_64-linux-gnu/libjansson.so* /usr/local/lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libhdf5*.so* /usr/local/lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libsz.so* /usr/local/lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libaec.so* /usr/local/lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libm.so* /usr/local/lib/
RUN pip install --upgrade pip \
--trusted-host files.pythonhosted.org \
numpy \
PyYAML \
psycopg2-binary
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV DLITE_ROOT=/usr/local
# Default command
CMD ["/bin/bash"]