-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerfile
45 lines (42 loc) · 1.64 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
# generate tailwind css files
FROM node:22-alpine3.20 AS tailwindbuilder
LABEL stage=tailwindbuilder
WORKDIR /build
COPY package.json package-lock.json tailwind.config.js ./
RUN npm install
COPY controllers/web/components/*.templ ./controllers/web/components/
COPY controllers/web/static/index.css ./controllers/web/static/
RUN npx tailwindcss -i ./controllers/web/static/index.css -o ./static/output.css
# generate _templ.go files from .templ files
FROM golang:alpine AS templbuilder
LABEL stage=templbuilder
WORKDIR /build
RUN go install github.com/a-h/templ/cmd/[email protected]
COPY controllers/web/components/*.templ ./controllers/web/components/
RUN templ generate
# build standalone golang server binary
FROM golang:alpine AS gobuilder
LABEL stage=gobuilder
ENV CGO_ENABLED 0
WORKDIR /build
RUN apk update --no-cache && apk add --no-cache tzdata
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY cmd ./cmd
COPY controllers ./controllers
COPY --from=templbuilder /build/controllers/web/components/*_templ.go ./controllers/web/components/
RUN go build -ldflags="-s -w" -o /app/unotone ./cmd/server/main.go
RUN go build -ldflags="-s -w" -o /app/healthcheck ./cmd/healthcheck/main.go
RUN chmod +x /app/unotone
# runner image
FROM alpine
WORKDIR /app
ENV UNOTONE_STATIC_DIR /var/www/static
ENV PATH /app:$PATH
COPY --from=gobuilder /build/controllers/web/static ${UNOTONE_STATIC_DIR}
COPY --from=tailwindbuilder /build/static/output.css ${UNOTONE_STATIC_DIR}/output.css
COPY --from=gobuilder /app/unotone /app/unotone
COPY --from=gobuilder /app/healthcheck /app/healthcheck
HEALTHCHECK --start-period=1s --interval=1m --timeout=3s --retries=3 CMD ["healthcheck"]
CMD ["unotone"]