From 67b9bdd5c62a8e78c3d3c17ec9c6abca38b8a96c Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 16 Nov 2024 20:25:22 -0800 Subject: [PATCH] chore: update Dockerfile to streamline Rust and Dioxus CLI installation, adjust PATH, and optimize dependency installation --- Dockerfile | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 79a9fc1..ef1f862 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,18 @@ ARG NODE_VERSION=23.0.0 FROM node:${NODE_VERSION}-alpine -# Install Rust, Dioxus CLI, and required dependencies (including make and Perl for building OpenSSL) -RUN apk add --no-cache curl gcc musl-dev perl make && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ - source $HOME/.cargo/env && \ +# Install system dependencies needed for Rust and Dioxus CLI +RUN apk add --no-cache curl gcc musl-dev perl make + +# Install Rust and Dioxus CLI as root +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ echo 'source $HOME/.cargo/env' >> /etc/profile && \ + source $HOME/.cargo/env && \ + PATH="$HOME/.cargo/bin:$PATH" && \ cargo install dioxus-cli && \ - chmod +x /root/.cargo/bin/dx # Ensure dx has execute permissions + chmod +x /root/.cargo/bin/dx -# Add Cargo to PATH for future commands +# Update PATH to include Cargo bin directory ENV PATH="/root/.cargo/bin:${PATH}" # Use production node environment by default @@ -19,19 +22,14 @@ ENV NODE_ENV=production WORKDIR /usr/src/app -# Copy package files into the image +# Copy package files into the image and install dependencies COPY package.json package-lock.json ./ +RUN npm ci --omit=dev && npm install concurrently tailwindcss --no-save -# Install all dependencies (omit dev dependencies for production) -RUN npm ci --omit=dev - -# Install specific devDependencies needed for `serve` script -RUN npm install concurrently tailwindcss --no-save - -# Create necessary directories with correct permissions +# Create necessary directories and set permissions RUN mkdir -p dist/assets/styles target && chown -R node:node dist target -# Run the application as a non-root user +# Switch to non-root user for running the application USER node # Copy the rest of the source files into the image