-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
92 lines (68 loc) · 2.12 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
##################
### BASE STAGE ###
##################
FROM rust:1.58.1 as base
# Install build dependencies
RUN cargo install --locked cargo-make trunk strip_cargo_version
RUN rustup target add wasm32-unknown-unknown
WORKDIR /app
RUN mkdir frontend backend common
###########################
### STRIP-VERSION STAGE ###
###########################
FROM base AS strip-version
COPY Cargo.lock Cargo.toml ./
COPY frontend/Cargo.toml ./frontend/
COPY backend/Cargo.toml ./backend/
COPY common/Cargo.toml ./common/
RUN strip_cargo_version
###################
### BUILD STAGE ###
###################
FROM base AS build
RUN cargo init --lib frontend
RUN cargo init --bin backend
RUN cargo init --lib common
COPY --from=strip-version /app/frontend/Cargo.toml /app/frontend/
COPY --from=strip-version /app/backend/Cargo.toml /app/backend/
COPY --from=strip-version /app/common/Cargo.toml /app/common/
COPY --from=strip-version /app/Cargo.toml /app/Cargo.lock /app/
WORKDIR /app/backend
RUN cargo build --release
WORKDIR /app/frontend
RUN cargo build --release --target wasm32-unknown-unknown
WORKDIR /app
COPY . .
WORKDIR /app/backend
RUN cargo build --release
WORKDIR /app/frontend
RUN trunk build --release
########################
### PRODUCTION STAGE ###
########################
FROM debian:stable-slim
# Rocket web server configuration
ENV ROCKET_ADDRESS="0.0.0.0"
ENV ROCKET_PORT="8000"
# Default to always running database migrations
ENV RUN_MIGRATIONS="true"
# Basic default configuration for database, suitable for dev.
ENV DATABASE_URL="postgres://postgres@database/strecklistan"
# Enable cache-control
ENV ENABLE_STATIC_FILE_CACHE="true"
ENV STATIC_FILES_MAX_AGE="0"
# Install dependencies
RUN apt-get update \
&& apt-get install -y libpq5 openssl \
&& apt-get autoremove && apt-get autoclean
RUN mkdir -p /www
WORKDIR /
# Copy application binary
COPY --from=build /app/target/release/strecklistan_backend /usr/local/bin/strecklistan
# Copy static web files
COPY --from=build /app/frontend/dist /www
# Copy database migrations
COPY backend/migrations /migrations
# Copy html templates
COPY backend/templates /templates
CMD strecklistan