Update Dockerfile

Try with cargo
This commit is contained in:
LucifersCircle 2024-11-29 00:25:20 -08:00
parent 82917f9214
commit e91eb72be3

View file

@ -1,42 +1,32 @@
FROM alpine:3.19 FROM rust:1.71.0-alpine3.19
# Set build arguments # Set the target architecture as an ARG
ARG TARGET ARG TARGET
ARG BUILD_DIR=/build
# Install required dependencies # Install necessary dependencies for building (including git)
RUN apk add --no-cache \ RUN apk add --no-cache curl git build-base
curl \
git \
build-base \
cmake
# Clone the repository and checkout the main branch # Clone the repository into /redlib
RUN git clone https://github.com/LucifersCircle/redlib.git ${BUILD_DIR} && \ RUN git clone https://github.com/LucifersCircle/redlib.git /redlib
cd ${BUILD_DIR} && \
git checkout main
# Build the project # Set the working directory to the root of the cloned repository
WORKDIR ${BUILD_DIR} WORKDIR /redlib
# Run cmake to configure and make to build the project # Checkout the main branch (if needed)
RUN cmake -DCMAKE_BUILD_TYPE=Release -DTARGET=${TARGET} . && \ RUN git checkout main
make
# Move the compiled binary to /usr/local/bin # Build the project using Cargo (this will handle the Rust-specific build)
RUN mv ${BUILD_DIR}/target/${TARGET}/redlib /usr/local/bin/redlib RUN cargo build --release --target ${TARGET}
# Clean up build dependencies # Create a non-root user to run the application
RUN apk del build-base cmake && rm -rf ${BUILD_DIR}
# Add a non-root user for security
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 port 8080 # Expose the application port (if applicable)
EXPOSE 8080 EXPOSE 8080
# Healthcheck to ensure 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
CMD ["redlib"] # Default command to run the application
CMD ["./target/${TARGET}/release/redlib"]