-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
80 lines (61 loc) · 2.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
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
# Multi-stage build for tournois-tt project
# API build stage
FROM golang:1.23-alpine AS api-build
WORKDIR /go/src/tournois-tt/api
COPY api/go.mod api/go.sum ./
RUN go mod download
COPY api ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/api ./cmd/main.go
# Frontend build stage
FROM node:20.18.1-alpine AS frontend-build
WORKDIR /app/frontend
# Install global dependencies
RUN npm install -g npm@latest
# Copy package files first for better caching
COPY frontend/package*.json ./
# Install dependencies with verbose output
RUN npm ci --verbose \
|| (echo "npm ci failed, trying npm install" && npm install --verbose)
# Copy the rest of the frontend files
COPY frontend ./
# Ensure node_modules is populated
RUN npm ls || true
# Build the frontend with production config
RUN npm run build \
&& echo "Build completed successfully" \
&& echo "Contents of build directory:" \
&& ls -la build \
&& echo "Contents of index.html:" \
&& cat build/index.html \
|| (echo "Build failed. Showing npm logs:" && cat /root/.npm/_logs/$(ls -t /root/.npm/_logs/ | head -n1) && exit 1)
# Production stage
FROM alpine:latest
WORKDIR /app
# Install necessary packages
RUN apk add --no-cache nginx nodejs npm
# Create /app/api directory
RUN mkdir -p /app/api
# Create necessary directories
RUN mkdir -p /app/api/cache
# Copy built frontend
COPY --from=frontend-build /app/frontend/build /usr/share/nginx/html
# Verify the contents of the build directory
RUN echo "Contents of /usr/share/nginx/html:" \
&& ls -la /usr/share/nginx/html \
&& echo "Contents of index.html:" \
&& cat /usr/share/nginx/html/index.html
# Copy built API binary
COPY --from=api-build /go/bin/api /app/api
# Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy necessary configuration files and cache
COPY api/.env.example /app/api/.env
COPY api/air.toml /app/api/air.toml
COPY api/cache/geocoding_cache.json /app/api/cache/
# Create entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Expose ports
EXPOSE 80
# Use the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]