|
| 1 | +# © Copyright IBM Corporation 2019, 2021 |
| 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 | + |
| 16 | +# This Dockerfile has two separate stages. |
| 17 | +# |
| 18 | +# The first stage is used to compile the Go program, where we need tools like the Go and C compilers. |
| 19 | +# The second stage is a runtime-only container that holds just the things we need to |
| 20 | +# execute the compiled program. |
| 21 | +# |
| 22 | +# Files and directories are copied from the builder container to the runtime container as needed. |
| 23 | +# |
| 24 | +# The base images are taken from the Red Hat Universal Base Images repository |
| 25 | + |
| 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 |
| 28 | +ARG GOPATH_ARG="/go" |
| 29 | + |
| 30 | +########################################################### |
| 31 | +# This starts the BUILD phase |
| 32 | +########################################################### |
| 33 | +FROM $BASE_IMAGE AS builder |
| 34 | + |
| 35 | +ARG GOPATH_ARG |
| 36 | +ENV GOPATH=$GOPATH_ARG \ |
| 37 | + ORG="github.com/ibm-messaging" |
| 38 | + |
| 39 | +# Install the Go compiler and some other tools. The version of Go that |
| 40 | +# is available from the repository is new enough that we don't need to |
| 41 | +# explicitly pull it from Google. Installing Go also gives prereqs like the C compiler. |
| 42 | +RUN yum --disableplugin=subscription-manager -y install wget curl tar golang \ |
| 43 | + && yum --disableplugin=subscription-manager clean all |
| 44 | + |
| 45 | +# Create a location for the go programs and the MQ installation |
| 46 | +RUN mkdir -p $GOPATH/src $GOPATH/bin $GOPATH/pkg \ |
| 47 | + && chmod -R 777 $GOPATH \ |
| 48 | + && cd /tmp \ |
| 49 | + && mkdir -p /opt/mqm \ |
| 50 | + && chmod a+rx /opt/mqm |
| 51 | + |
| 52 | +# Location of the downloadable MQ client package \ |
| 53 | +ENV RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \ |
| 54 | + RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \ |
| 55 | + VRMF=9.2.3.0 |
| 56 | + |
| 57 | +# Install the MQ client from the Redistributable package. This also contains the |
| 58 | +# header files we need to compile against. Setup the subset of the package |
| 59 | +# we are going to keep - the genmqpkg.sh script removes unneeded parts |
| 60 | +ENV genmqpkg_incnls=1 \ |
| 61 | + genmqpkg_incsdk=1 \ |
| 62 | + genmqpkg_inctls=1 |
| 63 | + |
| 64 | +RUN cd /opt/mqm \ |
| 65 | + && curl -LO "$RDURL/$VRMF-$RDTAR" \ |
| 66 | + && tar -zxf ./*.tar.gz \ |
| 67 | + && rm -f ./*.tar.gz \ |
| 68 | + && bin/genmqpkg.sh -b /opt/mqm |
| 69 | + |
| 70 | +ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| 71 | + |
| 72 | +# Copy the source file over. We also need a go.mod file |
| 73 | +# The source for that has a different name in the repo so it doesn't accidentally get |
| 74 | +# used. We rename it during this copy. |
| 75 | +COPY amqsput.go $GOPATH_ARG/src |
| 76 | +COPY runSample.gomod $GOPATH_ARG/src/go.mod |
| 77 | + |
| 78 | +# Do the actual compile. This will automatically download the ibmmq package |
| 79 | +RUN cd $GOPATH_ARG/src && go build -o $GOPATH_ARG/bin/amqsput amqsput.go |
| 80 | + |
| 81 | +########################################################### |
| 82 | +# This starts the RUNTIME phase |
| 83 | +########################################################### |
| 84 | +# Now that there is a container with the compiled program we can build a smaller |
| 85 | +# runtime image. Start from one of the smaller base container images. |
| 86 | +FROM registry.access.redhat.com/ubi8/ubi-minimal |
| 87 | +ARG GOPATH_ARG |
| 88 | + |
| 89 | +# Copy over the MQ runtime client code. This does preserve the .h files used during compile |
| 90 | +# but those are tiny so there's no real space-saving from deleting them here. |
| 91 | +COPY --from=builder /opt/mqm /opt/mqm |
| 92 | + |
| 93 | +# Create some directories that may be needed at runtime, depending on the container's |
| 94 | +# security environment. |
| 95 | +RUN mkdir -p /IBM/MQ/data/errors \ |
| 96 | + && mkdir -p /.mqm \ |
| 97 | + && chmod -R 777 /IBM \ |
| 98 | + && chmod -R 777 /.mqm \ |
| 99 | + && mkdir -p /go/bin |
| 100 | + |
| 101 | +# The actual program has all of the Go runtime embedded; we only need the single |
| 102 | +# binary along with the MQ client libraries, for it to run. |
| 103 | +COPY --from=builder $GOPATH_ARG/bin/amqsput /go/bin/amqsput |
| 104 | + |
| 105 | +# The startup script will set MQSERVER and optionally set more |
| 106 | +# environment variables that will be passed to amqsput through this entrypoint. |
| 107 | +ENTRYPOINT [ "/go/bin/amqsput" ] |
0 commit comments