-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
188 lines (148 loc) · 3.83 KB
/
Dockerfile
File metadata and controls
188 lines (148 loc) · 3.83 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
180
181
182
183
184
185
186
187
188
# Multi-stage Dockerfile for cross-platform building
# Supports: Ubuntu, Debian, CentOS, Alpine
# Architectures: x86_64, arm64, armv7
# Base builder image
FROM ubuntu:22.04 AS base-builder
# Install common build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
pkg-config \
git \
wget \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Ubuntu/Debian builder
FROM base-builder AS ubuntu-builder
# Install Ubuntu-specific dependencies
RUN apt-get update && apt-get install -y \
libssl-dev \
libjsoncpp-dev \
&& rm -rf /var/lib/apt/lists/*
# Set build environment
ENV PLATFORM=linux
ENV DISTRO=ubuntu
ENV ARCH=x86_64
# Copy source code
WORKDIR /app
COPY . .
# Build the application
RUN mkdir -p build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
&& make -j$(nproc)
# Create package
RUN make package
# CentOS/RHEL builder
FROM base-builder AS centos-builder
# Install CentOS-specific dependencies
RUN yum update -y && yum install -y \
gcc-c++ \
cmake3 \
openssl-devel \
jsoncpp-devel \
pkgconfig \
&& yum clean all
# Set build environment
ENV PLATFORM=linux
ENV DISTRO=centos
ENV ARCH=x86_64
# Copy source code
WORKDIR /app
COPY . .
# Build the application
RUN mkdir -p build && cd build \
&& cmake3 .. -DCMAKE_BUILD_TYPE=Release \
&& make -j$(nproc)
# Create package
RUN make package
# Alpine Linux builder
FROM alpine:3.18 AS alpine-builder
# Install Alpine-specific dependencies
RUN apk add --no-cache \
build-base \
cmake \
pkgconfig \
openssl-dev \
jsoncpp-dev \
git
# Set build environment
ENV PLATFORM=linux
ENV DISTRO=alpine
ENV ARCH=x86_64
# Copy source code
WORKDIR /app
COPY . .
# Build the application
RUN mkdir -p build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
&& make -j$(nproc)
# Create package
RUN make package
# Multi-architecture builder using buildx
FROM --platform=$BUILDPLATFORM base-builder AS multiarch-builder
# Install cross-compilation tools
RUN apt-get update && apt-get install -y \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf \
&& rm -rf /var/lib/apt/lists/*
# Set build environment
ENV PLATFORM=linux
ENV DISTRO=multiarch
ENV TARGETPLATFORM=$TARGETPLATFORM
# Copy source code
WORKDIR /app
COPY . .
# Build for target architecture
RUN mkdir -p build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
&& make -j$(nproc)
# Runtime image (minimal)
FROM ubuntu:22.04 AS runtime
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
libssl3 \
libjsoncpp25 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -s /bin/false simple-utcd
# Copy binary from builder
COPY --from=ubuntu-builder /app/build/bin/simple-utcd /usr/local/bin/
COPY --from=ubuntu-builder /app/config/ /etc/simple-utcd/
# Set ownership
RUN chown -R simple-utcd:simple-utcd /etc/simple-utcd
# Expose UTC daemon port (typically 37 for time protocol)
EXPOSE 37/tcp
# Switch to non-root user
USER simple-utcd
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD nc -z localhost 37 || exit 1
# Default command
CMD ["simple-utcd", "--config", "/etc/simple-utcd/simple-utcd.conf"]
# Development image
FROM base-builder AS dev
# Install development tools
RUN apt-get update && apt-get install -y \
libssl-dev \
libjsoncpp-dev \
clang-format \
cppcheck \
valgrind \
gdb \
&& rm -rf /var/lib/apt/lists/*
# Install Python tools
RUN apt-get update && apt-get install -y \
python3-pip \
&& pip3 install bandit semgrep
# Set development environment
ENV PLATFORM=linux
ENV DISTRO=ubuntu
ENV ARCH=x86_64
# Copy source code
WORKDIR /app
COPY . .
# Default command for development
CMD ["/bin/bash"]