Skip to content

✨ fix(docker): Update Dockerfile to copy files with correct ownership for enhanced security #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions server/app-authorization/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#################### DEVELOPMENT STAGE ####################
# Base image
FROM --platform=linux/amd64 node:20.13.1-alpine AS development

# Create app directory
Expand All @@ -8,22 +7,22 @@ WORKDIR /usr/src/app
# Create non-root user for better security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

# A wildcard is used to ensure both package.json AND package-lock.json are copied
# Copy all files and configs as root
COPY package*.json ./

# Install app dependencies
RUN npm i --ignore-scripts

# Bundle app source
COPY src ./src
COPY tsconfig*.json ./
COPY nest-cli.json ./
COPY package*.json ./
COPY eslint.config.mjs ./

# Creates a "dist" folder with the production build
# Install dependencies (still as root)
RUN npm install --ignore-scripts

# Build the app (still as root)
RUN npm run build

# Fix ownership of the entire app directory
RUN chown -R appuser:appgroup /usr/src/app

# Switch to non-root user
USER appuser

Expand All @@ -32,4 +31,3 @@ EXPOSE 3000

# Start the server using the production build
CMD ["npm", "run", "start"]