-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
60 lines (46 loc) · 1.37 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
#----------------
# Build stage
#----------------
FROM rust:1.76-alpine AS builder
ARG RUSTFLAGS="-C target-feature=-crt-static"
ARG APP=/usr/app
ARG CRATE_NAME=bostil-bot
# System dependencies
RUN apk add --no-cache \
build-base cmake musl-dev pkgconfig openssl-dev \
libpq-dev \
curl git yt-dlp
WORKDIR ${APP}
# Build dependencies
# create a dummy source file to cache the dependencies
COPY Cargo.toml ./
COPY app/Cargo.toml ./app/
COPY core/Cargo.toml ./core/
RUN mkdir -p ./app/src && echo "fn main() {println!(\"if you see this, the build broke\")}" > ./app/src/main.rs
RUN mkdir -p ./core/src && echo "" > ./core/src/lib.rs
RUN cargo build --release
# Replace with real source code
RUN rm -f ./app/src/main.rs
COPY app ./app
COPY core ./core
# Break the Cargo cache
RUN touch ./app/src/main.rs
RUN touch ./core/src/lib.rs
# Build the project
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release
RUN strip target/release/${CRATE_NAME}
#----------------
# Runtime stage
#----------------
FROM alpine:3.19 AS runtime
ARG APP=/usr/app
ARG CRATE_NAME=bostil-bot
# System dependencies
RUN apk add --no-cache ca-certificates tzdata yt-dlp libpq
WORKDIR ${APP}
# Copy the binary from the builder stage
COPY --from=builder ${APP}/target/release/${CRATE_NAME} ./
# Run the application
CMD ["./bostil-bot"]