-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
81 lines (65 loc) · 2.27 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy only files needed for installation
COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Generate Prisma client and build
RUN npx prisma generate && \
npm run build && \
npm prune --production
# Production stage
FROM node:20-alpine
ARG VERSION="3.0.1"
# Add metadata
LABEL maintainer="José Valdiviesso <[email protected]>"
LABEL author="José Valdiviesso <[email protected]>"
LABEL version="${VERSION}"
LABEL description="MyFin API Server"
LABEL org.opencontainers.image.authors="José Valdiviesso <[email protected]>"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.title="MyFin API Server"
LABEL org.opencontainers.image.description="Rest API for the personal finances platform that'll help you budget, keep track of your income/spending and forecast your financial future."
LABEL org.opencontainers.image.source="https://github.com/afaneca/myfin-api"
WORKDIR /app
# Install necessary system dependencies
RUN apk --no-cache add curl openssl zlib libgcc musl
# Copy only the necessary files from builder
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules ./node_modules
COPY package*.json ./
# Create startup script
RUN echo '#!/bin/sh' > /app/start.sh && \
echo 'export DATABASE_URL="mysql://$DB_USER:$DB_PW@$DB_HOST:$DB_PORT/$DB_NAME"' >> /app/start.sh && \
echo 'npm run db:deploy && npx tsx dist/server.js' >> /app/start.sh && \
chmod +x /app/start.sh
# Set environment variables
ENV NODE_ENV=production \
# Database Configuration
DB_NAME="" \
DB_USER="" \
DB_PW="" \
DB_PORT="3306" \
DB_HOST="localhost" \
# Email Configuration
SMTP_HOST="" \
SMTP_PORT="465" \
SMTP_SECURE="true" \
SMTP_USER="" \
SMTP_PASSWORD="" \
SMTP_FROM="" \
# Application Configuration
PORT="3001" \
LOGGING="false" \
BYPASS_SESSION_CHECK="false" \
ENABLE_USER_SIGNUP="true"
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3001/ || exit 1
EXPOSE 3001
CMD ["/app/start.sh"]