-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
86 lines (68 loc) · 2.31 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
86
ARG BASE_BUILD_IMAGE
FROM ${BASE_BUILD_IMAGE:-golang:1.19} AS builder
ARG VERSION
ARG W_PKG
ARG GO111MODULE
ARG GOPROXY
ARG CN
ARG WORKDIR
ARG APPNAME
# docker build --build-arg CN=1 -t awesome-tool:latest .
ENV AN=${APPNAME:-fluent}
ENV SRCS=./examples/fluent
ENV WDIR=${WORKDIR:-/var/lib/$AN}
ENV GIT_REVISION ""
ENV GOVERSION "1.15"
ENV BUILDTIME ""
ENV LDFLAGS ""
WORKDIR /go/src/github.com/hedzr/$AN/
COPY . .
RUN ls -ls ./; \
W_PKG=${W_PKG:-github.com/hedzr/cmdr/conf}; \
GOPROXY=${GOPROXY:-https://goproxy.io,direct}; \
V1=$(grep -E "Version[ \t]+=[ \t]+" doc.go|grep -Eo "[0-9.]+"); \
VERSION=${VERSION:-$V1}; \
GIT_REVISION="$(git rev-parse --short HEAD)"; \
GOVERSION="$(go version)"; \
BUILDTIME="$(date -u '+%Y-%m-%d_%H-%M-%S')"; \
LDFLAGS="-s -w \
-X '$W_PKG.Githash=$GIT_REVISION' \
-X '$W_PKG.GoVersion=$GOVERSION' \
-X '$W_PKG.Buildstamp=$BUILDTIME' \
-X '$W_PKG.Version=$VERSION'"; \
echo;echo;echo "Using GOPROXY: $GOPROXY";echo " CN: $CN";echo; \
CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo \
-ldflags "$LDFLAGS" \
-o bin/$AN $SRCS && \
ls -la bin/
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-alpine:latest}
ARG CN
ARG VERSION
ARG WORKDIR
ARG CONFDIR
ARG APPNAME
ENV AN=${APPNAME:-fluent}
ENV SRCS=./examples/fluent
ENV WDIR=${WORKDIR:-/var/lib/$AN}
ENV CDIR=${CONFDIR:-/etc/$AN}
LABEL by="hedzr" \
version="$VERSION" \
com.hedzr.cmdr-fluent.version="$VERSION" \
com.hedzr.cmdr-fluent.release-date="$(date -u '+%Y-%m-%d_%H-%M-%S')" \
description="awesome-tool a command-line tool to retrieve the stars of all repos in an awesome-list"
COPY --from=builder /go/src/github.com/hedzr/$AN/ci/etc/$AN /etc/$AN
RUN ls -la $CDIR/ $CDIR/conf.d && echo " CN: $CN"; \
[[ "$CN" != "" ]] && { \
cp /etc/apk/repositories /etc/apk/repositories.bak; \
echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories; \
echo;echo;echo "apk updating...";apk update; }; \
apk --no-cache add ca-certificates && \
mkdir -p $WDIR/output /var/log/$AN /var/run/$AN && \
ls -la $WDIR/output /var/log/$AN /var/run/$AN
VOLUME [ "$WDIR/output", "$CDIR/conf.d" ]
WORKDIR $WDIR
COPY --from=builder /go/src/github.com/hedzr/$AN/bin/$AN .
RUN echo $WDIR && echo $AN && ls -la $WDIR
ENTRYPOINT [ "./fluent" ]
CMD [ "--help" ]