Repository navigation
Expand file tree
/
Copy pathDockerfile.prod
More file actions
82 lines (59 loc) · 2.47 KB
/
Copy pathDockerfile.prod
File metadata and controls
82 lines (59 loc) · 2.47 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
# ---- Build Stage ----
FROM golang:1.22.6-alpine3.20 as builder
# Install necessary build dependencies
RUN apk update && apk add --no-cache \
git python3 py3-pip bash \
build-base linux-headers libcap-dev \
asciidoc gcc make pkgconfig eudev-dev sudo libcap
# Set the working directory
WORKDIR /app
# Clone isolate
RUN git clone https://github.com/ioi/isolate.git /isolate
# Modify isolate to work without systemd
RUN sed -i 's/#include <systemd\/sd-daemon.h>/\/\/#include <systemd\/sd-daemon.h>/' /isolate/isolate-cg-keeper.c && \
sed -i 's/sd_notify/\/\/sd_notify/' /isolate/isolate-cg-keeper.c
# Build and install isolate
WORKDIR /isolate
RUN make && make install
# Set up isolate
RUN addgroup -S isolate && adduser -S -G isolate isolate \
&& mkdir -p /var/local/lib/isolate \
&& chown -R isolate:isolate /var/local/lib/isolate \
&& chmod 777 /var/local/lib/isolate
# Set capabilities for isolate
RUN setcap cap_sys_admin,cap_sys_chroot,cap_mknod,cap_net_admin+ep /usr/local/bin/isolate
# Return to the app directory
WORKDIR /app
# Copy source code
COPY . .
RUN mkdir -p ./c_file/program \
&& gcc ./c_file/code/keyword_list.c -o ./c_file/program/keyword_list \
&& gcc ./c_file/code/kw_checker.c -o ./c_file/program/kw_checker
# Build the Go application
RUN go build -o main cmd/main.go
# ---- Runtime Stage ----
FROM alpine:3.20
# Install necessary runtime dependencies
RUN apk add --no-cache eudev libcap bash python3
# Copy isolate from the builder stage
COPY --from=builder /usr/local/bin/isolate /usr/local/bin/isolate
COPY --from=builder /usr/local/etc/isolate /usr/local/etc/isolate
COPY --from=builder /usr/local/bin/ /usr/local/bin/
COPY --from=builder /usr/local/sbin/isolate-cg-keeper /usr/local/sbin/isolate-cg-keeper
# Copy the python_files
COPY --from=builder /app/python_file /app/python_file
# Copy the built Go application
COPY --from=builder /app/main /app/main
COPY --from=builder /app/c_file/program/keyword_list /app/c_file/program/keyword_list
COPY --from=builder /app/c_file/program/kw_checker /app/c_file/program/kw_checker
# Set working directory
WORKDIR /app
# Set up isolate environment
RUN addgroup -S isolate && adduser -S -G isolate isolate \
&& mkdir -p /var/local/lib/isolate \
&& chown -R isolate:isolate /var/local/lib/isolate \
&& chmod 750 /var/local/lib/isolate
# Set capabilities for isolate
RUN setcap cap_sys_admin,cap_sys_chroot,cap_mknod,cap_net_admin+ep /usr/local/bin/isolate
# Run the application
CMD ["/app/main"]