forked from sqlpage/SQLPage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
58 lines (55 loc) · 2.23 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
FROM --platform=$BUILDPLATFORM rust:1.80-slim AS builder
WORKDIR /usr/src/sqlpage
ARG TARGETARCH
ARG BUILDARCH
RUN apt-get update && \
if [ "$TARGETARCH" = "$BUILDARCH" ]; then \
rustup target list --installed > TARGET && \
echo gcc > LINKER && \
apt-get install -y gcc libgcc-s1 && \
cp /lib/*/libgcc_s.so.1 .; \
elif [ "$TARGETARCH" = "arm64" ]; then \
echo aarch64-unknown-linux-gnu > TARGET && \
echo aarch64-linux-gnu-gcc > LINKER && \
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross && \
cp /usr/aarch64-linux-gnu/lib/libgcc_s.so.1 .; \
elif [ "$TARGETARCH" = "arm" ]; then \
echo armv7-unknown-linux-gnueabihf > TARGET && \
echo arm-linux-gnueabihf-gcc > LINKER && \
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross && \
cp /usr/arm-linux-gnueabihf/lib/libgcc_s.so.1 .; \
else \
echo "Unsupported cross compilation target: $TARGETARCH"; \
exit 1; \
fi && \
rustup target add $(cat TARGET) && \
cargo init .
# Build dependencies (creates a layer that avoids recompiling dependencies on every build)
COPY Cargo.toml Cargo.lock ./
RUN cargo build \
--target $(cat TARGET) \
--config target.$(cat TARGET).linker='"'$(cat LINKER)'"' \
--profile superoptimized
# Build the project
COPY . .
RUN touch src/main.rs && \
cargo build \
--target $(cat TARGET) \
--config target.$(cat TARGET).linker='"'$(cat LINKER)'"' \
--profile superoptimized && \
mv target/$(cat TARGET)/superoptimized/sqlpage sqlpage.bin
FROM busybox:glibc
RUN addgroup --gid 1000 --system sqlpage && \
adduser --uid 1000 --system --no-create-home --ingroup sqlpage sqlpage && \
mkdir -p /etc/sqlpage && \
touch /etc/sqlpage/sqlpage.db && \
chown -R sqlpage:sqlpage /etc/sqlpage/sqlpage.db
ENV SQLPAGE_WEB_ROOT=/var/www
ENV SQLPAGE_CONFIGURATION_DIRECTORY=/etc/sqlpage
WORKDIR /var/www
COPY --from=builder /usr/src/sqlpage/sqlpage.bin /usr/local/bin/sqlpage
COPY --from=builder /usr/src/sqlpage/libgcc_s.so.1 /lib/libgcc_s.so.1
USER sqlpage
COPY --from=builder --chown=sqlpage:sqlpage /usr/src/sqlpage/sqlpage/sqlpage.db sqlpage/sqlpage.db
EXPOSE 8080
CMD ["/usr/local/bin/sqlpage"]