-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
52 lines (38 loc) · 1.69 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
# Start from the official Rust image
FROM rust:latest as builder
# Install musl-tools
RUN apt-get update && apt-get install -y musl-tools && rm -rf /var/lib/apt/lists/*
# Target the musl architecture for a fully static binary
RUN rustup target add x86_64-unknown-linux-musl
# Set the working directory
WORKDIR /usr/src/app
# Add labels for OCI annotations
LABEL org.opencontainers.image.source="https://github.com/storopoli/stoic-quotes" \
org.opencontainers.image.description="Stoic Quotes" \
org.opencontainers.image.licenses="MIT"
# Copy project's Cargo.toml file
COPY ./Cargo.toml ./
# This dummy build is to cache dependencies so they don't need to be rebuilt
# every time your source changes
RUN mkdir src/ && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release --target x86_64-unknown-linux-musl && \
rm -f target/x86_64-unknown-linux-musl/release/deps/stoic*
# Copy project's source code and other relevant folders to the Docker image
COPY ./src ./src
COPY ./assets ./assets
COPY ./data ./data
COPY ./templates ./templates
# Build application for release target musl
RUN cargo build --release --target x86_64-unknown-linux-musl
# Start a new stage from a slim version of Debian to reduce the size of the final image
FROM debian:buster-slim
WORKDIR /usr/src/app
# Copy the binary from the builder stage to the new stage
COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/stoic-quotes /usr/local/bin/stoic-quotes
# Copy the assets/ from the builder stage to the new stage
COPY --from=builder /usr/src/app/assets /usr/src/app/assets
# Expose port 3000
EXPOSE 3000
# Command to run the binary
CMD ["stoic-quotes"]