Improve cacheability
All checks were successful
Build and Publish Docker Image / build_and_push (push) Successful in 42s
All checks were successful
Build and Publish Docker Image / build_and_push (push) Successful in 42s
This commit is contained in:
38
Dockerfile
38
Dockerfile
@@ -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"]
|
||||
Reference in New Issue
Block a user