Improve cacheability
All checks were successful
Build and Publish Docker Image / build_and_push (push) Successful in 42s

This commit is contained in:
2024-09-16 14:29:51 +00:00
parent 3a9fc1897a
commit 83ce2f6f57
3 changed files with 32 additions and 14 deletions

View File

@@ -1,22 +1,38 @@
FROM node:lts-alpine
################################################
FROM node:lts-alpine AS base
# Create user and group
RUN mkdir /app && \
addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /app
WORKDIR /app
################################################
FROM base AS build
# Create app directory and copy the app
WORKDIR /app
COPY . .
# Run as non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
RUN chown -R nodejs:nodejs /app
USER nodejs
COPY package*.json tsconfig.json ./
# Install
RUN npm install
# Copy the app
COPY src ./src
# Build
RUN npm run build
################################################
FROM node:lts-alpine
COPY --from=build /app/package*.json ./
COPY --from=build /app/dist ./dist
# Install dependencies but skip dev dependencies
RUN npm install --only=production
# Start the app
ENTRYPOINT ["npm", "run"]
CMD ["start"]
CMD ["start"]