-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (49 loc) · 1.62 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
# Fetch
FROM golang:latest AS fetch-stage
COPY go.mod go.sum /app/
WORKDIR /app
RUN go mod download
# Templ generate
FROM ghcr.io/a-h/templ:latest AS templ-stage
COPY --chown=65532:65532 . /templ
WORKDIR /templ
RUN ["templ", "generate"]
# Tailwind build
FROM node:alpine AS tailwind-stage
WORKDIR /tailwind
COPY package*.json /tailwind
RUN npm install
COPY --from=templ-stage /templ /tailwind
RUN npx tailwindcss -i ./input.css -o ./public/css/style.css --minify
# Go build
FROM --platform=$BUILDPLATFORM golang:alpine AS build-stage
ARG TARGETOS
ARG TARGETARCH
RUN apk add --no-cache --update go gcc g++
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
wget -P ~ https://musl.cc/aarch64-linux-musl-cross.tgz \
&& tar -xvzf ~/aarch64-linux-musl-cross.tgz -C /usr/local \
&& rm ~/aarch64-linux-musl-cross.tgz; \
fi
COPY --from=tailwind-stage /tailwind /app
WORKDIR /app
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
export CC=/usr/local/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc; \
fi && \
CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /app/main -buildvcs=false
# Go test
FROM build-stage AS test-stage
RUN go test -v ./...
# Deploy
FROM alpine:latest AS deploy-stage
WORKDIR /app
RUN addgroup --system --gid 5000 app && adduser --system --no-create-home --uid 5000 app --ingroup app
COPY --chown=app:app --from=build-stage /app/public /app/public
COPY --chown=app:app --from=build-stage /app/main /app/main
USER app
ENV CLONE_IN_MEMORY=true
EXPOSE 5000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10m \
CMD wget --no-verbose --tries=1 --spider http://localhost:5000/ || exit 1
RUN ls -al
CMD ["./main"]