-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
58 lines (45 loc) · 1.58 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
# syntax=docker/dockerfile:1
# Fetch
FROM golang:1.23.4 AS fetch-stage
COPY ./frontend/ /frontend/
COPY ./internal/ /internal/
COPY ./blog_posts/ /blog_posts/
COPY ./backend/pre-render/ /backend/pre-render/
# Generate
FROM ghcr.io/a-h/templ:latest AS generate-stage
COPY --chown=65532:65532 --from=fetch-stage /frontend /frontend/
WORKDIR /frontend
RUN ["templ", "generate"]
# Build
FROM golang:1.23.4 AS build-stage
COPY --from=fetch-stage /internal /internal/
COPY --from=generate-stage /frontend /frontend/
WORKDIR /frontend
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -a .
COPY --from=fetch-stage /backend/pre-render /backend/pre-render/
WORKDIR /backend/pre-render
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -a .
# Static
FROM alpine:latest AS static-stage
COPY --from=build-stage /frontend/ /frontend/
COPY --from=build-stage /backend/pre-render/ /backend/pre-render/
COPY --from=fetch-stage /blog_posts/ /blog_posts/
WORKDIR /frontend
RUN apk add curl
RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/tailwindcss-linux-x64
RUN chmod +x tailwindcss-linux-x64
RUN mv tailwindcss-linux-x64 tailwindcss
RUN ./tailwindcss -c /frontend/tailwind.config.js -i /frontend/main.css -o /frontend/render/dist/tailwind.min.css --minify
WORKDIR /
RUN ./backend/pre-render/pre-render
RUN cp -r /blog_posts/published/ /frontend/render/posts/
RUN cp -r /blog_posts/rendered/ /frontend/render/posts/
# Deploy
FROM alpine:latest AS final
COPY --from=static-stage /frontend/ /frontend/
WORKDIR /frontend
ENTRYPOINT ["/frontend/frontend"]
EXPOSE 80
EXPOSE 443