-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
46 lines (34 loc) · 1.03 KB
/
Dockerfile
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
# Build stage
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci
# Copy and build application
COPY . .
RUN npm run build
# Final stage
FROM node:20-alpine
# Set working directory
WORKDIR /app
# Install global dependencies and clean up in one layer
RUN npm install -g aws-cdk && \
apk add --no-cache bash curl && \
rm -rf /tmp/* /var/cache/apk/*
# Copy built application from builder stage
COPY --from=builder /app .
# Copy the entrypoint script and make it executable
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create a non-root user and change ownership
RUN addgroup -S cdkuser && \
adduser -S cdkuser -G cdkuser && \
chown -R cdkuser:cdkuser /app
# Switch to the non-root user
USER cdkuser
# Add HEALTHCHECK instruction
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:3000/ || exit 1
# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]