From 84069dd67664afe0b638f522877f772f2813b75b Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 21 Nov 2024 16:07:58 -0800 Subject: [PATCH] chore: update Dockerfile to install system dependencies, set up Rust and Dioxus CLI, and ensure directory ownership for node user --- Dockerfile | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 627a635..ff85e2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,42 @@ # syntax=docker/dockerfile:1 +ARG NODE_VERSION=23.0.0 +FROM node:${NODE_VERSION}-alpine -FROM duel80003/rust-dioxus:latest +# Install necessary system dependencies 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 --profile minimal --default-toolchain stable && \ + source $HOME/.cargo/env && \ + PATH="$HOME/.cargo/bin:$PATH" && \ + cargo install dioxus-cli --root /usr/local && \ + chmod +x /usr/local/bin/dx + +# Update PATH to include Cargo bin directory +ENV PATH="/root/.cargo/bin:/usr/local/bin:${PATH}" + +# Ensure all necessary directories are owned by `node` +RUN mkdir -p /root/.cargo /root/.rustup dist/assets/styles target && \ + chown -R node:node /root/.cargo /root/.rustup dist target /usr/src/app # Use production node environment by default ENV NODE_ENV=production -# Set the working directory WORKDIR /usr/src/app -# Copy package.json and install dependencies +# 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 -# Copy the rest of the application code -COPY . . +# Switch to non-root user for running the application +USER node + +# Copy the rest of the source files into the image +COPY --chown=node:node . . -# Expose the port for the application +# Expose the port that the application listens on EXPOSE 8080 # Run the application -CMD ["npm", "run", "serve"] \ No newline at end of file +CMD ["npm", "run", "serve"]