-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
50 lines (38 loc) · 1.08 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
47
48
49
50
# Stage 1: Build
FROM node:22-alpine AS builder
# Install necessary packages
RUN apk add --no-cache python3 make g++
WORKDIR /usr/src/app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci --only=production
# Copy source files and build the project
COPY . .
RUN npm rebuild bcrypt --build-from-source
RUN npm install -g typescript
RUN npm run build
# Stage 2: Final image
FROM node:22-alpine
# Set up timezone
ARG TZ=GMT
ENV TZ=${TZ}
RUN apk --no-cache add tzdata \
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone
# Create app directory and set permissions
WORKDIR /usr/src/app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
COPY --from=builder /usr/src/app /usr/src/app
RUN chown -R appuser:appgroup /usr/src/app
# Install cron
RUN apk add --no-cache cron
# Add and configure cron jobs
COPY ./cron-jobs /etc/cron.d/cron-jobs
RUN chmod 0644 /etc/cron.d/cron-jobs \
&& crontab /etc/cron.d/cron-jobs
# Expose port
EXPOSE 3001
# Use non-root user
USER appuser
# Start cron and the app
CMD ["sh", "-c", "crond && npm start"]