Skip to content

Commit

Permalink
Refactor docker file (#76)
Browse files Browse the repository at this point in the history
* Refactor docker file

* typo.
  • Loading branch information
Takaros999 authored Feb 4, 2025
1 parent 672d0d0 commit 11378e9
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
# Use a specific version of clux/muslrust
FROM --platform=linux/amd64 clux/muslrust:stable AS builder
# ---- Builder Stage ----
FROM --platform=linux/amd64 rust:1.81 AS builder

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

FROM --platform flag should not use a constant value

FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" More info: https://docs.docker.com/go/dockerfile/rule/from-platform-flag-const-disallowed/

# Install additional build dependencies required by aws-lc-sys
RUN apt-get update && \
apt-get install -y \
cmake \
pkg-config \
git \
build-essential \
ninja-build \
python3 \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

RUN ln -s /usr/bin/ar /usr/bin/musl-ar
ARG SQLX_OFFLINE
ENV SQLX_OFFLINE=${SQLX_OFFLINE}

WORKDIR /wld-usernames
# Copy the entire source code into the container
COPY . .

ENV AR=musl-ar
# Build the application in release mode
RUN cargo build --release --bin wld-usernames

ARG SQLX_OFFLINE
ENV SQLX_OFFLINE=${SQLX_OFFLINE}
# ---- Runtime Stage ----
FROM --platform=linux/amd64 debian:bookworm-slim AS runtime

Check warning on line 29 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker

FROM --platform flag should not use a constant value

FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" More info: https://docs.docker.com/go/dockerfile/rule/from-platform-flag-const-disallowed/

RUN cargo build --release --bin wld-usernames
# Install runtime dependencies (CA certificates and libssl3 for OpenSSL 3)
RUN apt-get update && \
apt-get install -y ca-certificates libssl3 && \
rm -rf /var/lib/apt/lists/*

# Set the working directory in the runtime container
WORKDIR /app

FROM --platform=linux/amd64 alpine AS runtime
WORKDIR /wld-usernames
COPY --from=builder /wld-usernames/target/x86_64-unknown-linux-musl/release/wld-usernames /usr/local/bin
# Copy the built binary from the builder stage
COPY --from=builder /app/target/release/wld-usernames /usr/local/bin/wld-usernames

# Expose the port your server listens on
EXPOSE 8000
ENTRYPOINT ["/usr/local/bin/wld-usernames"]

HEALTHCHECK --interval=5m \
CMD curl -f http://localhost:8000/ || exit 1
CMD curl -f http://localhost:8000/ || exit 1

0 comments on commit 11378e9

Please sign in to comment.