tariffs/Dockerfile

64 lines
1.9 KiB
Docker
Raw Normal View History

2023-08-23 14:59:45 +00:00
FROM node:20.5.1-alpine3.17 as build
2022-12-16 00:36:33 +00:00
2023-08-23 14:59:45 +00:00
# Update packages and clear cache
2022-12-16 00:36:33 +00:00
RUN apk update && rm -rf /var/cache/apk/*
2023-08-23 14:59:45 +00:00
# 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
2022-12-16 00:36:33 +00:00
2023-08-23 14:59:45 +00:00
FROM node:20.5.1-alpine3.17 as test
2022-12-16 00:36:33 +00:00
2023-08-23 14:59:45 +00:00
# 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"]
2022-12-16 00:36:33 +00:00
2023-08-23 14:59:45 +00:00
FROM node:20.5.1-alpine3.17 as production
2022-12-16 00:36:33 +00:00
2023-08-23 14:59:45 +00:00
# Update packages and clear cache
2022-12-16 00:36:33 +00:00
RUN apk update && rm -rf /var/cache/apk/*
2023-08-23 14:59:45 +00:00
# Set production env
ENV NODE_ENV=production
# Set the working directory inside the container
2022-12-16 00:36:33 +00:00
WORKDIR /app
2023-08-23 14:59:45 +00:00
# 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
2022-12-16 00:36:33 +00:00
RUN chown -R node: .
2023-08-23 14:59:45 +00:00
# Install packages
2022-12-16 00:36:33 +00:00
RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean
2023-08-23 14:59:45 +00:00
# Set 'node' user as the active user within the container
USER node
# Run the Node.js application
CMD ["node", "./index.js"]