Update Dockerfile

try fix build from source
This commit is contained in:
LucifersCircle 2024-11-29 01:10:45 -08:00
parent 2b3a81a18a
commit ca5e5e0772

View file

@ -1,37 +1,35 @@
# Use the official Rust image with Alpine base FROM rust:1.71.0-alpine3.19
FROM rust:alpine
# Set the target architecture as an ARG # Set the target architecture as an ARG (default to x86_64)
ARG TARGET ARG TARGET=x86_64-unknown-linux-musl
# Install necessary dependencies for building (including git) # Install dependencies (curl, make, cmake, etc.)
RUN apk add --no-cache curl git build-base RUN apk add --no-cache curl cmake make
# Clone the repository into /redlib # Create the working directory for the build process
RUN git clone https://github.com/LucifersCircle/redlib.git /redlib WORKDIR /build
# Set the working directory to the root of the cloned repository # Clone the redlib repository
WORKDIR /redlib RUN git clone https://github.com/LucifersCircle/redlib.git /build
# Checkout the main branch (if needed) # Checkout the main branch
RUN git checkout main RUN cd /build && git checkout main
# Install the desired version of Rust (if a specific version is needed) # Build the redlib binary using cargo
RUN rustup install stable RUN cd /build && cargo build --release --target ${TARGET}
RUN rustup default stable
# Build the project using Cargo (this will handle the Rust-specific build) # Copy the binary to the appropriate location
RUN cargo build --release --target ${TARGET} RUN cp /build/target/${TARGET}/release/redlib /usr/local/bin/redlib
# Create a non-root user to run the application # Set up a non-privileged user to run the binary
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
USER redlib USER redlib
# Expose the application port (if applicable) # Expose port 8080
EXPOSE 8080 EXPOSE 8080
# Run a healthcheck every minute to make sure redlib is functional # Run a healthcheck every minute to make sure redlib is functional
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1 HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1
# Default command to run the application # Command to run the binary
CMD ["./target/${TARGET}/release/redlib"] CMD ["redlib"]