-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
84 lines (70 loc) · 2.4 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
#
# NOTE:
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
#
FROM golang:1.23-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 libmcrypt-dev \
&& echo "--"
RUN go test $(go list ./... | grep -v tcg/integration) \
&& echo "[Go TESTS DONE]"
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.23-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]"
# use bash for run to support '[[' command
SHELL ["/bin/bash", "-c"]
RUN sh -x \
&& mkdir -p /app \
&& 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}'" \
&& CGO_ENABLED=1 go build -v -o /app/tcg -ldflags "$ldflags" . \
&& echo "[TCG BUILD DONE]"
RUN sh -x \
&& for d in /go/src/connectors/*/ ; \
do [ ! -f "${d}tcg_config.yaml" ] && continue ; \
cmd=$(basename "$d") ; dest="/app/${cmd}" ; \
echo "__ $cmd __" ; mkdir -p "$dest" \
&& cp "${d}tcg_config.yaml" "$dest" \
&& ln -s /app/tcg "/app/tcg-${cmd}" ; \
done \
&& echo "[CONNECTORS DONE]"
RUN sh -x \
&& [ -d /app/k8s ] && ln -s /app/k8s /app/kubernetes \
&& ln -s /app/tcg /app/tcg-kubernetes \
&& echo "[ALIASES 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 coreutils \
ca-certificates openssl \
curl jq vim \
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"]