forked from Squads-Protocol/public-v4-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (52 loc) · 1.97 KB
/
Dockerfile
File metadata and controls
68 lines (52 loc) · 1.97 KB
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
# Use a minimal base image
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Enable Yarn (since corepack is built-in with Node.js 20)
RUN corepack enable && corepack prepare yarn@1.22.22 --activate
# Ensure consistent timestamps for deterministic builds
ENV NODE_ENV=production
ENV SOURCE_DATE_EPOCH=315532800
# Copy dependencies first (for better caching)
COPY package.json yarn.lock ./
# Install dependencies in a reproducible way
RUN yarn install --frozen-lockfile --non-interactive --check-files --ignore-scripts
# Copy the full source code after dependencies are cached
COPY . .
# Build the application using Webpack
RUN yarn build
# Ensure consistent timestamps for all files in dist/
RUN find dist -exec touch -d @${SOURCE_DATE_EPOCH} {} + && \
find dist -exec chmod 644 {} +
# Prepare final output structure
RUN mkdir -p /squads-public-build/dist && \
mv dist/* /squads-public-build/dist && \
cd /squads-public-build/dist && \
find . -type f -print0 | sort -z | xargs -0 cat | sha256sum | awk '{ print $1 }' > /squads-public-build/hash.txt
# Set proper permissions
RUN chmod -R u+rwX,go+rX /squads-public-build/dist && \
chmod u+rw,go+r /squads-public-build/hash.txt
# Copy the build output to a standard location
RUN mkdir -p /output && cp -r /squads-public-build/* /output/
# Use a lightweight web server for serving static files
FROM nginx:alpine AS server
# Copy built files and hash into the nginx root directory
COPY --from=builder /output/dist /usr/share/nginx/html
COPY --from=builder /output/hash.txt /var/build-metadata/hash.txt
# Ensure Nginx serves the correct index.html
RUN rm /etc/nginx/conf.d/default.conf
COPY <<EOF /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files \$uri /index.html;
}
}
EOF
# Expose port 80 for serving the static site
EXPOSE 80
# Default command to run nginx
CMD ["nginx", "-g", "daemon off;"]