-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
67 lines (50 loc) · 1.89 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
# Stage 1: Build stage
FROM node:22.7.0-alpine AS builder
# Set environment variables for UTF-8 support
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONIOENCODING=utf-8
# Install pnpm and other necessary tools
RUN apk add --no-cache python3 make g++ && \
npm install -g pnpm
# Set working directory
WORKDIR /app
# Copy package.json and pnpm-lock.yaml if they exist, otherwise create empty ones
COPY package.json* pnpm-lock.yaml* ./
RUN if [ ! -f package.json ]; then echo '{}' > package.json; fi
RUN if [ ! -f pnpm-lock.yaml ]; then touch pnpm-lock.yaml; fi
# Remove any existing node_modules and pnpm store prune
RUN rm -rf node_modules pnpm-lock.yaml && \
[ -d "/root/.local/share/pnpm/store" ] && pnpm store prune || echo "No pnpm store to prune"
# Install dependencies if package.json exists, forcing a fresh installation
RUN if [ -s package.json ]; then pnpm install --force; fi
# Copy the rest of the application code
COPY . .
# Create .env file from environment variables
RUN echo "DB_HOST=$DB_HOST" >> .env && \
echo "DB_PORT=$DB_PORT" >> .env && \
echo "DB_USER=$DB_USER" >> .env && \
echo "DB_PASSWORD=$DB_PASSWORD" >> .env && \
echo "DB_NAME=$DB_NAME" >> .env && \
echo "AUTH_SECRET=$AUTH_SECRET" >> .env
# Print installed packages and types before build
RUN pnpm list --depth 0
# RUN pnpm exec tsc --noEmit
# Build the application if there's a build script
RUN if grep -q '"build"' package.json; then pnpm build; fi
# Stage 2: Production stage
FROM node:22.7.0-alpine AS production
# Set environment variables for UTF-8 support
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONIOENCODING=utf-8
# Install pnpm
RUN npm install -g pnpm
# Set working directory
WORKDIR /app
# Copy the built application and .env file from the builder stage
COPY --from=builder /app /app
# Expose the port
EXPOSE 4321
# Start the application
CMD ["sh", "-c", "node /app/initTypesense.js && pnpm start"]