Skip to content

Commit 36a9d5b

Browse files
committed
Add scripts to compile samples in Docker
1 parent 99a6892 commit 36a9d5b

8 files changed

+183
-79
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4-
## March 26 2019
4+
## April 1 2019
5+
* Added scripts to compile samples inside a container
6+
7+
## March 26 2019 - v4.0.2
58
* BREAKING API: Add hConn to callback function
69
* Callbacks not setting hConn correctly (#93)
710

Dockerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# © Copyright IBM Corporation 2019
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:18.10
16+
FROM $BASE_IMAGE
17+
18+
ARG GOPATH_ARG="/go"
19+
20+
ENV GOVERSION=1.10 \
21+
GOPATH=$GOPATH_ARG \
22+
ORG="github.com/ibm-messaging" \
23+
REPO="mq-golang"
24+
25+
# Location of the downloadable MQ client package \
26+
ENV RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
27+
RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \
28+
VRMF=9.1.2.0
29+
30+
# Install the Go compiler and Git
31+
RUN export DEBIAN_FRONTEND=noninteractive \
32+
&& bash -c 'source /etc/os-release; \
33+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} main restricted" > /etc/apt/sources.list; \
34+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates main restricted" >> /etc/apt/sources.list; \
35+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-backports main restricted universe" >> /etc/apt/sources.list; \
36+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} universe" >> /etc/apt/sources.list; \
37+
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates universe" >> /etc/apt/sources.list;' \
38+
&& apt-get update \
39+
&& apt-get install -y --no-install-recommends \
40+
golang-${GOVERSION} \
41+
git \
42+
ca-certificates \
43+
curl \
44+
tar \
45+
bash \
46+
go-dep \
47+
build-essential \
48+
&& rm -rf /var/lib/apt/lists/*
49+
50+
# Create location for the git clone and MQ installation
51+
RUN mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg \
52+
&& chmod -R 777 $GOPATH \
53+
&& mkdir -p $GOPATH/src/$ORG \
54+
&& mkdir -p /opt/mqm \
55+
&& chmod a+rx /opt/mqm
56+
57+
# Install the MQ client from the Redistributable package. This also contains the
58+
# header files we need to compile against.
59+
RUN cd /opt/mqm \
60+
&& curl -LO "$RDURL/$VRMF-$RDTAR" \
61+
&& tar -zxf ./*.tar.gz \
62+
&& rm -f ./*.tar.gz
63+
64+
# Insert the script that will do the build
65+
COPY buildInDocker.sh $GOPATH
66+
RUN chmod 777 $GOPATH/buildInDocker.sh
67+
68+
# Copy the rest of the source tree from this directory into the container
69+
COPY . $GOPATH/src/$ORG/$REPO
70+
71+
# Set the entrypoint to the script that will do the compilation
72+
ENTRYPOINT $GOPATH/buildInDocker.sh

Dockerfile-build-packages

Lines changed: 0 additions & 49 deletions
This file was deleted.

Dockerfile-build-samples

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ some monitoring packages. These have now been moved to a
99
new [GitHub repository called mq-metric-samples](https://github.com/ibm-messaging/mq-metric-samples).
1010

1111
A minimum level of MQ V8 is required to build these packages. However, note that
12-
the monitoring data published by the queue manager is not available before MQ V9.
12+
the monitoring data published by the queue manager and exploited in the mqmetric package
13+
is not available before MQ V9.
1314

1415
## Health Warning
1516

@@ -77,10 +78,10 @@ export CGO_LDFLAGS_ALLOW="-Wl,-rpath.*"
7778
### Windows
7879

7980
* Install the Go runtime and compiler. On Windows, the common directory is `c:\Go`
80-
* Ensure you have a gcc-based compiler, for example from the Cygwin distribution.
81-
I recommend you use the mingw variation, to ensure compiled code can be used on systems without Cygwin installed.
81+
* Ensure you have a gcc-based compiler, for example from the Cygwin distribution.
82+
I recommend you use the mingw variation, to ensure compiled code can be used on systems without Cygwin installed.
8283
The default `gcc` compiler from Cygwin does not work because it tries to build a
83-
Cygwin-enabled executable but the MQ libraries do not work in that model;
84+
Cygwin-enabled executable but the MQ libraries do not work in that model;
8485
the `mingw` versions build Windows-native programs.
8586
* Create a working directory. For example, `mkdir c:\Gowork`
8687
* Set environment variables. Based on the previous lines,
@@ -105,7 +106,7 @@ set CC=x86_64-w64-mingw32-gcc.exe
105106
* If you have not installed MQ libraries into the default location, then set environment variables
106107
for the C compiler to recognise those directories. You may get messages from the compiler
107108
saying that the default MQ directories cannot be found, but those warnings can be ignored.
108-
The exact values for these environment variables will vary by platform, but follow the
109+
The exact values for these environment variables will vary by platform, but follow the
109110
corresponding CFLAGS/LDFLAGS values in `mqi.go`
110111

111112
For example,
@@ -133,6 +134,9 @@ For example,
133134
At this point, you should have a compiled copy of the program in `$GOPATH/bin`. See the
134135
`samples` directory for more sample programs.
135136

137+
The `buildSamples.sh` script in this directory can also be used to create a container which will
138+
compile the samples and copy them to a local directory.
139+
136140
## Limitations
137141

138142
All regular MQI verbs are now available through the `ibmmq` package.

buildInDocker.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# © Copyright IBM Corporation 2019
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Script to build the Go libraries and sample programs from within a Docker container
18+
# This script is INSIDE the container and used as the entrypoint.
19+
20+
export PATH="${PATH}:/usr/lib/go-${GOVERSION}/bin:/go/bin"
21+
export CGO_CFLAGS="-I/opt/mqm/inc/"
22+
export CGO_LDFLAGS_ALLOW="-Wl,-rpath.*"
23+
24+
# Build the libraries so they can be used by other programs
25+
cd $GOPATH/src
26+
27+
for pkg in $ORG/$REPO/ibmmq $ORG/$REPO/mqmetric
28+
do
29+
lib=`basename $pkg`
30+
echo "Building $lib"
31+
go install $pkg
32+
done
33+
34+
# And do the sample program builds into the bin directory
35+
cd $GOPATH
36+
srcdir=src/$ORG/$REPO/samples
37+
38+
for samp in $srcdir/*.go
39+
do
40+
exe=`basename $samp .go`
41+
echo "Building $exe"
42+
go build -o bin/$exe $samp
43+
done

buildSamples.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# © Copyright IBM Corporation 2019
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+
# This simple script builds a Docker container whose purpose is simply
16+
# to compile the libraries and sample programs, and then to copy those
17+
# outputs to a local temporary directory.
18+
# In order to run the sample programs you will still need a copy of
19+
# the MQ runtime libraries in the environment.
20+
21+
GOPATH="/go"
22+
23+
TAG="mq-golang-samples-gobuild"
24+
# Assume repo tags have been created in a sensible order
25+
VER=`git tag -l | sort | tail -1 | sed "s/^v//g"`
26+
if [ -z "$VER" ]
27+
then
28+
VER="latest"
29+
fi
30+
echo "Building container $TAG:$VER"
31+
32+
# Build a container that has all the pieces needed to compile the Go programs for MQ
33+
docker build --build-arg GOPATH_ARG=$GOPATH -t $TAG:$VER .
34+
rc=$?
35+
36+
if [ $rc -eq 0 ]
37+
then
38+
# Run the image to do the compilation and extract the files
39+
# from it into local directories mounted into the container.
40+
OUTBINDIR=$HOME/tmp/mq-golang-samples/bin
41+
OUTPKGDIR=$HOME/tmp/mq-golang-samples/pkg
42+
rm -rf $OUTBINDIR $OUTPKGDIR >/dev/null 2>&1
43+
mkdir -p $OUTBINDIR $OUTPKGDIR
44+
45+
# Mount an output directory
46+
# Delete the container once it's done its job
47+
docker run --rm \
48+
-v $OUTBINDIR:$GOPATH/bin:z \
49+
-v $OUTPKGDIR:$GOPATH/pkg:z \
50+
$TAG:$VER
51+
echo "Compiled samples should now be in $OUTBINDIR"
52+
fi

samples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ which configuration values can be changed.
88
Make sure you first read the README in the root of this repository to set up an environment
99
where Go programs can be compiled, and how the packages refer to the MQ interfaces.
1010

11+
The `buildSamples.sh` script in the root directory can be used to create a container to
12+
compile the samples and copy them to a local directory.
13+
1114
## Default values
1215
Where needed for the sample programs:
1316

0 commit comments

Comments
 (0)