Skip to content

Commit c52ecc2

Browse files
committed
show how to build a runnable container from a sample.
1 parent 02b10a0 commit c52ecc2

File tree

6 files changed

+163
-2
lines changed

6 files changed

+163
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## Sep 29 2020 - no new version
5+
* samples - Add script to build a running container with a sample program in it
6+
47
## Sep 10 2020 - v5.1.2
58
* mqmetric - Add loglevel=TRACE and trace-points for all key functions in the package
69
* mqmetric - Add channel status bytes and buffer counts

mqmetric/status.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,13 @@ func statusGetIntAttributes(s StatusSet, elem *ibmmq.PCFParameter, key string) b
274274
// then use it to create the delta. Otherwise make the initial
275275
// value 0.
276276
if prevVal, ok := s.Attributes[attr].prevValues[key]; ok {
277-
s.Attributes[attr].Values[key] = newStatusValueInt64(v - prevVal)
277+
if v-prevVal < 0 {
278+
// Value might have wrapped. This number may be temporarily "wrong" but it's
279+
// sorted out on the next iteration
280+
s.Attributes[attr].Values[key] = newStatusValueInt64(v)
281+
} else {
282+
s.Attributes[attr].Values[key] = newStatusValueInt64(v - prevVal)
283+
}
278284
} else {
279285
s.Attributes[attr].Values[key] = newStatusValueInt64(0)
280286
}
@@ -290,7 +296,11 @@ func statusGetIntAttributes(s StatusSet, elem *ibmmq.PCFParameter, key string) b
290296
// then use it to create the delta. Otherwise make the initial
291297
// value 0.
292298
if prevVal, ok := s.Attributes[attr].prevValues[key]; ok {
293-
s.Attributes[attr].Values[key] = newStatusValueInt64(v[index] - prevVal)
299+
if v[index]-prevVal < 0 {
300+
s.Attributes[attr].Values[key] = newStatusValueInt64(v[index])
301+
} else {
302+
s.Attributes[attr].Values[key] = newStatusValueInt64(v[index] - prevVal)
303+
}
294304
} else {
295305
s.Attributes[attr].Values[key] = newStatusValueInt64(0)
296306
}

samples/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Some trivial scripts run the sample programs in matching pairs:
3636
* putget.sh : Run amqsput and then use the generated MsgId to get the same message with amqsget
3737
* pubsub.sh : Start amqssub and then run the amqspub program immediately
3838

39+
Building a container:
40+
* runSample.sh : Drives the process to get `amqsput` into the container
41+
* runSample.Dockerfile : Instructions to create the container with its dependencies
42+
* runSample.gomod : Copied into the container as `go.mod`
43+
3944
The `mqitest` sample program in its own subdirectory is a more general demonstration
4045
of many of the features available from the MQI rather than focussed on a specific
4146
aspect.
@@ -62,6 +67,11 @@ You will probably want to run `amqssub` JUST BEFORE running `amqspub` to ensure
6267
there is something waiting to receive the publications when they are made. The
6368
`pubsub.sh` script executes the two programs appropriately.
6469

70+
## Building a container for running samples
71+
There is an set of files in here that will show how to create a container that runs
72+
the `amqsput` program. The `runSample.sh` script drives the process. It will try to
73+
connect to a queue manager running on the host machine.
74+
6575
## More information
6676
Comments in the programs explain what they are doing. For more detailed information about the
6777
MQ API, the functions, structures, and constants, see the

samples/runSample.Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# © Copyright IBM Corporation 2019, 2020
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BASE_IMAGE=ubuntu:19.10
16+
FROM $BASE_IMAGE
17+
18+
ARG GOPATH_ARG="/go"
19+
20+
ENV GOVERSION=1.13 \
21+
GOPATH=$GOPATH_ARG \
22+
ORG="github.com/ibm-messaging"
23+
24+
# Install the Go compiler and Git
25+
RUN export DEBIAN_FRONTEND=noninteractive \
26+
&& bash -c 'source /etc/os-release; \
27+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} main restricted" > /etc/apt/sources.list; \
28+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates main restricted" >> /etc/apt/sources.list; \
29+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-backports main restricted universe" >> /etc/apt/sources.list; \
30+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} universe" >> /etc/apt/sources.list; \
31+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates universe" >> /etc/apt/sources.list;' \
32+
&& apt-get update \
33+
&& apt-get install -y --no-install-recommends \
34+
golang-${GOVERSION} \
35+
git \
36+
ca-certificates \
37+
curl \
38+
tar \
39+
bash \
40+
go-dep \
41+
build-essential \
42+
&& rm -rf /var/lib/apt/lists/*
43+
44+
# Create location for the go programs and the MQ installation
45+
RUN mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg \
46+
&& chmod -R 777 $GOPATH \
47+
&& mkdir -p /opt/mqm \
48+
&& chmod a+rx /opt/mqm
49+
50+
# Location of the downloadable MQ client package \
51+
ENV RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
52+
RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \
53+
VRMF=9.2.0.0
54+
55+
# Install the MQ client from the Redistributable package. This also contains the
56+
# header files we need to compile against. Setup the subset of the package
57+
# we are going to keep - the genmqpkg.sh script removes unneeded parts
58+
ENV genmqpkg_incnls=1 \
59+
genmqpkg_incsdk=1 \
60+
genmqpkg_inctls=1
61+
62+
RUN cd /opt/mqm \
63+
&& curl -LO "$RDURL/$VRMF-$RDTAR" \
64+
&& tar -zxf ./*.tar.gz \
65+
&& rm -f ./*.tar.gz \
66+
&& bin/genmqpkg.sh -b /opt/mqm
67+
68+
# We need the Go compiler in our PATH
69+
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/go-$GOVERSION/bin
70+
71+
# Copy the source file over. We also need a go.mod file
72+
# The source for that has a different name in the repo so it doesn't accidentally get
73+
# used and we rename it during this copy.
74+
COPY amqsput.go $GOPATH_ARG/src
75+
COPY runSample.gomod $GOPATH_ARG/src/go.mod
76+
77+
# Do the actual compile. This will automatically download the ibmmq package
78+
RUN cd $GOPATH_ARG/src && go build -o $GOPATH_ARG/bin/amqsput amqsput.go
79+
80+
# The startup script will set MQSERVER and optionally set
81+
# more environment variables that will be passed to amqsput through this entrypoint.
82+
ENTRYPOINT /go/bin/amqsput $QUEUE $QMGR

samples/runSample.gomod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module amqsput/v5
2+
3+
go 1.13
4+
5+
require (
6+
github.com/ibm-messaging/mq-golang/v5 v5.1.2
7+
)

samples/runSample.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This is an example of running one of the sample programs in a container.
2+
3+
function latestSemVer {
4+
(for x in $*
5+
do
6+
echo $x | sed "s/^v//g"
7+
done) | sort -n | tail -1
8+
}
9+
10+
# Assume repo tags have been created in a sensible order. Find the mq-golang
11+
# version in the root go.mod file and the current Git tag for this repo.
12+
# Then pick the latest version to create the Docker tag
13+
VERDEP=`cat ../go.mod | awk '/mq-golang/ {print $2}' `
14+
VERREPO=`git tag -l | sort | tail -1 `
15+
16+
VER=`latestSemVer $VERDEP $VERREPO`
17+
if [ -z "$VER" ]
18+
then
19+
VER="latest"
20+
fi
21+
22+
# Basic name for the container
23+
TAG=mq-golang-sample-amqsput
24+
echo Building container with tag $TAG:$VER
25+
26+
# Build the container which includes compilation of the program
27+
docker build -t $TAG:$VER -f runSample.Dockerfile .
28+
if [ $? -eq 0 ]
29+
then
30+
# This line grabs a currently active IPv4 address for this machine. It's probably
31+
# not what you want to use for a real system but it's useful for testing. "localhost"
32+
# does not necessarily work inside the container so we need a real address.
33+
addr=`ip -4 addr | grep "state UP" -A2 | grep inet | tail -n1 | awk '{print $2}' | cut -f1 -d'/'`
34+
echo "Local address is $addr"
35+
port="1414"
36+
37+
if [ ! -z "addr" ]
38+
then
39+
# Run the container. Can override default command line values in amqsput voa
40+
# env vars here.
41+
docker run -e MQSERVER="SYSTEM.DEF.SVRCONN/TCP/$addr($port)" \
42+
-e QUEUE=DEV.QUEUE.1 \
43+
-e QMGR=QM1 \
44+
$TAG:$VER
45+
else
46+
echo "Cannot find a working address for this system"
47+
exit 1
48+
fi
49+
fi

0 commit comments

Comments
 (0)