forked from thehowl/ip.zxq.co
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
85 lines (70 loc) · 2.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
FROM alpine as assets
WORKDIR /opt
# ADD https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz /app/
ADD https://raw.githubusercontent.com/wp-statistics/GeoLite2-City/master/GeoLite2-City.mmdb.gz /opt
ADD https://raw.githubusercontent.com/wp-statistics/GeoLite2-Country/master/GeoLite2-Country.mmdb.gz /opt
RUN cd /opt && \
# gunzip GeoLite2-ASN.tar.gz && \
gunzip GeoLite2-City.mmdb.gz && \
gunzip GeoLite2-Country.mmdb.gz && \
chmod 444 *.mmdb
# build application
FROM golang:1.15 AS build
WORKDIR /go/src/app
# Create appuser.
# See https://stackoverflow.com/a/55757473/12429735RUN
ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
RUN apt-get update && apt-get install -y ca-certificates
COPY go.mod .
COPY go.sum .
RUN go mod download
ARG APPLICATION="myapp"
ARG BUILD_RFC3339="1970-01-01T00:00:00Z"
ARG REVISION="local"
ARG VERSION="dirty"
ARG GO_LDFLAGS="-w -s \
-X github.com/jnovack/release.Application=${APPLICATION} \
-X github.com/jnovack/release.BuildRFC3339=${BUILD_RFC3339} \
-X github.com/jnovack/release.Package=${PACKAGE} \
-X github.com/jnovack/release.Revision=${REVISION} \
-X github.com/jnovack/release.Version=${VERSION} \
-extldflags '-static'"
# Build
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "${GO_LDFLAGS}" -o /go/bin/${APPLICATION} cmd/${APPLICATION}/*
###############################################################################
# final stage
FROM scratch
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=assets /opt/*.mmdb /
USER appuser:appuser
ARG APPLICATION="myapp"
ARG BUILD_RFC3339="1970-01-01T00:00:00Z"
ARG REVISION="local"
ARG DESCRIPTION="no description"
ARG PACKAGE="user/repo"
ARG VERSION="dirty"
LABEL org.opencontainers.image.ref.name="${PACKAGE}" \
org.opencontainers.image.created=$BUILD_RFC3339 \
org.opencontainers.image.authors="Justin J. Novack <[email protected]>" \
org.opencontainers.image.documentation="https://github.com/${PACKAGE}/README.md" \
org.opencontainers.image.description="${DESCRIPTION}" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://github.com/${PACKAGE}" \
org.opencontainers.image.revision=$REVISION \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.url="https://hub.docker.com/r/${PACKAGE}/"
EXPOSE 8000
COPY --from=build /go/bin/${APPLICATION} /app
ENTRYPOINT ["/app"]