-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (57 loc) · 1.85 KB
/
Dockerfile
File metadata and controls
73 lines (57 loc) · 1.85 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
FROM rust:1.93-alpine AS builder
# Install system dependencies
RUN apk add --no-cache \
musl-dev \
pkgconfig \
openssl-dev \
openssl-libs-static \
postgresql-dev \
bash \
netcat-openbsd \
git
# Set environment variables
ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PQ_LIB_DIR=/usr/lib
ENV RUSTFLAGS="-C target-feature=-crt-static"
ARG BUILD_JOBS=4
ENV CARGO_BUILD_JOBS=${BUILD_JOBS}
WORKDIR /app
# Copy only Cargo files first for dependency caching
COPY rustytime/Cargo.toml rustytime/Cargo.lock ./rustytime/
# Create dummy source files to compile dependencies (for caching)
RUN mkdir -p rustytime/src && \
echo "fn main() {}" > rustytime/src/main.rs && \
echo "pub fn lib_main() {}" > rustytime/src/lib.rs
WORKDIR /app/rustytime
# Fetch and build dependencies (native compilation)
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/rustytime/target \
cargo fetch
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/rustytime/target \
cargo build --profile good --no-default-features
# Remove dummy source
RUN rm -rf src/
# Copy actual source code
COPY rustytime/src ./src
COPY rustytime/build.rs ./build.rs
COPY rustytime/migrations ./migrations
COPY .git ../.git
# Build with actual source and copy binary out of cache
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/rustytime/target \
touch src/main.rs && \
cargo build --profile good --no-default-features && \
mkdir -p /tmp/target && \
cp /app/rustytime/target/good/rustytime /tmp/target/rustytime
# Runtime stage
FROM alpine:latest
RUN apk add --no-cache \
libpq \
ca-certificates \
libgcc
COPY --from=builder /tmp/target/rustytime /usr/local/bin/rustytime
EXPOSE 3000
CMD ["rustytime"]