-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (42 loc) · 1.68 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (42 loc) · 1.68 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
# Stage 1: Build
FROM debian:bookworm AS builder
ARG CONFIG=config/AllDocker.cmake
ARG HAS_GUI_APPS=true
ARG HAS_BOOST_APPS=true
ARG HAS_CODE_GENERATORS=true
# Install dependencies
RUN apt update && apt install -y cmake g++ git
RUN if [ "${HAS_GUI_APPS}" = "true" ]; then apt install -y make qtbase5-dev libqt5serialport5-dev; fi
RUN if [ "${HAS_BOOST_APPS}" = "true" ]; then apt install -y libssl-dev libboost-all-dev; fi
RUN if [ "${HAS_CODE_GENERATORS}" = "true" ]; then apt install -y libxml2-dev; fi
# Set working directory
WORKDIR /cc
# Copy source code
COPY . .
WORKDIR /cc/build
# Build the target
RUN cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DCMAKE_PROJECT_INCLUDE=${CONFIG}
RUN cmake --build /cc/build --parallel $(nproc)
RUN rm -rf /cc/build/install/include /cc/build/install/bin/*.sh /cc/build/install/lib/*.a
# Stage 2: Runtime
FROM debian:bookworm
ARG USERNAME=cc
ARG UID=1000
ARG HAS_GUI_APPS=true
ARG HAS_BOOST_APPS=true
ARG HAS_CODE_GENERATORS=true
# Install packages
RUN apt update
RUN if [ "${HAS_GUI_APPS}" = "true" ]; then apt install -y libqt5gui5 libqt5widgets5 libqt5serialport5 qt5dxcb-plugin; fi
RUN if [ "${HAS_BOOST_APPS}" = "true" ]; then apt install -y libssl3 libboost-program-options1.74.0 libboost-system1.74.0; fi
RUN if [ "${HAS_CODE_GENERATORS}" = "true" ]; then apt install -y libxml2; fi
# Copy compiled binary from builder stage
COPY --from=builder /cc/build/install /cc
COPY --from=builder /cc/docker/cc.sh /
ENV LD_LIBRARY_PATH=/cc/lib
ENV USERNAME=${USERNAME}
ENV UID=${UID}
RUN if [ "${USERNAME}" != "root" ]; then useradd -m -s /bin/bash -u ${UID} ${USERNAME}; fi
USER ${USERNAME}
ENTRYPOINT ["/cc.sh"]
WORKDIR /home/${USERNAME}