-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (38 loc) · 1.02 KB
/
Dockerfile
File metadata and controls
51 lines (38 loc) · 1.02 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
# --------------------------
# Stage 1: Builder
# --------------------------
FROM golang:alpine AS builder
RUN apk add --no-cache \
curl \
make \
git \
nodejs \
npm
RUN go install github.com/a-h/templ/cmd/templ@latest
ENV PATH="/go/bin:${PATH}"
WORKDIR /app
# Install JS deps first (better caching)
COPY package*.json ./
RUN npm install
# Copy everything else (Go + Makefiles + templates)
COPY . .
# Always use production env
ENV ENV_FILE=/app/.env.prod
# Build artifacts + env files
RUN make docker-build
# --------------------------
# Stage 2: Runtime
# --------------------------
FROM alpine:3.20 AS runtime
WORKDIR /app
# Copy only what we need from builder
COPY --from=builder /app/tmp/main /app/main
COPY --from=builder /app/static /app/static
COPY --from=builder /app/gen /app/gen
COPY --from=builder /app/.env.prod /app/.env.prod
RUN chmod +x /app/main
# Point Go app to the right env file
ENV ENV_FILE=/app/.env.prod
# Expose a port (Railway will override with $PORT)
EXPOSE 8080
CMD ["/app/main"]