-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
78 lines (61 loc) · 2.04 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
# Start with a base Debian image
FROM ubuntu:22.04 AS base
# Add arguments that can be used when creating the docker container
ARG USER_ID=1000
ARG GROUP_ID=1000
# Install necessary tools and libraries including Qt5 and CMake
RUN apt-get update; \
apt-get upgrade -y; \
apt-get install -y \
build-essential \
cmake \
vim \
&& rm -rf /var/lib/apt/lists/*
RUN \
apt-get update; \
apt-get -y install --fix-missing \
qtbase5-dev \
qtdeclarative5-dev \
libqt5serialport5-dev \
qml-module-qtquick-layouts \
qml-module-qtquick-controls \
qtquickcontrols2-5-dev \
qml-module-qtgraphicaleffects \
qml-module-qttest
# Adding the user an creating a directory for him
RUN addgroup --gid $GROUP_ID dockergroup \
&& adduser \
--home /home/dockeruser \
--uid $USER_ID \
--ingroup dockergroup \
dockeruser
RUN mkdir /app && chown dockeruser:dockergroup /app
#Switch container user
USER dockeruser
# Copy the source code and CMakeLists.txt into the Docker
# container with user rights adapted
COPY --chown=dockeruser:dockergroup . /app
#Switch working directory
WORKDIR /app
# Navigate into the build directory, run CMake, and compile the application
RUN cmake -B ./build -S ./src && cmake --build build
# Start the second stage
#############################################################################
FROM ubuntu:22.04 AS runtime
# Copy necessary libraries and binaries from the build stage
COPY --from=base /usr/lib /usr/lib
COPY --from=base /usr/share /usr/share
# In the runtime stage:
COPY --from=base /etc/fonts/ /etc/fonts/
COPY --from=base /var/cache/fontconfig/ /var/cache/fontconfig/
# Copy over the user and group information
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --from=base /etc/shadow /etc/shadow
# Copy the compiled application from the build stage
COPY --from=base --chown=dockeruser:dockergroup /app/build/MyQtApp /app/MyQtApp
# Set the user and working directory
USER dockeruser
WORKDIR /app
# Set the entrypoint for the application
ENTRYPOINT ["/app/MyQtApp"]