-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (59 loc) · 2.47 KB
/
Dockerfile
File metadata and controls
78 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
# this file generates a docker image to run the app in PRODUCTION - not related to the postgres SQLX docker!
# cargo-chef allows for incremental updates
FROM lukemathwalker/cargo-chef:latest-rust-1.80.1 AS chef
WORKDIR /app
RUN apt update && apt install lld clang -y
FROM chef AS planner
COPY . .
# Compute a lock-like file for our project
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build our project dependencies, not our application!
RUN cargo chef cook --release --recipe-path recipe.json
# Up to this point, if our dependency tree stays the same,
# all layers should be cached.
COPY . .
ENV SQLX_OFFLINE true
# Build our project
RUN cargo build --release --bin zero2prod
# # We use the latest Rust stable release as base image
# FROM rust:1.80.1 AS builder
# # Let's switch our working directory to `app` (equivalent to `cd app`)
# # The `app` folder will be created for us by Docker in case it does not
# # exist already.
# WORKDIR /app
# # Install the required system dependencies for our linking configuration
# RUN apt update && apt install lld clang -y
# # Copy all files from our working environment to our Docker image
# COPY . .
# # offline build - no access to sqlx database. this requires the queries to be pre-generated in .sqlx folder
# # via: cargo sqlx prepare (args...)
# ENV SQLX_OFFLINE=true
# # Let's build our binary!
# # We'll use the release profile to make it faaaast
# RUN cargo build --release
# # When `docker run` is executed, launch the binary!
# ENTRYPOINT ["./target/release/zero2prod"]
# call:
# docker build --tag zero2prod .
# to build the docker image
# Using '.' we are telling Docker to use the current directory as the build context for this image; COPY . app
# will therefore copy all files from the current directory (including our source code!) into the app directory of
# our Docker image.
# Runtime stage
FROM debian:bookworm-slim AS runtime
WORKDIR /app
# Install OpenSSL - it is dynamically linked by some of our dependencies
# Install ca-certificates - it is needed to verify TLS certificates
# when establishing HTTPS connections
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends openssl ca-certificates \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/zero2prod zero2prod
COPY configuration configuration
ENV APP_ENVIRONMENT=production
ENTRYPOINT ["./zero2prod"]