-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
163 lines (141 loc) · 4.6 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
#
# 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:22.04 AS dependencies
RUN apt-get -qq update --fix-missing
# Install dependencies
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -qq -y --fix-missing \
cmake \
cmake-curses-gui \
cppcheck \
doxygen \
gcc \
gdb \
gfortran \
git \
g++ \
libhdf5-dev \
librdf0-dev \
librasqal3-dev \
libraptor2-dev \
make \
python3-dev \
python3-pip \
swig4.0 \
rpm \
librpmbuild9 \
dpkg \
&& rm -rf /var/lib/apt/lists/*
# Install Python packages
COPY requirements.txt .
COPY requirements_full.txt .
COPY requirements_dev.txt .
COPY requirements_doc.txt .
RUN pip3 install --trusted-host files.pythonhosted.org \
--upgrade pip \
-r requirements.txt \
-r requirements_full.txt \
-r requirements_dev.txt \
-r requirements_doc.txt
##########################################
# Stage: build
##########################################
FROM dependencies AS build
# Setup dlite
RUN mkdir -p /home/user/sw/dlite
COPY bindings /home/user/sw/dlite/bindings
COPY cmake /home/user/sw/dlite/cmake
COPY doc /home/user/sw/dlite/doc
COPY examples /home/user/sw/dlite/examples
COPY src /home/user/sw/dlite/src
COPY storages /home/user/sw/dlite/storages
COPY tools /home/user/sw/dlite/tools
COPY python/MANIFEST.in python/pyproject.toml python/setup.py /home/user/sw/dlite/python/
COPY 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 . \
-I src \
--language=c -q --force --error-exitcode=2 --inline-suppr -i build
# Build dlite
RUN mkdir build
WORKDIR /home/user/sw/dlite/build
RUN cmake .. -DFORCE_EXAMPLES=ON -DALLOW_WARNINGS=ON -DWITH_FORTRAN=ON \
-DWITH_DOC=ON -DCMAKE_INSTALL_PREFIX=/tmp/dlite-install
RUN make
# Create distributable packages
RUN cpack
RUN cpack -G DEB
RUN cpack -G RPM
# Install
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...
RUN ctest -E "(postgresql|ex4|dlite-validate|static-code-analysis)" || \
ctest -E "(postgresql|ex4|dlite-validate|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 ubuntu:22.04 AS production
#FROM python:3.9.6-slim-buster
RUN apt-get -qq update
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -qq -y --fix-missing librdf0 python3-dev python3-pip \
&& 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/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/
COPY requirements.txt .
COPY requirements_full.txt .
COPY requirements_dev.txt .
RUN pip install \
--trusted-host files.pythonhosted.org \
--upgrade pip \
-r requirements.txt \
-r requirements_full.txt \
-r requirements_dev.txt
WORKDIR /home/user
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV DLITE_ROOT=/usr/local
ENV PYTHONPATH=/usr/local/lib/python3.9/site-packages
# Default command
CMD ["/bin/bash"]