1+ # syntax=docker/dockerfile:1
2+
3+ # Global ARG. To be used in all stages.
4+ ARG EXPORTER=mq_prometheus
5+
6+ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
7+ # # ### ### ### ### ### ### BUILD ### ### ### ### ### ### ##
8+ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
9+ FROM golang:1.19 AS builder
10+
11+ ARG EXPORTER
12+
13+ ENV EXPORTER=${EXPORTER} \
14+ ORG="github.com/ibm-messaging" \
15+ REPO="mq-metric-samples" \
16+ RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
17+ RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \
18+ VRMF=9.3.1.0 \
19+ CGO_CFLAGS="-I/opt/mqm/inc/" \
20+ CGO_LDFLAGS_ALLOW="-Wl,-rpath.*" \
21+ genmqpkg_incnls=1 \
22+ genmqpkg_incsdk=1 \
23+ genmqpkg_inctls=1
24+
25+ # Install packages
26+ RUN apt-get update \
27+ && apt-get install -y --no-install-recommends \
28+ ca-certificates \
29+ build-essential
30+
31+ # Create directory structure
32+ RUN mkdir -p /go/src /go/bin /go/pkg \
33+ && chmod -R 777 /go \
34+ && mkdir -p /go/src/$ORG \
35+ && mkdir -p /opt/mqm \
36+ && chmod a+rx /opt/mqm
37+
38+ # Install MQ client
39+ WORKDIR /opt/mqm
40+ RUN curl -LO "$RDURL/$VRMF-$RDTAR" \
41+ && tar -zxf ./*.tar.gz \
42+ && rm -f ./*.tar.gz \
43+ && bin/genmqpkg.sh -b /opt/mqm
44+
45+ # Build Go application
46+ WORKDIR /go/src/$ORG/$REPO
47+ COPY go.mod .
48+ COPY go.sum .
49+ COPY --chmod=777 ./cmd/${EXPORTER} .
50+ COPY vendor ./vendor
51+ COPY pkg ./pkg
52+ RUN go build -mod=vendor -o /go/bin/${EXPORTER} ./*.go
53+
54+ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
55+ # ## ### ### ### ### ### ### RUN ### ### ### ### ### ### ###
56+ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
57+ FROM golang:1.19
58+
59+ ARG EXPORTER
60+
61+ ENV EXPORTER=${EXPORTER} \
62+ RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
63+ RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \
64+ VRMF=9.3.1.0 \
65+ genmqpkg_incnls=1 \
66+ genmqpkg_incsdk=1 \
67+ genmqpkg_inctls=1 \
68+ LD_LIBRARY_PATH="/opt/mqm/lib64:/usr/lib64" \
69+ MQ_CONNECT_TYPE=CLIENT \
70+ IBMMQ_GLOBAL_CONFIGURATIONFILE=/opt/config/${EXPORTER}.yaml
71+
72+ # Create directory structure
73+ RUN mkdir -p /opt/bin \
74+ && chmod -R 777 /opt/bin \
75+ && mkdir -p /opt/mqm \
76+ && chmod 775 /opt/mqm \
77+ && mkdir -p /opt/config \
78+ && chmod a+rx /opt/config
79+
80+ # Install packages
81+ RUN apt-get update \
82+ && apt-get install -y --no-install-recommends \
83+ ca-certificates \
84+ && rm -rf /var/lib/apt/lists/*
85+
86+ # Install MQ client
87+ WORKDIR /opt/mqm
88+ RUN curl -LO "$RDURL/$VRMF-$RDTAR" \
89+ && tar -zxf ./*.tar.gz \
90+ && rm -f ./*.tar.gz \
91+ && bin/genmqpkg.sh -b /opt/mqm \
92+ && mkdir -p /IBM/MQ/data/errors \
93+ && mkdir -p /.mqm \
94+ && chmod -R 777 /IBM \
95+ && chmod -R 777 /.mqm
96+
97+ COPY --chmod=777 --from=builder /go/bin/${EXPORTER} /opt/bin/${EXPORTER}
98+
99+ CMD ["sh" , "-c" , "/opt/bin/${EXPORTER}" ]
0 commit comments