-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
53 lines (41 loc) · 1.29 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
FROM rust:1.80-alpine3.20 as builder
# Install system dependencies
RUN apk add --no-cache \
libc-dev \
cmake \
make \
g++ \
pkgconfig \
openssl-dev \
protoc
# Configure cargo
RUN mkdir -p ~/.cargo && \
echo '[registries.crates-io]' > ~/.cargo/config && \
echo 'protocol = "sparse"' >> ~/.cargo/config
WORKDIR /app
# Copy only the files needed for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY redis-test-macro redis-test-macro/
# Create a dummy main.rs to build dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
# Build dependencies only
export RUSTFLAGS="-Ctarget-feature=-crt-static" && \
export PKG_CONFIG_ALLOW_CROSS=1 && \
cargo build --release && \
rm -rf src/
# Set environment variables for the final build
ENV RUSTFLAGS="-Ctarget-feature=-crt-static"
ENV PKG_CONFIG_ALLOW_CROSS=1
ARG UPTIME_CHECKER_GIT_REVISION
ENV UPTIME_CHECKER_GIT_REVISION=$UPTIME_CHECKER_GIT_REVISION
# Copy the actual source code and build
COPY . .
RUN cargo build --release
FROM alpine:3.20
COPY --from=builder /app/target/release/uptime-checker /usr/local/bin/uptime-checker
RUN apk add --no-cache tini libgcc && \
addgroup -S app && \
adduser -S app -G app
USER app
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/uptime-checker"]