-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
88 lines (60 loc) · 2.53 KB
/
Dockerfile
File metadata and controls
88 lines (60 loc) · 2.53 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Base stage, sets up the GRPC Health Probe, we use a ubuntu image because no devcontainer features work on alpine
ARG GO_VERSION
FROM golang:${GO_VERSION} AS builder_base
# Needed to get the right grpc_health_probe binary
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
# Install gRPC Health Probe
RUN set -ex \
&& curl -fSL "https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.19/grpc_health_probe-${TARGETOS}-${TARGETARCH}" -o /usr/local/bin/grpc_health_probe \
&& chmod +x /usr/local/bin/grpc_health_probe
#######################################################
# Builds the development container
FROM builder_base AS development
# We listen on port 80 in development
EXPOSE 80
# Health check
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 CMD [ "grpc_health_probe", "-addr", "localhost:80", "-connect-timeout", "100ms", "-rpc-timeout", "250ms" ]
# Create the user
RUN adduser --uid 1000 appuser
USER appuser
# Install Air for live reloading
RUN go install github.com/cosmtrek/air@latest
ENTRYPOINT ["./docker/dev-container.sh"]
#######################################################
# Builds the test container for CI
FROM golang:${GO_VERSION}-alpine AS testing
WORKDIR /app
# Create the user
RUN adduser -u1000 -D appuser
USER appuser
# We check if a file exists in /tmp/health.txt to see if the container is healthy
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=10 CMD [ "sh", "-c", "[ -f /tmp/health.txt ]"]
ENTRYPOINT [ "./docker/test-container.sh" ]
#######################################################
# Builds the production binary
FROM golang:${GO_VERSION}-alpine AS builder_production
WORKDIR /app
# Go dependencies
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
COPY proto ./proto
# Do the build
RUN go build -buildvcs=false -o ecfmp-discord ./cmd/ecfmp-discord
# Make sure the binary is executable
RUN chmod +x ecfmp-discord
#######################################################
# This container runs the actual binary in production
FROM alpine:3.18 as production
# Create the user
RUN adduser -u1000 -D appuser
COPY --from=builder_production --chown=appuser:appuser ./app/ecfmp-discord /ecfmp-discord
COPY --from=builder_base /usr/local/bin/grpc_health_probe /usr/local/bin/grpc_health_probe
EXPOSE 80
# Health check
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 CMD [ "grpc_health_probe", "-addr", "localhost:80", "-connect-timeout", "100ms", "-rpc-timeout", "250ms" ]
USER appuser
ENTRYPOINT [ "/ecfmp-discord" ]