-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprod.Dockerfile
76 lines (55 loc) · 2.25 KB
/
prod.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
# Stage 1: Build the Go API server
FROM --platform=linux/arm64 golang:1.22.4-alpine AS go-builder
# add gcc
RUN apk add --no-cache gcc libc-dev sqlite-dev musl-dev
# Move to working directory (/build).
WORKDIR /build
# Copy and download dependency using go mod.
COPY backend/go.mod backend/go.sum ./
RUN go mod download
# Copy the backend code into the container.
COPY backend/ ./
# Set necessary environment variables needed for our image and build the API server.
ENV CGO_ENABLED=1 GOOS=linux GOARCH=arm64
RUN go build -tags musl --ldflags "-extldflags -static -s -w" -o main .
# Stage 2: Build the Next.js app
FROM node:20-alpine
# Move to working directory (/app).
WORKDIR /app
# Copy the Next.js app files
RUN mkdir frontend
COPY frontend/package*.json ./frontend/
RUN cd frontend && npm install
# Copy the rest of the frontend code
COPY frontend/ ./frontend
# Copy the backend code into the container.
COPY backend/ ./backend
# Build the Next.js app
RUN cd frontend && npm run build
# Install additional tools
RUN apk add --no-cache tzdata sqlite sqlite-dev ca-certificates bash gcc
# Copy the Go API binary
COPY --from=go-builder /build/main ./backend/main
# Install s6 overlay
ENV S6_OVERLAY_VERSION=3.2.0.0
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
# Download the correct s6 overlay based on the architecture
RUN ARCH=$(uname -m) && \
wget -O /tmp/s6-overlay-${ARCH}.tar.xz https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${ARCH}.tar.xz && \
tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz && \
tar -C / -Jxpf /tmp/s6-overlay-${ARCH}.tar.xz
# Expose the necessary ports
EXPOSE 8418 8417
# Create the /app/data directory
RUN mkdir /app/data
# Create service directories
RUN mkdir -p /etc/services.d/backend /etc/services.d/frontend
# Copy service scripts
COPY services/backend/run /etc/services.d/backend/run
COPY services/frontend/run /etc/services.d/frontend/run
# Copy frontend finish script
COPY services/frontend/finish /etc/services.d/frontend/finish
# Make the scripts executable
RUN chmod +x /etc/services.d/backend/run /etc/services.d/frontend/run /etc/services.d/frontend/finish
# Set s6 as the entrypoint
ENTRYPOINT ["/init"]