forked from ccported/ccported.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
64 lines (47 loc) · 1.42 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
# Build stage for static site
FROM node:20.16.0-slim AS builder
WORKDIR /build
# Install htmlc and other build dependencies
RUN npm install -g @sojs_coder/[email protected]
# Copy only package files first to leverage cache
COPY server/package.json ./server/
COPY static/roms/package*.json ./static/roms/
COPY package*.json ./
# Install dependencies
RUN cd server && npm install
RUN cd static/roms && npm install
RUN npm install
# Copy source files
COPY . .
# Build static site
RUN node generate_sitemap.js
RUN cd static/roms && node build.js
RUN htmlc static --out=build
RUN node modify_gitattr.js && \
cp .gitattributes build/.gitattributes
# Production stage
FROM node:20.16.0-slim
WORKDIR /usr/local/ccported
# Install nginx and clean up in one layer
RUN apt-get update && \
apt-get install -y nginx && \
rm -rf /var/lib/apt/lists/* && \
rm /etc/nginx/sites-enabled/default
# Copy nginx config
COPY server/nginx.conf /etc/nginx/sites-enabled/
# Copy built static files
COPY --from=builder /build/build /usr/share/nginx/html/
# Create IS_HOSTED.txt
RUN echo "===is_hosted===" > /usr/share/nginx/html/IS_HOSTED.txt
# Copy only the necessary server files
COPY server/package.json ./
RUN npm install --production
COPY server/client.js ./
COPY server/index.js ./
# Set environment variables
ENV node_env=production \
port=3000
# Expose ports
EXPOSE 80 3000
# Start nginx and node
CMD sh -c "service nginx start && node index.js"