This repository was archived by the owner on Mar 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (56 loc) · 2.58 KB
/
Dockerfile
File metadata and controls
73 lines (56 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# syntax=docker/dockerfile:1
###############################################################################
# IMAGE: nerdware/fixit-api
#
# This Dockerfile is used to create a production image for the Fixit API AWS
# ECS Service. The image is built in two stages:
# 1. builder: creates the dist/ build artifact for "prod" build stage
# 2. prod: creates the final "prod" image for ECS tasks
#
# After being uploaded to the AWS ECR image repo by the relevant GitHub Action,
# the image is scanned for conformance with relevant CIS benchmarks and other
# security standards. Once all checks pass, the image is deployed to AWS ECS.
###############################################################################
# STAGE: builder
# Source image: NodeJS v20 (https://hub.docker.com/_/node)
FROM node:20 as builder
# Explicitly set workdir
WORKDIR /home/node/app
# Copy over files needed to create the dist build
COPY package*.json tsconfig*.json? npm-shrinkwrap.json? .swcrc ./
# Install all dependencies (dev deps are needed to create the dist build)
RUN npm ci --include=dev
# Copy over src files (this is done after `npm ci` to take advantage of caching)
COPY src src/
# Create dist/ for "prod" stage and remove dev dependencies
RUN npm run build && npm prune --production
#------------------------------------------------------------------------------
# STAGE: prod
# This build stage creates the final "prod" image for ECS tasks
FROM node:20-slim as prod
# Expose desired port
EXPOSE 80
# Explicitly set workdir
WORKDIR /home/node/app
# Add Tini for improved Node process handling https://github.com/krallin/tini
ENV TINI_VERSION=v0.19.0
RUN apt-get update \
&& apt-get install -y ca-certificates curl --no-install-recommends \
&& curl -L https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini -o /tini \
&& chmod +x /tini \
&& echo "Tini downloaded successfully" \
&& apt-get purge -y ca-certificates curl \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/tini", "--"]
# Copy over the package.json
COPY --from=builder /home/node/app/package.json ./
# Copy over only the dist files needed in production
COPY --from=builder /home/node/app/dist ./dist/
# # Copy over only the pruned node_modules from builder stage
COPY --from=builder /home/node/app/node_modules ./node_modules/
# Set non-root user (this step must be after tini-setup)
USER node
# Run the API directly with node executable
CMD ["node", "dist/index.js"]
###############################################################################