Skip to content

Commit d16330d

Browse files
committed
Update Dockerfile examples to default to current UBI
1 parent ab20cff commit d16330d

File tree

4 files changed

+27
-49
lines changed

4 files changed

+27
-49
lines changed

Dockerfile

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,30 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
ARG BASE_IMAGE=ubuntu:20.04
16-
FROM $BASE_IMAGE
15+
ARG BASE_IMAGE=registry.access.redhat.com/ubi8/go-toolset:1.21
16+
FROM $BASE_IMAGE AS builder
1717

1818
ARG GOPATH_ARG="/go"
19-
ARG GOVERSION=1.18
2019
ARG GOARCH=amd64
2120
ARG MQARCH=X64
2221

23-
ENV GOVERSION=${GOVERSION} \
24-
GOPATH=$GOPATH_ARG \
25-
GOTAR=go${GOVERSION}.linux-${GOARCH}.tar.gz \
22+
ENV GOPATH=$GOPATH_ARG \
2623
ORG="github.com/ibm-messaging"
2724

28-
29-
# Install the Go compiler and Git
30-
RUN export DEBIAN_FRONTEND=noninteractive \
31-
&& bash -c 'source /etc/os-release; \
32-
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} main restricted" > /etc/apt/sources.list; \
33-
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates main restricted" >> /etc/apt/sources.list; \
34-
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-backports main restricted universe" >> /etc/apt/sources.list; \
35-
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME} universe" >> /etc/apt/sources.list; \
36-
echo "deb http://archive.ubuntu.com/ubuntu/ ${UBUNTU_CODENAME}-updates universe" >> /etc/apt/sources.list;' \
37-
&& apt-get update \
38-
&& apt-get install -y --no-install-recommends \
39-
git \
40-
wget \
41-
ca-certificates \
42-
curl \
43-
tar \
44-
bash \
45-
build-essential \
46-
&& rm -rf /var/lib/apt/lists/*
25+
# Make sure we've got permissions inside the container
26+
USER 0
4727

4828
# Create location for the git clone and MQ installation
4929
RUN mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg \
5030
&& chmod -R 777 $GOPATH \
5131
&& mkdir -p $GOPATH/src/$ORG \
5232
&& cd /tmp \
53-
&& wget -nv https://dl.google.com/go/${GOTAR} \
54-
&& tar -xf ${GOTAR} \
55-
&& mv go /usr/lib/go-${GOVERSION} \
56-
&& rm -f ${GOTAR} \
5733
&& mkdir -p /opt/mqm \
5834
&& chmod a+rx /opt/mqm
5935

60-
# Location of the downloadable MQ client package \
61-
ENV RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
36+
# Location of the downloadable MQ client package
37+
ARG RDURL_ARG="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist"
38+
ENV RDURL=${RDURL_ARG} \
6239
RDTAR="IBM-MQC-Redist-Linux${MQARCH}.tar.gz" \
6340
VRMF=9.4.1.0
6441

@@ -77,13 +54,12 @@ RUN cd /opt/mqm \
7754

7855
# Insert the script that will do the build
7956
COPY --chmod=777 buildInDocker.sh $GOPATH
80-
# RUN chmod 777 $GOPATH/buildInDocker.sh
8157

8258
# Copy the rest of the source tree from this directory into the container
8359
# And make sure it's readable by the id that will run the compiles (not just root)
8460
ENV REPO="mq-golang"
8561
COPY --chmod=0777 . $GOPATH/src/$ORG/$REPO
86-
# RUN chmod -R a+rx $GOPATH/src
8762

8863
# Set the entrypoint to the script that will do the compilation
89-
ENTRYPOINT $GOPATH/buildInDocker.sh
64+
WORKDIR $GOPATH
65+
ENTRYPOINT [ "./buildInDocker.sh" ]

samples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Building a container:
4646
* runSample.*.Dockerfile : Instructions to create containers with runtime dependencies
4747
* runSample.gomod : Copied into the container as `go.mod`
4848
Two variants of the Dockerfile are provided. Set the `FROM` environment variable to "UBI"
49-
to use Red Hat Universal Base Images as the starting points for building and runtime;
50-
otherwise an Ubuntu/Debian combination is used.
49+
to use Red Hat Universal Base Images as the starting points for building and runtime; set it to
50+
"DEP" to use a Ubuntu/Debian combination.
5151

5252
The `mqitest` sample program in its own subdirectory is a more general demonstration
5353
of many of the features available from the MQI rather than focussed on a specific

samples/runSample.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
# This is an example of running one of the sample programs in a container.
24

35
function latestSemVer {
@@ -31,13 +33,13 @@ echo Building container with tag $TAG:$VER
3133

3234
# Build the container which includes compilation of the program. Can set the FROM
3335
# environment variable outside this script to choose which base image to work from.
34-
# The UBI variant is built on the Red Hat Universal Base Image set of containers; the
35-
# default is built on Ubuntu/Debian containers.
36-
if [ "$FROM" = "UBI" ]
36+
# The UBI default variant is built on the Red Hat Universal Base Image set of containers;
37+
# the alternative is built on Ubuntu/Debian containers.
38+
if [ "$FROM" = "DEB" ]
3739
then
38-
dfile="runSample.ubi.Dockerfile"
39-
else
4040
dfile="runSample.deb.Dockerfile"
41+
else
42+
dfile="runSample.ubi.Dockerfile"
4143
fi
4244

4345
# Setting NOCACHE environment variable will force a complete rebuild of the container
@@ -64,7 +66,7 @@ then
6466
then
6567
# Run the container. Can override default command line values in amqsput via
6668
# env vars here.
67-
docker run -e MQSERVER="SYSTEM.DEF.SVRCONN/TCP/$addr($port)" \
69+
docker run --rm -e MQSERVER="SYSTEM.DEF.SVRCONN/TCP/$addr($port)" \
6870
-e QUEUE=DEV.QUEUE.1 \
6971
-e QMGR=QM1 \
7072
$TAG:$VER

samples/runSample.ubi.Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#
2424
# The base images are taken from the Red Hat Universal Base Images repository
2525

26-
# Start by setting some global variables that can still be overridden on the build command line.
27-
ARG BASE_IMAGE=registry.access.redhat.com/ubi8/ubi
26+
# Start by setting some global variables that could still be overridden on the build command line.
27+
ARG BASE_IMAGE=registry.access.redhat.com/ubi8/go-toolset:1.21
2828
ARG GOPATH_ARG="/go"
2929

3030
###########################################################
@@ -35,15 +35,15 @@ FROM $BASE_IMAGE AS builder
3535
ARG GOPATH_ARG
3636
ENV GOPATH=$GOPATH_ARG \
3737
ORG="github.com/ibm-messaging"
38-
ARG GOVERSION=1.18
3938
ARG GOARCH=amd64
4039
ARG MQARCH=X64
4140

4241

43-
# Install the Go compiler and some other tools. The version of Go that
44-
# is available from the repository is new enough that we don't need to
45-
# explicitly pull it from Google. Installing Go also gives prereqs like the C compiler.
46-
RUN yum --disableplugin=subscription-manager -y install wget curl tar golang \
42+
# Make sure we install some other tools. The version of Go that
43+
# is available from this base image is new enough that we don't need to
44+
# explicitly pull a newer version from Google.
45+
USER 0
46+
RUN yum --disableplugin=subscription-manager -y install gzip curl tar \
4747
&& yum --disableplugin=subscription-manager clean all
4848

4949
# Create a location for the go programs and the MQ installation

0 commit comments

Comments
 (0)