-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile.liquid
53 lines (38 loc) · 1.28 KB
/
Dockerfile.liquid
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
# Stage 1: Build
FROM rust:1.85 as builder
# Install cross-compilation dependencies
RUN apt-get update && \
apt-get install -y musl-tools gcc-aarch64-linux-gnu && \
rustup target add aarch64-unknown-linux-musl
# Set the working directory
WORKDIR /usr/src/app
# Create .cargo/config.toml for cross-compilation
RUN mkdir -p .cargo
RUN echo '[target.aarch64-unknown-linux-musl]\nlinker = "aarch64-linux-gnu-gcc"' > .cargo/config.toml
# Copy the source code into the container
COPY . .
# Build the release version
RUN cargo build --target aarch64-unknown-linux-musl --release --all-features
# Stage 2: Runtime
FROM alpine:3.19
# Install minimal dependencies for a static binary
RUN apk --no-cache add ca-certificates
# Create a non-root user
RUN adduser -D appuser
# Set the working directory
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /usr/src/app/target/aarch64-unknown-linux-musl/release/{{project-name}} ./{{project-name}}
{% if static_assets_dir %}
# Copy static assets
COPY {{ static_assets_dir }} ./assets/
{% endif %}
# Set the ownership and permissions
RUN chown appuser:appuser ./{{project-name}} && \
chmod 755 ./{{project-name}}
# Switch to the non-root user
USER appuser
# Expose the port
EXPOSE 8080
# Start the application
CMD ["./{{project-name}}"]