-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDockerfile
68 lines (48 loc) · 1.6 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
59
60
61
62
63
64
65
66
67
68
FROM golang:1.20.5-alpine3.18 AS build
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
# Create appuser
ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /app
COPY go.mod go.sum /app/
RUN go mod download
ENV CGO_ENABLED=0
COPY . /app
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /app/aim-oscar-server
RUN chmod +x /app/aim-oscar-server
FROM golang:1.20.5-alpine3.18 AS prod
WORKDIR /app
EXPOSE 5190
EXPOSE 5191
# Import from builder.
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
COPY --from=build /app/models /app/models
COPY --from=build /app/aim-oscar-server /app/aim-oscar-server
# Use an unprivileged user.
USER appuser:appuser
ARG config
COPY $config /etc/aim-oscar-server/config.yml
CMD ["/app/aim-oscar-server", "-config", "/etc/aim-oscar-server/config.yml"]
FROM prod as dev
ARG config
COPY $config /etc/aim-oscar-server/config.yml
CMD ["/app/aim-oscar-server", "-config", "/etc/aim-oscar-server/config.yml"]
FROM build as db_tools
WORKDIR /app
ARG config
COPY $config /etc/aim-oscar-server/config.yml
COPY . /app
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=linux GOARCH=amd64 go build -o migrate cmd/migrate/main.go
ENTRYPOINT ["/app/migrate", "-config", "/etc/aim-oscar-server/config.yml"]