64 lines
1.9 KiB
Docker
64 lines
1.9 KiB
Docker
FROM node:20.5.1-alpine3.17 as build
|
|
|
|
# Update packages and clear cache
|
|
RUN apk update && rm -rf /var/cache/apk/*
|
|
# Set the working directory inside the container
|
|
WORKDIR /app
|
|
# Add package metadata files
|
|
ADD yarn.lock package.json tsconfig.json ./
|
|
# Add src folder
|
|
ADD src ./src/
|
|
# Add tools
|
|
ADD tools ./tools/
|
|
# Add migrations
|
|
ADD migrations ./migrations
|
|
# Install packages
|
|
RUN yarn install --ignore-scripts --non-interactive && yarn cache clean
|
|
# Build app
|
|
RUN yarn build
|
|
|
|
|
|
|
|
FROM node:20.5.1-alpine3.17 as test
|
|
|
|
# Update packages and clear cache
|
|
RUN apk update && rm -rf /var/cache/apk/*
|
|
# Set production env
|
|
ENV NODE_ENV=production
|
|
# Set the working directory inside the container
|
|
WORKDIR /app
|
|
# Copy built files from build stage
|
|
COPY --from=build /app/dist /app/package.json /app/yarn.lock ./
|
|
# Copy migrate tool from build stage
|
|
COPY --from=build /app/tools/migrate /usr/local/bin/migrate
|
|
# Copy test migrations from build stage
|
|
COPY --from=build /app/migrations/test ./migrations
|
|
# Change ownership of files in the /app directory to the 'node' user
|
|
RUN chown -R node: .
|
|
# Install packages
|
|
RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean
|
|
# Set 'node' user as the active user within the container
|
|
USER node
|
|
# Run the Node.js application
|
|
CMD ["node", "./index.js"]
|
|
|
|
|
|
|
|
FROM node:20.5.1-alpine3.17 as production
|
|
|
|
# Update packages and clear cache
|
|
RUN apk update && rm -rf /var/cache/apk/*
|
|
# Set production env
|
|
ENV NODE_ENV=production
|
|
# Set the working directory inside the container
|
|
WORKDIR /app
|
|
# Copy built files from build stage
|
|
COPY --from=build /app/dist /app/package.json /app/yarn.lock ./
|
|
# Change ownership of files in the /app directory to the 'node' user
|
|
RUN chown -R node: .
|
|
# Install packages
|
|
RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean
|
|
# Set 'node' user as the active user within the container
|
|
USER node
|
|
# Run the Node.js application
|
|
CMD ["node", "./index.js"] |