-
Notifications
You must be signed in to change notification settings - Fork 70
/
Dockerfile
158 lines (139 loc) · 6.36 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# syntax=docker/dockerfile:1
# This Dockerfile shows how you can both build and run a container with
# a specific exporter/collector program. It uses two stages, copying the relevant
# material from the build step into the runtime container.
#
# It can cope with both platforms where a Redistributable Client is available, and platforms
# where it is not - copy the .deb install images for such platforms into the MQINST
# subdirectory of this repository first.
# Global ARG. To be used in all stages.
# Override with "--build-arg EXPORTER=mq_xxxxx" when building.
ARG EXPORTER=mq_prometheus
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
## ### ### ### ### ### ### BUILD ### ### ### ### ### ### ##
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
ARG BASE_IMAGE=registry.access.redhat.com/ubi8/go-toolset:1.21
FROM $BASE_IMAGE AS builder
ARG EXPORTER
ENV EXPORTER=${EXPORTER} \
ORG="github.com/ibm-messaging" \
REPO="mq-metric-samples" \
VRMF=9.4.1.0 \
CGO_CFLAGS="-I/opt/mqm/inc/" \
CGO_LDFLAGS_ALLOW="-Wl,-rpath.*" \
genmqpkg_incnls=1 \
genmqpkg_incsdk=1 \
genmqpkg_inctls=1
ENV GOVERSION=1.22.8
USER 0
# The base UBI8 image does not (currently) contain the most
# recent Go compiler. Which tends to be required for the OTel
# packages. So we have to explicitly download and install it.
# As long as we've got SOME level of compiler (which this base image)
# does have, we can use it to pull down the more recent levels. It appears as if a
# "go build ..." will now actually automatically pull in the newer level if needed
# by the go.mod directives. But let's be explicit.
RUN go install golang.org/dl/go${GOVERSION}@latest
# The compiler is in a non-default location. For the UBI8 image,
# this is where it ends up.
ENV GO=/opt/app-root/src/go/bin/go${GOVERSION}
RUN $GO download && $GO version
# Create directory structure
RUN mkdir -p /go/src /go/bin /go/pkg \
&& chmod -R 777 /go \
&& mkdir -p /go/src/$ORG \
&& mkdir -p /opt/mqm \
&& mkdir -p /MQINST \
&& chmod a+rx /opt/mqm
# Install MQ client and SDK
# For platforms with a Redistributable client, we can use curl to pull it in and unpack it.
# For most other platforms, we assume that you have deb files available under the current directory
# and we then copy them into the container image. Use dpkg to install from them; these have to be
# done in the right order.
#
# The Linux ARM64 image is a full-function server package that is directly unpacked.
# We only need a subset of the files so strip the unneeded filesets. The download of the image could
# be automated via curl in the same way as the Linux/amd64 download, but it's a much bigger image and
# has a different license. So I'm not going to do that for now.
#
# If additional Redistributable Client platforms appear, then this block can be altered, including the MQARCH setting.
#
# The copy of the README is so that at least one file always gets copied, even if you don't have the deb files locally.
# Using a wildcard in the directory name also helps to ensure that this part of the build always succeeds.
COPY README.md MQINST*/*deb MQINST*/*tar.gz /MQINST
# These are values always set by the "docker build" process
ARG TARGETARCH TARGETOS
RUN echo "Target arch is $TARGETARCH; os is $TARGETOS"
# Might need to refer to TARGET* vars a few times in this block, so define something shorter.
ARG RDURL_ARG="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist"
RUN T="$TARGETOS/$TARGETARCH"; \
if [ "$T" = "linux/amd64" ]; \
then \
MQARCH=X64;\
RDURL=${RDURL_ARG};\
RDTAR="IBM-MQC-Redist-Linux${MQARCH}.tar.gz"; \
cd /opt/mqm \
&& curl -LO "$RDURL/$VRMF-$RDTAR" \
&& tar -zxf ./*.tar.gz \
&& rm -f ./*.tar.gz \
&& bin/genmqpkg.sh -b /opt/mqm;\
elif [ "$T" = "linux/arm64" ] ;\
then \
cd /MQINST; \
c=`ls *$VRMF*.tar.gz 2>/dev/null| wc -l`; if [ $c -ne 1 ]; then echo "MQ installation file does not exist in MQINST subdirectory";exit 1;fi; \
cd /opt/mqm \
&& tar -zxf /MQINST/*.tar.gz \
&& export genmqpkg_incserver=0 \
&& bin/genmqpkg.sh -b /opt/mqm;\
elif [ "$T" = "linux/ppc64le" -o "$T" = "linux/s390x" ];\
then \
cd /MQINST; \
c=`ls ibmmq-*$VRMF*.deb 2>/dev/null| wc -l`; if [ $c -lt 4 ]; then echo "MQ installation files do not exist in MQINST subdirectory";exit 1;fi; \
for f in ibmmq-runtime_$VRMF*.deb ibmmq-gskit_$VRMF*.deb ibmmq-client_$VRMF*.deb ibmmq-sdk_$VRMF*.deb; do dpkg -i $f;done; \
else \
echo "Unsupported platform $T";\
exit 1;\
fi
# Build the Go application
WORKDIR /go/src/$ORG/$REPO
COPY go.mod .
COPY go.sum .
COPY --chmod=777 ./cmd/${EXPORTER} .
COPY --chmod=777 vendor ./vendor
COPY --chmod=777 pkg ./pkg
# This file holds something like the current commit level if it exists in your tree. It might not be there, so
# we use wildcards and a known file to avoid errors on non-existent files/dirs.
COPY --chmod=777 README.md ./.git*/refs/heads/master* .
RUN buildStamp=`date +%Y%m%d-%H%M%S`; \
hw=`uname -m`; \
os=`uname -s`; \
bp="$os/$hw"; \
if [ -r master ]; then gitCommit=`cat master`;else gitCommit="Unknown";fi; \
BUILD_EXTRA_INJECT="-X \"main.BuildStamp=$buildStamp\" -X \"main.BuildPlatform=$bp\" -X \"main.GitCommit=$gitCommit\""; \
$GO build -mod=vendor -ldflags "$BUILD_EXTRA_INJECT" -o /go/bin/${EXPORTER} ./*.go
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
### ### ### ### ### ### ### RUN ### ### ### ### ### ### ###
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
# Use a "minimal" runtime image
FROM registry.access.redhat.com/ubi8-minimal:latest AS runtime
ARG EXPORTER
# Create directory structure
RUN mkdir -p /opt/bin \
&& chmod -R 777 /opt/bin \
&& mkdir -p /opt/mqm \
&& chmod 775 /opt/mqm \
&& mkdir -p /opt/config \
&& chmod a+rx /opt/config
# Create MQ client directories
WORKDIR /opt/mqm
RUN mkdir -p /IBM/MQ/data/errors \
&& mkdir -p /.mqm \
&& chmod -R 777 /IBM \
&& chmod -R 777 /.mqm
ENV EXPORTER=${EXPORTER} \
LD_LIBRARY_PATH="/opt/mqm/lib64:/usr/lib64" \
MQ_CONNECT_TYPE=CLIENT \
IBMMQ_GLOBAL_CONFIGURATIONFILE=/opt/config/${EXPORTER}.yaml
COPY --chmod=555 --from=builder /go/bin/${EXPORTER} /opt/bin/${EXPORTER}
COPY --from=builder /opt/mqm/ /opt/mqm/
CMD ["sh", "-c", "/opt/bin/${EXPORTER}"]