-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
50 lines (38 loc) · 1.44 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
FROM rust:1.66-alpine3.16 as builder
WORKDIR /usr/src/myapp
# Needed for diesel
RUN apk add --no-cache postgresql-client libc-dev=0.7.2-r3
# Create the same scaffhold to build and cache dependecies
RUN cargo new --bin api && \
cargo new --lib application && \
cargo new --lib domain && \
cargo new --lib infrastructure && \
cargo new --lib shared
COPY ./Cargo.toml ./Cargo.toml
COPY ./api/Cargo.toml ./api/Cargo.toml
COPY ./application/Cargo.toml ./application/Cargo.toml
COPY ./domain/Cargo.toml ./domain/Cargo.toml
COPY ./infrastructure/Cargo.toml ./infrastructure/Cargo.toml
COPY ./shared/Cargo.toml ./shared/Cargo.toml
# Build regardles of any code changes just to cache deps
# This will only rebuild if any Cargo.toml file was changed
# but not if actualy code was changed
RUN cargo build --workspace --release
# Clean up
RUN cargo clean -p api && \
cargo clean -p application && \
cargo clean -p domain && \
cargo clean -p infrastructure && \
cargo clean -p shared
RUN rm -rf api application domain infrastructure shared
# RUN rm ./target/release/*.d ./target/release/*.rlib ./target/release/api
# Copy the actual code
COPY . .
# Build with precached dependencies
RUN cargo install --locked --path ./api
FROM alpine3.16 as runner
RUN apk add --no-cache postgresql-client
COPY --from=builder /usr/local/cargo/bin/api /usr/local/bin/api
RUN echo DATABASE_URL=postgres://cos:password@db/cos > .env
EXPOSE 8000
CMD ["api"]