-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
57 lines (37 loc) · 1.72 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
# syntax=docker/dockerfile:1
# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0
# https://docs.docker.com/engine/reference/builder/
### healthcheck builder ###
# https://hub.docker.com/_/golang/
FROM golang:1.23.2-alpine3.20 AS healthcheck
WORKDIR /app
COPY go.sum go.mod ./
RUN go mod download
COPY cmd cmd
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-s -w' -o target/healthcheck cmd/healthcheck.go
LABEL de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="builder"
### HTTP server ###
# https://hub.docker.com/_/nginx/
FROM nginx:1.27.2-alpine3.20-slim AS http_server
RUN mkdir -p /usr/share/nginx/html/-/health && \
touch /usr/share/nginx/html/-/health/liveness && \
printf '<!doctype html><title>sdavids-docker-healthcheck-go-http</title><h1>sdavids-docker-healthcheck-go-http</h1>' > /usr/share/nginx/html/index.html && \
printf 'server {listen 3000;listen [::]:3000;location / {root /usr/share/nginx/html;index index.html;}}' > /etc/nginx/conf.d/default.conf
LABEL de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="builder"
### final ###
FROM http_server
EXPOSE 3000
COPY --from=healthcheck \
/app/target/healthcheck \
/usr/local/bin/healthcheck
HEALTHCHECK --interval=5s --timeout=5s --start-period=5s \
CMD healthcheck || exit 1
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.vendor="Sebastian Davids" \
org.opencontainers.image.title="healthcheck-go-http" \
de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="development"