-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.aws
More file actions
70 lines (51 loc) · 1.77 KB
/
Dockerfile.aws
File metadata and controls
70 lines (51 loc) · 1.77 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
# syntax = docker/dockerfile:1
# Stage 1: Dependencies
# Use AL2023 base image for future integration with shiboleth sp
# See: https://github.com/CDLUC3/dmptool-shibboleth-sp
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS deps
RUN dnf -y install \
nodejs22
WORKDIR /app
# Set production environment
ENV CI=true
# Copy package.json and package-lock.json
# to the /app working directory
COPY package*.json ./
# Install dependencies in /app (excluding devDependencies)
RUN npm ci
#Stage 2: Builder
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS builder
RUN dnf -y install \
nodejs22
WORKDIR /app
# Set production environment
ENV CI=true
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the application
RUN npm run build
# Prune node_modules to only production-ready ones AFTER build
RUN npm ci --omit=dev \
&& npm cache clean --force \
# Verify jest/babel are gone before runner copies this
&& ls node_modules | grep -v "jest\|babel\|typescript\|eslint" > /dev/null \
# We don't need the package files now that the code is compiled and it just messes
# up the Trivy scans
&& rm package-lock.json && rm package.json
# Remove all unecessary test and mock files from the distribution
RUN rm -rf dist/__tests__ \
dist/__mocks__ \
dist/**/__tests__ \
dist/**/__mocks__
# Stage 3: Runner
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS runner
RUN rm -fr /var/cache/dnf/* && dnf clean all && dnf -y update && dnf -y install \
nodejs22 \
&& dnf clean all
WORKDIR /app
# Only copy the compiled code and the pruned node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
# Start the application
CMD ["node", "dist/index.js"]