generated from WaifuSquad/Rust-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
48 lines (36 loc) · 1.15 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
FROM alpine:latest AS build
# Install software
RUN apk update && apk upgrade && apk add --no-cache curl musl-dev gcc
# Add to non-root user
RUN adduser -D -u 1000 rasopus
# Copy source code from host
RUN mkdir /app
WORKDIR /app
COPY ./src /app/src
COPY ./migrations /app/migrations
COPY ./Cargo.toml /app/Cargo.toml
COPY ./Cargo.lock /app/Cargo.lock
COPY ./rust-toolchain.toml /app/rust-toolchain.toml
RUN chown -R rasopus:rasopus /app
RUN chmod -R 755 /app
# Switch to non-root user
USER rasopus
# Install Rust toolchain for user
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/home/rasopus/.cargo/bin:${PATH}"
# Build the project
RUN cargo build --release
################################################################################
FROM alpine:latest AS runtime
# Install software
RUN apk update && apk upgrade
# Uninstall non-necessary software
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/* && rm /sbin/apk
# Create a non-root user
RUN adduser -D -u 1000 rasopus
USER rasopus
# Copy necessary files from the build container
WORKDIR /app
COPY --from=build /app/target/release/rasopus .
# Default command
CMD ["./rasopus"]