-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
77 lines (67 loc) · 2.23 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
#
# NOTE:
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
#
FROM golang:1.19-bullseye AS build-libtransit
ARG TRAVIS_TAG=
ENV TRAVIS_TAG=${TRAVIS_TAG:-master}
WORKDIR /go/src/
COPY . .
RUN apt-get update -y \
&& echo "--" \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
libjansson-dev \
&& echo "--"
RUN make clean && make \
&& cp libtransit/libtransit.so libtransit/libtransit.h libtransit/transit.h build/ \
&& echo "[LIBTRANSIT BUILD DONE]"
FROM scratch AS export-libtransit
COPY --from=build-libtransit /go/src/build /
FROM golang:1.19-alpine AS build
ARG TRAVIS_TAG=
ENV TRAVIS_TAG=${TRAVIS_TAG:-master}
WORKDIR /go/src/
COPY . .
RUN apk add --no-cache \
bash build-base git \
libmcrypt libmcrypt-dev \
&& echo "[CHECKER NSCA DEPS DONE]"
RUN go test $(go list ./... | grep -v tcg/integration) \
&& echo "[Go TESTS DONE]"
# use bash for run to support '[[' command
SHELL ["/bin/bash", "-c"]
RUN sh -x \
&& build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
&& ldflags="-X 'github.com/gwos/tcg/config.buildTime=${build_time}'" \
&& ldflags="${ldflags} -X 'github.com/gwos/tcg/config.buildTag=${TRAVIS_TAG}'" \
&& for d in /go/src/connectors/*connector/; \
do cd "$d"; pwd; \
CGO_ENABLED=0; \
if [[ "$d" == *nsca* ]] ; then CGO_ENABLED=1; fi; \
echo "CGO_ENABLED:$CGO_ENABLED"; \
CGO_ENABLED=$CGO_ENABLED go build -ldflags "$ldflags" . \
&& name=$(ls *connector) \
&& dest="/app/${name}" \
&& mkdir -p "$dest" \
&& cp *connector *config.yaml "$dest" \
&& cd -; \
done \
&& echo "[CONNECTORS DONE]"
RUN cp ./docker_cmd.sh /app/
# Support custom-build-outputs for debug the build
# https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
FROM scratch AS export
COPY --from=build /app /
FROM alpine:3.11 AS prod
# update zlib to fix CVE
RUN apk add -u --no-cache \
bash \
ca-certificates openssl \
curl \
libmcrypt \
zlib \
&& update-ca-certificates
COPY --from=build /app /app
# Land docker exec into var folder
WORKDIR /tcg/
CMD ["/app/docker_cmd.sh", "apm-connector"]