Buildah containerized Go build
This commit is contained in:
committed by
Robert Parker
parent
d2ea8d4f06
commit
e66bcfd77f
11
incubating/mq-advanced-server-rhel/go-build.sh
Executable file
11
incubating/mq-advanced-server-rhel/go-build.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Build and test the Go code
|
||||
go build ./cmd/runmqserver/
|
||||
go build ./cmd/chkmqready/
|
||||
go build ./cmd/chkmqhealthy/
|
||||
go test -v ./cmd/runmqserver/
|
||||
go test -v ./cmd/chkmqready/
|
||||
go test -v ./cmd/chkmqhealthy/
|
||||
go test -v ./internal/...
|
||||
go vet ./cmd/... ./internal/...
|
||||
35
incubating/mq-advanced-server-rhel/go-buildah.sh
Executable file
35
incubating/mq-advanced-server-rhel/go-buildah.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh -*-
|
||||
# © Copyright IBM Corporation 2018
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
readonly tag=$1
|
||||
|
||||
if [[ $* < 1 ]]; then
|
||||
printf "Usage: $0 TAG\n" >&2
|
||||
printf "Where:\n" >&2
|
||||
printf " TAG\tTag for image containing MQ SDK and Go compiler\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy the go-build.sh script into the Go builder image
|
||||
install --mode 0755 go-build.sh $mnt/usr/local/bin/
|
||||
# Run the Go build script inside the Go container, mounting the source
|
||||
# directory in
|
||||
podman run \
|
||||
--volume ${PWD}/../..:/go/src/github.com/ibm-messaging/mq-container/ \
|
||||
--env GOPATH=/go \
|
||||
${tag} \
|
||||
bash -c "cd /go/src/github.com/ibm-messaging/mq-container/ && ./incubating/mq-advanced-server-rhel/go-build.sh"
|
||||
68
incubating/mq-advanced-server-rhel/install-mq-rhel.sh
Executable file
68
incubating/mq-advanced-server-rhel/install-mq-rhel.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh -*-
|
||||
# © Copyright IBM Corporation 2018
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Install one or more MQ components into a buildah container
|
||||
|
||||
set -ex
|
||||
|
||||
readonly ctr=$1
|
||||
readonly scratchmnt=$2
|
||||
readonly archive=$3
|
||||
readonly mq_packages=$4
|
||||
readonly dir_extract=/tmp/extract
|
||||
|
||||
if [[ $* < 3 ]]; then
|
||||
printf "Usage: $0 container mount-dir mq-archive mq-packages\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
groupadd --root $scratchmnt --system --gid 888 mqm
|
||||
useradd --root $scratchmnt --system --uid 888 --gid mqm mqm
|
||||
usermod --root $scratchmnt -G root mqm
|
||||
|
||||
if [ ! -d ${dir_extract} ]; then
|
||||
mkdir -p ${dir_extract}
|
||||
tar -zxvf $archive -C ${dir_extract}
|
||||
fi
|
||||
#DIR_RPM=$(find ${dir_extract} -name "*.rpm" -printf "%h\n" | sort -u | head -1)
|
||||
#DIR_RPM=${DIR_RPM#$dir_extract}
|
||||
#DIR_RPM=$(buildah run $ctr -- find ${dir_extract} -name "*.rpm" -printf "%h\n" | sort -u | head -1)
|
||||
# Find location of mqlicense.sh
|
||||
#MQLICENSE=$(buildah run $ctr -- find ${dir_extract} -name "mqlicense.sh")
|
||||
#MQLICENSE=$(find ${dir_extract} -name "mqlicense.sh")
|
||||
#MQLICENSE=${MQLICENSE#dir_extract}
|
||||
|
||||
# Accept the MQ license
|
||||
buildah run --volume ${dir_extract}:/mnt/mq-download $ctr -- /mnt/mq-download/MQServer/mqlicense.sh -text_only -accept
|
||||
|
||||
buildah run --volume ${dir_extract}:/mnt/mq-download $ctr -- bash -c "cd /mnt/mq-download/MQServer && rpm -ivh $mq_packages"
|
||||
|
||||
#rm -rf ${dir_extract}
|
||||
|
||||
# Remove 32-bit libraries from 64-bit container
|
||||
find $scratchmnt/opt/mqm $scratchmnt/var/mqm -type f -exec file {} \; | awk -F: '/ELF 32-bit/{print $1}' | xargs --no-run-if-empty rm -f
|
||||
|
||||
# Remove tar.gz files unpacked by RPM postinst scripts
|
||||
find $scratchmnt/opt/mqm -name '*.tar.gz' -delete
|
||||
|
||||
# Recommended: Set the default MQ installation (makes the MQ commands available on the PATH)
|
||||
buildah run $ctr -- /opt/mqm/bin/setmqinst -p /opt/mqm -i
|
||||
|
||||
# Optional: Set these values for the IBM Cloud Vulnerability Report
|
||||
sed -i 's/PASS_MAX_DAYS\t99999/PASS_MAX_DAYS\t90/' $scratchmnt/etc/login.defs
|
||||
sed -i 's/PASS_MIN_DAYS\t0/PASS_MIN_DAYS\t1/' $scratchmnt/etc/login.defs
|
||||
sed -i 's/password\t\[success=1 default=ignore\]\tpam_unix\.so obscure sha512/password\t[success=1 default=ignore]\tpam_unix.so obscure sha512 minlen=8/' $scratchmnt/etc/pam.d/password-auth
|
||||
116
incubating/mq-advanced-server-rhel/mq-buildah.sh
Executable file
116
incubating/mq-advanced-server-rhel/mq-buildah.sh
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh -*-
|
||||
# © Copyright IBM Corporation 2018
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Build a RHEL image, using the buildah tool
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
MQ_ARCHIVE=downloads/mqadv_dev910_linux_x86-64.tar.gz
|
||||
|
||||
###############################################################################
|
||||
# Setup MQ server working container
|
||||
###############################################################################
|
||||
|
||||
# Use a "scratch" container, so the resulting image has minimal files
|
||||
# Resulting image won't have yum, for example
|
||||
readonly ctr_mq=$(buildah from scratch)
|
||||
readonly mnt_mq=$(buildah mount $ctr_mq)
|
||||
|
||||
# Initialize yum for use with the scratch container
|
||||
rpm --root $mnt_mq --initdb
|
||||
|
||||
# TODO: eek
|
||||
yum install yum-utils
|
||||
yumdownloader --destdir=/tmp redhat-release-server
|
||||
rpm --root $mnt_mq -ihv /tmp/redhat-release-server*.rpm || true
|
||||
|
||||
###############################################################################
|
||||
# Install MQ server
|
||||
###############################################################################
|
||||
|
||||
# Install the packages required by MQ
|
||||
yum install -y --installroot=${mnt_mq} --releasever 7 --setopt install_weak_deps=false --setopt=tsflags=nodocs --setopt=override_install_langs=en_US.utf8 \
|
||||
bash \
|
||||
bc \
|
||||
coreutils \
|
||||
file \
|
||||
findutils \
|
||||
gawk \
|
||||
glibc-common \
|
||||
grep \
|
||||
passwd \
|
||||
procps-ng \
|
||||
sed \
|
||||
tar \
|
||||
util-linux
|
||||
|
||||
# Clean up cached files
|
||||
yum clean all --installroot=${mnt_mq} --releasever 7
|
||||
rm -rf ${mnt_mq}/var/cache/yum/*
|
||||
|
||||
# Install MQ server packages into the MQ builder image
|
||||
./install-mq-rhel.sh ${ctr_mq} "${mnt_mq}" "${MQ_ARCHIVE}" "MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm"
|
||||
|
||||
# Remove the directory structure under /var/mqm which was created by the installer
|
||||
rm -rf ${mnt_mq}/var/mqm
|
||||
|
||||
# Create the mount point for volumes
|
||||
mkdir -p ${mnt_mq}/mnt/mqm
|
||||
|
||||
# Create the directory for MQ configuration files
|
||||
mkdir -p ${mnt_mq}/etc/mqm
|
||||
|
||||
# Create a symlink for /var/mqm -> /mnt/mqm/data
|
||||
buildah run $ctr ln -s /mnt/mqm/data /var/mqm
|
||||
|
||||
# Install the Go binaries into the image
|
||||
install --mode 0750 --owner 888 --group 888 ../../runmqserver ${mnt_mq}/usr/local/bin/
|
||||
install --mode 6750 --owner 888 --group 888 ../../chk* ${mnt_mq}/usr/local/bin/
|
||||
install --mode 0750 --owner 888 --group 888 ../../NOTICES.txt ${mnt_mq}/opt/mqm/licenses/notices-container.txt
|
||||
# cp runmqserver $mnt_mq/usr/local/bin/
|
||||
# cp chkmq* $mnt_mq/usr/local/bin/
|
||||
# cp NOTICES.txt $mnt_mq/opt/mqm/licenses/notices-container.txt
|
||||
# chmod ug+x $mnt_mq/usr/local/bin/runmqserver
|
||||
# chown mqm:mqm $mnt_mq/usr/local/bin/*mq*
|
||||
# chmod ug+xs $mnt_mq/usr/local/bin/chkmq*
|
||||
|
||||
###############################################################################
|
||||
# Final Buildah commands
|
||||
###############################################################################
|
||||
|
||||
buildah config \
|
||||
--port 1414/tcp \
|
||||
--port 9157/tcp \
|
||||
--os linux \
|
||||
--label architecture=x86_64 \
|
||||
--label io.openshift.tags="mq messaging" \
|
||||
--label io.k8s.display-name="IBM MQ Advanced Server" \
|
||||
--label io.k8s.description="IBM MQ is messaging middleware that simplifies and accelerates the integration of diverse applications and business data across multiple platforms. It uses message queues to facilitate the exchanges of information and offers a single messaging solution for cloud, mobile, Internet of Things (IoT) and on-premises environments." \
|
||||
--label name="mqadvanced-server" \
|
||||
--label vendor="IBM" \
|
||||
--label version="9.1.0.0" \
|
||||
--env AMQ_ADDITIONAL_JSON_LOG=1 \
|
||||
--env LANG=en_US.UTF-8 \
|
||||
--env LOG_FORMAT=basic \
|
||||
--entrypoint runmqserver \
|
||||
--user 888 \
|
||||
$ctr_mq
|
||||
buildah unmount $ctr_mq
|
||||
buildah commit $ctr_mq mymq
|
||||
|
||||
# TODO: Leaves the working container lying around. Good for dev.
|
||||
46
incubating/mq-advanced-server-rhel/mq-golang-sdk-buildah.sh
Executable file
46
incubating/mq-advanced-server-rhel/mq-golang-sdk-buildah.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: sh -*-
|
||||
# © Copyright IBM Corporation 2018
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Build a RHEL image for building Go programs which use MQ
|
||||
|
||||
set -ex
|
||||
readonly mq_archive=downloads/mqadv_dev910_linux_x86-64.tar.gz
|
||||
# Use plain RHEL 7 container
|
||||
# Note: Red Hat's devtools/go-toolset-7-rhel7 image doesn't allow use of 'root'
|
||||
# user required for installing the MQ SDK
|
||||
readonly ctr=$(buildah from rhel7)
|
||||
readonly mnt=$(buildah mount $ctr)
|
||||
readonly tag=mq-golang-sdk
|
||||
# Enable Yum repository for "optional" RPMs, which is needed for "golang"
|
||||
buildah run ${ctr} -- yum-config-manager --enable rhel-7-server-optional-rpms
|
||||
# Install Go compiler
|
||||
buildah run ${ctr} -- yum install -y golang git gcc
|
||||
# Install the MQ SDK into the Go builder image
|
||||
./install-mq-rhel.sh ${ctr} "${mnt}" "${mq_archive}" "MQSeriesRuntime-*.rpm MQSeriesSDK-*.rpm"
|
||||
# Clean up Yum files
|
||||
buildah run ${ctr} -- yum clean all --releasever 7
|
||||
rm -rf ${mnt}/var/cache/yum/*
|
||||
buildah unmount ${ctr}
|
||||
# Set environment variables for MQ/Go compilation
|
||||
buildah config \
|
||||
--os linux \
|
||||
--env CGO_CFLAGS="-I/opt/mqm/inc/" \
|
||||
--env CGO_LDFLAGS_ALLOW="-Wl,-rpath.*" \
|
||||
${ctr}
|
||||
buildah commit ${ctr} ${tag}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user