-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
50 lines (37 loc) · 1.19 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
# Use Ubuntu 22.04 as the base image for both build and runtime
FROM ubuntu:22.04 as builder
# Install build dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
build-essential \
protobuf-compiler \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Set the working directory
WORKDIR /app
# Copy the entire project structure
COPY . .
# Build the project
RUN cd server && cargo build --release
# Use the same Ubuntu 22.04 as the final image
FROM ubuntu:22.04
# Install runtime dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
libssl3 \
ca-certificates \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN useradd -ms /bin/bash appuser
# Copy the binary from the builder
COPY --from=builder /app/server/target/release/server /usr/local/bin/server
# Set ownership and permissions
RUN chown appuser:appuser /usr/local/bin/server
USER appuser
# Expose the port the server will run on
EXPOSE 3000 8080
# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/server"]