From d2ea8d4f06a2cb31724c8a85949e60698527cda4 Mon Sep 17 00:00:00 2001 From: Rob Parker Date: Mon, 20 Aug 2018 13:49:10 +0100 Subject: [PATCH] Create IBM MQ RHEL Buildah build (#192) * Buildah containerized Go build * Minor fixes to buildah build * Move and rename files for RHEL build * Create MQ RHEL buildah build --- Makefile | 318 +++--------------- Makefile-RHEL | 145 ++++++++ Makefile-UBUNTU | 299 ++++++++++++++++ .../ansible/.gitignore | 1 - .../ansible/rhel-build.yaml | 62 ---- incubating/mq-advanced-server-rhel/buildah.sh | 141 -------- .../README.md | 0 mq-advanced-server-rhel/go-build.sh | 47 +++ mq-advanced-server-rhel/go-buildah.sh | 34 ++ mq-advanced-server-rhel/install-mq-rhel.sh | 62 ++++ mq-advanced-server-rhel/mq-buildah.sh | 115 +++++++ .../mq-golang-sdk-buildah.sh | 45 +++ mq-advanced-server-rhel/mqdev-buildah.sh | 81 +++++ 13 files changed, 880 insertions(+), 470 deletions(-) create mode 100644 Makefile-RHEL create mode 100644 Makefile-UBUNTU delete mode 100644 incubating/mq-advanced-server-rhel/ansible/.gitignore delete mode 100644 incubating/mq-advanced-server-rhel/ansible/rhel-build.yaml delete mode 100644 incubating/mq-advanced-server-rhel/buildah.sh rename {incubating/mq-advanced-server-rhel => mq-advanced-server-rhel}/README.md (100%) create mode 100755 mq-advanced-server-rhel/go-build.sh create mode 100755 mq-advanced-server-rhel/go-buildah.sh create mode 100755 mq-advanced-server-rhel/install-mq-rhel.sh create mode 100755 mq-advanced-server-rhel/mq-buildah.sh create mode 100755 mq-advanced-server-rhel/mq-golang-sdk-buildah.sh create mode 100755 mq-advanced-server-rhel/mqdev-buildah.sh diff --git a/Makefile b/Makefile index 4250d73..73e6fe4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# © Copyright IBM Corporation 2017, 2018 +# © 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. @@ -12,288 +12,74 @@ # See the License for the specific language governing permissions and # limitations under the License. -############################################################################### -# Conditional variables - you can override the values of these variables from -# the command line -############################################################################### -# BASE_IMAGE is the base image to use for MQ, for example "ubuntu" or "rhel" -BASE_IMAGE ?= ubuntu:16.04 -# MQ_VERSION is the fully qualified MQ version number to build -MQ_VERSION ?= 9.1.0.0 -# MQ_ARCHIVE is the name of the file, under the downloads directory, from which MQ Advanced can -# be installed. The default value is derived from MQ_VERSION, BASE_IMAGE and architecture -# Does not apply to MQ Advanced for Developers. -MQ_ARCHIVE ?= IBM_MQ_$(MQ_VERSION)_$(MQ_ARCHIVE_TYPE)_$(MQ_ARCHIVE_ARCH).tar.gz -# MQ_ARCHIVE_DEV is the name of the file, under the downloads directory, from which MQ Advanced -# for Developers can be installed -MQ_ARCHIVE_DEV ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) -# MQ_SDK_ARCHIVE specifies the archive to use for building the golang programs. Defaults vary on developer or advanced. -MQ_SDK_ARCHIVE ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) -# Options to `go test` for the Docker tests -TEST_OPTS_DOCKER ?= -# MQ_IMAGE_ADVANCEDSERVER is the name and tag of the built MQ Advanced image -MQ_IMAGE_ADVANCEDSERVER ?=mqadvanced-server:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) -# MQ_IMAGE_DEVSERVER is the name and tag of the built MQ Advanced for Developers image -MQ_IMAGE_DEVSERVER ?=mqadvanced-server-dev:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) -# MQ_IMAGE_SDK is the name and tag of the built MQ Advanced for Developers SDK image -MQ_IMAGE_SDK ?=mq-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) -# MQ_IMAGE_GOLANG_SDK is the name and tag of the built MQ Advanced for Developers SDK image, plus Go tools -MQ_IMAGE_GOLANG_SDK ?=mq-golang-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) -# DOCKER is the Docker command to run -DOCKER ?= docker -# MQ_PACKAGES specifies the MQ packages (.deb or .rpm) to install. Defaults vary on base image. -MQ_PACKAGES ?= - -############################################################################### -# Other variables -############################################################################### -# ARCH is the platform architecture (e.g. x86_64, ppc64le or s390x) -ARCH = $(shell uname -m) -# BUILD_SERVER_CONTAINER is the name of the web server container used at build time -BUILD_SERVER_CONTAINER=build-server -# NUM_CPU is the number of CPUs available to Docker. Used to control how many -# test run in parallel -NUM_CPU = $(or $(shell docker info --format "{{ .NCPU }}"),2) -# BASE_IMAGE_TAG is a normalized version of BASE_IMAGE, suitable for use in a Docker tag -BASE_IMAGE_TAG=$(subst /,-,$(subst :,-,$(BASE_IMAGE))) -MQ_IMAGE_DEVSERVER_BASE=mqadvanced-server-dev-base:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) -# Docker image name to use for JMS tests -DEV_JMS_IMAGE=mq-dev-jms-test -# Variables for versioning -IMAGE_REVISION=$(shell git rev-parse HEAD) -IMAGE_SOURCE=$(shell git config --get remote.origin.url) - -ifneq (,$(findstring Microsoft,$(shell uname -r))) - DOWNLOADS_DIR=$(patsubst /mnt/c%,C:%,$(realpath ./downloads/)) -else - DOWNLOADS_DIR=$(realpath ./downloads/) -endif - -# Try to figure out which archive to use from the BASE_IMAGE -ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" - MQ_ARCHIVE_TYPE=UBUNTU - MQ_ARCHIVE_DEV_PLATFORM=ubuntu -else - MQ_ARCHIVE_TYPE=LINUX - MQ_ARCHIVE_DEV_PLATFORM=linux -endif -# Try to figure out which archive to use from the architecture -ifeq "$(ARCH)" "x86_64" - MQ_ARCHIVE_ARCH=X86-64 - MQ_DEV_ARCH=x86-64 -else ifeq "$(ARCH)" "ppc64le" - MQ_ARCHIVE_ARCH=LE_POWER - MQ_DEV_ARCH=ppcle -else ifeq "$(ARCH)" "s390x" - MQ_ARCHIVE_ARCH=SYSTEM_Z - MQ_DEV_ARCH=s390x -endif -# Archive names for IBM MQ Advanced for Developers -MQ_ARCHIVE_DEV_9.0.5.0=mqadv_dev905_$(MQ_ARCHIVE_DEV_PLATFORM)_x86-64.tar.gz -MQ_ARCHIVE_DEV_9.1.0.0=mqadv_dev910_$(MQ_ARCHIVE_DEV_PLATFORM)_$(MQ_DEV_ARCH).tar.gz - ############################################################################### # Build targets ############################################################################### -.PHONY: vars -vars: -#ifeq "$(findstring ubuntu,$(BASE_IMAGE))","ubuntu" - @echo $(MQ_ARCHIVE_ARCH) - @echo $(MQ_ARCHIVE_TYPE) - @echo $(MQ_ARCHIVE) -.PHONY: default -default: build-devserver test +# default to building UBUNTU as this was the default for the previous Makefile +.PHONY: build-devserver +build-devserver: build-devserver-ubuntu -# Build all components (except incubating ones) -.PHONY: all -all: build-devserver build-advancedserver +.PHONY: build-advancedserver +build-advancedserver: build-advancedserver-ubuntu -.PHONY: test-all -test-all: test-devserver test-advancedserver - -.PHONY: precommit -precommit: fmt lint all test-all - -.PHONY: devserver -devserver: build-devserver test-devserver - -# Build incubating components -.PHONY: incubating -incubating: build-explorer - -.PHONY: clean -clean: - rm -rf ./coverage - rm -rf ./build - rm -rf ./deps - -downloads/$(MQ_ARCHIVE_DEV): - $(info $(SPACER)$(shell printf $(TITLE)"Downloading IBM MQ Advanced for Developers "$(MQ_VERSION)$(END))) - mkdir -p downloads - cd downloads; curl -LO https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/$(MQ_ARCHIVE_DEV) - -downloads/$(MQ_SDK_ARCHIVE): - $(info $(SPACER)$(shell printf $(TITLE)"Downloading IBM MQ Advanced for Developers "$(MQ_VERSION)$(END))) - mkdir -p downloads - cd downloads; curl -LO https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/$(MQ_SDK_ARCHIVE) - -.PHONY: downloads -downloads: downloads/$(MQ_ARCHIVE_DEV) downloads/$(MQ_SDK_ARCHIVE) - -.PHONY: deps -deps: - glide install --strip-vendor - -# Vendor Go dependencies for the Docker tests -test/docker/vendor: - cd test/docker && dep ensure -vendor-only - -.PHONY: build-cov -build-cov: - mkdir -p build - cd build; go test -c -covermode=count ../cmd/runmqserver - -# Shortcut to just run the unit tests -.PHONY: test-unit -test-unit: - docker build --target builder --file Dockerfile-server . +.PHONY: test-devserver +test-devserver: test-devserver-ubuntu .PHONY: test-advancedserver -test-advancedserver: test/docker/vendor - $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) on $(shell docker --version)"$(END))) - cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) EXPECTED_LICENSE=Production go test -parallel $(NUM_CPU) $(TEST_OPTS_DOCKER) +test-advancedserver: test-advancedserver-ubuntu + +.PHONY: deps +deps: deps-ubuntu + +.PHONY: lint +lint: lint-ubuntu + +# UBUNTU building targets +.PHONY: build-devserver-ubuntu +build-devserver-ubuntu: + $(MAKE) -f Makefile-UBUNTU build-devserver + +.PHONY: test-devserver-ubuntu +test-devserver-ubuntu: + $(MAKE) -f Makefile-UBUNTU test-devserver .PHONY: build-devjmstest build-devjmstest: - $(info $(SPACER)$(shell printf $(TITLE)"Build JMS tests for developer config"$(END))) - cd test/messaging && docker build --tag $(DEV_JMS_IMAGE) . + $(MAKE) -f Makefile-UBUNTU build-devjmstest -.PHONY: test-devserver -test-devserver: test/docker/vendor - $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_DEVSERVER) on $(shell docker --version)"$(END))) - cd test/docker && TEST_IMAGE=$(MQ_IMAGE_DEVSERVER) EXPECTED_LICENSE=Developer DEV_JMS_IMAGE=$(DEV_JMS_IMAGE) go test -parallel $(NUM_CPU) -tags mqdev $(TEST_OPTS_DOCKER) +.PHONY: build-devjmstest-ubuntu + $(MAKE) -f Makefile-UBUNTU build-devjmstest -coverage: - mkdir coverage +.PHONY: build-advancedserver-ubuntu +build-advancedserver-ubuntu: + $(MAKE) -f Makefile-UBUNTU build-advancedserver -.PHONY: test-advancedserver-cover -test-advancedserver-cover: test/docker/vendor coverage - $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) with code coverage on $(shell docker --version)"$(END))) - rm -f ./coverage/unit*.cov - # Run unit tests with coverage, for each package under 'internal' - go list -f '{{.Name}}' ./internal/... | xargs -I {} go test -cover -covermode count -coverprofile ./coverage/unit-{}.cov ./internal/{} -# ls -1 ./cmd | xargs -I {} go test -cover -covermode count -coverprofile ./coverage/unit-{}.cov ./cmd/{}/... - echo 'mode: count' > ./coverage/unit.cov - tail -q -n +2 ./coverage/unit-*.cov >> ./coverage/unit.cov - go tool cover -html=./coverage/unit.cov -o ./coverage/unit.html +.PHONY: test-advancedserver-ubuntu +test-advancedserver-ubuntu: + $(MAKE) -f Makefile-UBUNTU test-advancedserver - rm -f ./test/docker/coverage/*.cov - rm -f ./coverage/docker.* - mkdir -p ./test/docker/coverage/ - cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER)-cover TEST_COVER=true go test $(TEST_OPTS_DOCKER) - echo 'mode: count' > ./coverage/docker.cov - tail -q -n +2 ./test/docker/coverage/*.cov >> ./coverage/docker.cov - go tool cover -html=./coverage/docker.cov -o ./coverage/docker.html +.PHONY: deps-ubuntu +deps-ubuntu: + $(MAKE) -f Makefile-UBUNTU deps - echo 'mode: count' > ./coverage/combined.cov - tail -q -n +2 ./coverage/unit.cov ./coverage/docker.cov >> ./coverage/combined.cov - go tool cover -html=./coverage/combined.cov -o ./coverage/combined.html +.PHONY: lint-ubuntu +lint-ubuntu: + $(MAKE) -f Makefile-UBUNTU lint -define docker-build-mq - # Create a temporary network to use for the build - $(DOCKER) network create build - # Start a web server to host the MQ downloadable (tar.gz) file - $(DOCKER) run \ - --rm \ - --name $(BUILD_SERVER_CONTAINER) \ - --network build \ - --network-alias build \ - --volume $(DOWNLOADS_DIR):/usr/share/nginx/html:ro \ - --detach \ - nginx:alpine - # Build the new image - $(DOCKER) build \ - --tag $1 \ - --file $2 \ - --network build \ - --build-arg MQ_URL=http://build:80/$3 \ - --build-arg BASE_IMAGE=$(BASE_IMAGE) \ - --build-arg BUILDER_IMAGE=$(MQ_IMAGE_GOLANG_SDK) \ - --build-arg IMAGE_REVISION="$(IMAGE_REVISION)" \ - --build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" \ - --label IBM_PRODUCT_ID=$4 \ - --label IBM_PRODUCT_NAME=$5 \ - --label IBM_PRODUCT_VERSION=$6 \ - --build-arg MQ_PACKAGES="$(MQ_PACKAGES)" \ - . ; $(DOCKER) kill $(BUILD_SERVER_CONTAINER) && $(DOCKER) network rm build -endef +# RHEL building targets +.PHONY: build-devserver-rhel +build-devserver-rhel: + $(MAKE) -f Makefile-RHEL build-devserver -DOCKER_SERVER_VERSION=$(shell docker version --format "{{ .Server.Version }}") -DOCKER_CLIENT_VERSION=$(shell docker version --format "{{ .Client.Version }}") -.PHONY: docker-version -docker-version: - @test "$(word 1,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "17" || ("$(word 1,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -eq "17" && "$(word 2,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "05") || (echo "Error: Docker client 17.05 or greater is required" && exit 1) - @test "$(word 1,$(subst ., ,$(DOCKER_SERVER_VERSION)))" -ge "17" || ("$(word 1,$(subst ., ,$(DOCKER_SERVER_VERSION)))" -eq "17" && "$(word 2,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "05") || (echo "Error: Docker server 17.05 or greater is required" && exit 1) +.PHONY: test-devserver-rhel +test-devserver-rhel: + $(MAKE) -f Makefile-RHEL test-devserver -.PHONY: build-advancedserver -build-advancedserver: MQ_SDK_ARCHIVE=$(MQ_ARCHIVE) -build-advancedserver: downloads/$(MQ_ARCHIVE) docker-version build-golang-sdk-ex - $(info $(SPACER)$(shell printf $(TITLE)"Build $(MQ_IMAGE_ADVANCEDSERVER)"$(END))) - $(call docker-build-mq,$(MQ_IMAGE_ADVANCEDSERVER),Dockerfile-server,$(MQ_ARCHIVE),"4486e8c4cc9146fd9b3ce1f14a2dfc5b","IBM MQ Advanced",$(MQ_VERSION)) +.PHONY: build-advancedserver-rhel +build-advancedserver-rhel: + $(MAKE) -f Makefile-RHEL build-advancedserver -.PHONY: build-devserver -# Target-specific variable to add web server into devserver image -ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" -build-devserver: MQ_PACKAGES=ibmmq-server ibmmq-java ibmmq-jre ibmmq-gskit ibmmq-msg-.* ibmmq-samples ibmmq-ams ibmmq-web -else -build-devserver: MQ_PACKAGES=MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm MQSeriesWeb-*.rpm -endif -build-devserver: MQ_SDK_ARCHIVE=$(MQ_ARCHIVE_DEV) -build-devserver: downloads/$(MQ_ARCHIVE_DEV) docker-version build-golang-sdk-ex - $(info $(shell printf $(TITLE)"Build $(MQ_IMAGE_DEVSERVER_BASE)"$(END))) - $(call docker-build-mq,$(MQ_IMAGE_DEVSERVER_BASE),Dockerfile-server,$(MQ_ARCHIVE_DEV),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)",$(MQ_VERSION)) - $(DOCKER) build --tag $(MQ_IMAGE_DEVSERVER) --build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" --build-arg IMAGE_REVISION="$(IMAGE_REVISION)" --build-arg BASE_IMAGE=$(MQ_IMAGE_DEVSERVER_BASE) --build-arg BUILDER_IMAGE=$(MQ_IMAGE_GOLANG_SDK) --file incubating/mqadvanced-server-dev/Dockerfile . - -.PHONY: build-advancedserver-cover -build-advancedserver-cover: docker-version - $(DOCKER) build --build-arg BASE_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) -t $(MQ_IMAGE_ADVANCEDSERVER)-cover -f Dockerfile-server.cover . - -.PHONY: build-explorer docker-pull -build-explorer: downloads/$(MQ_ARCHIVE_DEV) - $(call docker-build-mq,mq-explorer:latest-$(ARCH),incubating/mq-explorer/Dockerfile-mq-explorer,$(MQ_ARCHIVE_DEV),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)",$(MQ_VERSION)) - -.PHONY: build-sdk -build-sdk: downloads/$(MQ_SDK_ARCHIVE) build-sdk-ex - -.PHONY: build-sdk-ex -ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" -build-sdk-ex: MQ_PACKAGES=ibmmq-sdk ibmmq-samples build-essential -else -build-sdk-ex: MQ_PACKAGES=MQSeriesRuntime-*.rpm MQSeriesSDK-*.rpm MQSeriesSamples*.rpm -endif -build-sdk-ex: docker-version docker-pull - $(call docker-build-mq,$(MQ_IMAGE_SDK),incubating/mq-sdk/Dockerfile,$(MQ_SDK_ARCHIVE),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers SDK (Non-Warranted)",$(MQ_VERSION)) - -.PHONY: build-golang-sdk -build-golang-sdk: downloads/$(MQ_SDK_ARCHIVE) build-golang-sdk-ex - -.PHONY: build-golang-sdk-ex -build-golang-sdk-ex: docker-version build-sdk-ex - $(DOCKER) build --build-arg BASE_IMAGE=$(MQ_IMAGE_SDK) -t $(MQ_IMAGE_GOLANG_SDK) -f incubating/mq-golang-sdk/Dockerfile . -# $(call docker-build-mq,$(MQ_IMAGE_GOLANG_SDK),incubating/mq-golang-sdk/Dockerfile,$(MQ_IMAGE_SDK),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers SDK (Non-Warranted)",$(MQ_VERSION)) - -docker-pull: - $(DOCKER) pull $(BASE_IMAGE) - -GO_PKG_DIRS = ./cmd ./internal ./test - -fmt: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS)) - go fmt $(addsuffix /..., $(GO_PKG_DIRS)) - -lint: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS)) - @# This expression is necessary because /... includes the vendor directory in golint - @# As of 11/04/2018 there is an open issue to fix it: https://github.com/golang/lint/issues/320 - golint -set_exit_status $(sort $(dir $(wildcard $(addsuffix /*/*.go, $(GO_PKG_DIRS))))) - -include formatting.mk +.PHONY: test-advancedserver-rhel +test-advancedserver-rhel: + $(MAKE) -f Makefile-RHEL test-advancedserver diff --git a/Makefile-RHEL b/Makefile-RHEL new file mode 100644 index 0000000..4efa6cb --- /dev/null +++ b/Makefile-RHEL @@ -0,0 +1,145 @@ +# © 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. + +############################################################################### +# Conditional variables - you can override the values of these variables from +# the command line +############################################################################### +# BASE_IMAGE is the base image to use for MQ, for example "ubuntu" or "rhel" +BASE_IMAGE ?= rhel +# MQ_VERSION is the fully qualified MQ version number to build +MQ_VERSION ?= 9.1.0.0 +# MQ_ARCHIVE is the name of the file, under the downloads directory, from which MQ Advanced can +# be installed. The default value is derived from MQ_VERSION, BASE_IMAGE and architecture +# Does not apply to MQ Advanced for Developers. +MQ_ARCHIVE ?= IBM_MQ_$(MQ_VERSION)_LINUX_$(MQ_ARCHIVE_ARCH).tar.gz +# MQ_ARCHIVE_DEV is the name of the file, under the downloads directory, from which MQ Advanced +# for Developers can be installed +MQ_ARCHIVE_DEV ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) +# MQ_SDK_ARCHIVE specifies the archive to use for building the golang programs. Defaults vary on developer or advanced. +MQ_SDK_ARCHIVE ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) +# Options to `go test` for the Docker tests +TEST_OPTS_DOCKER ?= +# MQ_IMAGE_ADVANCEDSERVER is the name and tag of the built MQ Advanced image +MQ_IMAGE_ADVANCEDSERVER ?=mqadvanced-server:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_DEVSERVER is the name and tag of the built MQ Advanced for Developers image +MQ_IMAGE_DEVSERVER ?=mqadvanced-server-dev:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_SDK is the name and tag of the built MQ Advanced for Developers SDK image +MQ_IMAGE_SDK ?=mq-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_GOLANG_SDK is the name and tag of the built MQ Advanced for Developers SDK image, plus Go tools +MQ_IMAGE_GOLANG_SDK ?=mq-golang-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# DOCKER is the Docker command to run +DOCKER ?= podman +# MQ_PACKAGES specifies the MQ packages to install. Defaults vary on base image. +MQ_PACKAGES ?= MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm + +############################################################################### +# Other variables +############################################################################### +# ARCH is the platform architecture (e.g. x86_64, ppc64le or s390x) +ARCH = $(shell uname -m) +# BUILD_SERVER_CONTAINER is the name of the web server container used at build time +BUILD_SERVER_CONTAINER=build-server +# NUM_CPU is the number of CPUs available to Docker. Used to control how many +# test run in parallel +NUM_CPU = $(or $(shell docker info --format "{{ .NCPU }}"),2) +# BASE_IMAGE_TAG is a normalized version of BASE_IMAGE, suitable for use in a Docker tag +BASE_IMAGE_TAG=$(subst /,-,$(subst :,-,$(BASE_IMAGE))) +MQ_IMAGE_DEVSERVER_BASE=mqadvanced-server-dev-base:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# Docker image name to use for JMS tests +DEV_JMS_IMAGE=mq-dev-jms-test +# Variables for versioning +IMAGE_REVISION=$(shell git rev-parse HEAD) +IMAGE_SOURCE=$(shell git config --get remote.origin.url) +MQDEV= + + +ifneq (,$(findstring Microsoft,$(shell uname -r))) + DOWNLOADS_DIR=$(patsubst /mnt/c%,C:%,$(realpath ./downloads/)) +else + DOWNLOADS_DIR=$(realpath ./downloads/) +endif + +# Try to figure out which archive to use from the architecture +ifeq "$(ARCH)" "x86_64" + MQ_ARCHIVE_ARCH=X86-64 + MQ_DEV_ARCH=x86-64 +else ifeq "$(ARCH)" "ppc64le" + MQ_ARCHIVE_ARCH=LE_POWER + MQ_DEV_ARCH=ppcle +else ifeq "$(ARCH)" "s390x" + MQ_ARCHIVE_ARCH=SYSTEM_Z + MQ_DEV_ARCH=s390x +endif +# Archive names for IBM MQ Advanced for Developers +MQ_ARCHIVE_DEV_9.0.5.0=mqadv_dev905_linux_x86-64.tar.gz +MQ_ARCHIVE_DEV_9.1.0.0=mqadv_dev910_linux_$(MQ_DEV_ARCH).tar.gz + +############################################################################### +# Build targets +############################################################################### + +downloads/$(MQ_ARCHIVE_DEV): + $(info $(SPACER)$(shell printf $(TITLE)"Downloading IBM MQ Advanced for Developers "$(MQ_VERSION)$(END))) + mkdir -p downloads + cd downloads; curl -LO https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/$(MQ_ARCHIVE_DEV) + +.PHONY: downloads +downloads: downloads/$(MQ_ARCHIVE_DEV) + +.PHONY: check-prereqs +check-prereqs: + $(info $(SPACER)$(shell printf $(TITLE)"Checking for prereqs"$(END))) + which buildah || (echo "Missing required program buildah" && exit 1) + which podman || (echo "Missing required program podman" && exit 1) + yum list | grep yum-utils || (echo "Missing required package yum-utils" && exit 1) + + +.PHONY: test-advancedserver +test-advancedserver: + $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) on $(shell docker --version)"$(END))) + + +.PHONY: test-devserver +test-devserver: + $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_DEVSERVER) on $(shell docker --version)"$(END))) + + +.PHONY: build-advancedserver +build-advancedserver: check-prereqs downloads/$(MQ_ARCHIVE) build-go-programs + $(info $(SPACER)$(shell printf $(TITLE)"Build $(MQ_IMAGE_ADVANCEDSERVER)"$(END))) + mq-advanced-server-rhel/mq-buildah.sh "$(MQ_ARCHIVE)" "$(MQ_PACKAGES)" "$(MQ_IMAGE_ADVANCEDSERVER)" "$(MQ_VERSION)" "$(MQDEV)" + + +.PHONY: build-devserver +build-devserver: MQDEV=TRUE +build-devserver: MQ_PACKAGES=MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm MQSeriesWeb-*.rpm +build-devserver: check-prereqs downloads/$(MQ_ARCHIVE_DEV) build-go-programs + $(info $(SPACER)$(shell printf $(TITLE)"Build $(MQ_IMAGE_DEVSERVER)"$(END))) + mq-advanced-server-rhel/mq-buildah.sh "$(MQ_ARCHIVE_DEV)" "$(MQ_PACKAGES)" "$(MQ_IMAGE_DEVSERVER_BASE)" "$(MQ_VERSION)" "$(MQDEV)" + mq-advanced-server-rhel/mqdev-buildah.sh "$(MQ_IMAGE_DEVSERVER_BASE)" "$(MQ_IMAGE_DEVSERVER)" "$(MQ_VERSION)" + + +.PHONY: build-mqgolang-sdk +build-mqgolang-sdk: check-prereqs downloads/$(MQ_SDK_ARCHIVE) + $(info $(SPACER)$(shell printf $(TITLE)"Build mq-golang SDK"$(END))) + mq-advanced-server-rhel/mq-golang-sdk-buildah.sh "$(MQ_SDK_ARCHIVE)" "$(MQ_IMAGE_GOLANG_SDK)" + + +.PHONY: build-go-programs +build-go-programs: check-prereqs build-mqgolang-sdk + $(info $(SPACER)$(shell printf $(TITLE)"Build go programs"$(END))) + IMAGE_REVISION=$(IMAGE_REVISION) IMAGE_SOURCE=$(IMAGE_SOURCE) mq-advanced-server-rhel/go-buildah.sh "$(MQ_IMAGE_GOLANG_SDK)" "$(MQDEV)" + +include formatting.mk diff --git a/Makefile-UBUNTU b/Makefile-UBUNTU new file mode 100644 index 0000000..4250d73 --- /dev/null +++ b/Makefile-UBUNTU @@ -0,0 +1,299 @@ +# © Copyright IBM Corporation 2017, 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. + +############################################################################### +# Conditional variables - you can override the values of these variables from +# the command line +############################################################################### +# BASE_IMAGE is the base image to use for MQ, for example "ubuntu" or "rhel" +BASE_IMAGE ?= ubuntu:16.04 +# MQ_VERSION is the fully qualified MQ version number to build +MQ_VERSION ?= 9.1.0.0 +# MQ_ARCHIVE is the name of the file, under the downloads directory, from which MQ Advanced can +# be installed. The default value is derived from MQ_VERSION, BASE_IMAGE and architecture +# Does not apply to MQ Advanced for Developers. +MQ_ARCHIVE ?= IBM_MQ_$(MQ_VERSION)_$(MQ_ARCHIVE_TYPE)_$(MQ_ARCHIVE_ARCH).tar.gz +# MQ_ARCHIVE_DEV is the name of the file, under the downloads directory, from which MQ Advanced +# for Developers can be installed +MQ_ARCHIVE_DEV ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) +# MQ_SDK_ARCHIVE specifies the archive to use for building the golang programs. Defaults vary on developer or advanced. +MQ_SDK_ARCHIVE ?= $(MQ_ARCHIVE_DEV_$(MQ_VERSION)) +# Options to `go test` for the Docker tests +TEST_OPTS_DOCKER ?= +# MQ_IMAGE_ADVANCEDSERVER is the name and tag of the built MQ Advanced image +MQ_IMAGE_ADVANCEDSERVER ?=mqadvanced-server:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_DEVSERVER is the name and tag of the built MQ Advanced for Developers image +MQ_IMAGE_DEVSERVER ?=mqadvanced-server-dev:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_SDK is the name and tag of the built MQ Advanced for Developers SDK image +MQ_IMAGE_SDK ?=mq-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# MQ_IMAGE_GOLANG_SDK is the name and tag of the built MQ Advanced for Developers SDK image, plus Go tools +MQ_IMAGE_GOLANG_SDK ?=mq-golang-sdk:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# DOCKER is the Docker command to run +DOCKER ?= docker +# MQ_PACKAGES specifies the MQ packages (.deb or .rpm) to install. Defaults vary on base image. +MQ_PACKAGES ?= + +############################################################################### +# Other variables +############################################################################### +# ARCH is the platform architecture (e.g. x86_64, ppc64le or s390x) +ARCH = $(shell uname -m) +# BUILD_SERVER_CONTAINER is the name of the web server container used at build time +BUILD_SERVER_CONTAINER=build-server +# NUM_CPU is the number of CPUs available to Docker. Used to control how many +# test run in parallel +NUM_CPU = $(or $(shell docker info --format "{{ .NCPU }}"),2) +# BASE_IMAGE_TAG is a normalized version of BASE_IMAGE, suitable for use in a Docker tag +BASE_IMAGE_TAG=$(subst /,-,$(subst :,-,$(BASE_IMAGE))) +MQ_IMAGE_DEVSERVER_BASE=mqadvanced-server-dev-base:$(MQ_VERSION)-$(ARCH)-$(BASE_IMAGE_TAG) +# Docker image name to use for JMS tests +DEV_JMS_IMAGE=mq-dev-jms-test +# Variables for versioning +IMAGE_REVISION=$(shell git rev-parse HEAD) +IMAGE_SOURCE=$(shell git config --get remote.origin.url) + +ifneq (,$(findstring Microsoft,$(shell uname -r))) + DOWNLOADS_DIR=$(patsubst /mnt/c%,C:%,$(realpath ./downloads/)) +else + DOWNLOADS_DIR=$(realpath ./downloads/) +endif + +# Try to figure out which archive to use from the BASE_IMAGE +ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" + MQ_ARCHIVE_TYPE=UBUNTU + MQ_ARCHIVE_DEV_PLATFORM=ubuntu +else + MQ_ARCHIVE_TYPE=LINUX + MQ_ARCHIVE_DEV_PLATFORM=linux +endif +# Try to figure out which archive to use from the architecture +ifeq "$(ARCH)" "x86_64" + MQ_ARCHIVE_ARCH=X86-64 + MQ_DEV_ARCH=x86-64 +else ifeq "$(ARCH)" "ppc64le" + MQ_ARCHIVE_ARCH=LE_POWER + MQ_DEV_ARCH=ppcle +else ifeq "$(ARCH)" "s390x" + MQ_ARCHIVE_ARCH=SYSTEM_Z + MQ_DEV_ARCH=s390x +endif +# Archive names for IBM MQ Advanced for Developers +MQ_ARCHIVE_DEV_9.0.5.0=mqadv_dev905_$(MQ_ARCHIVE_DEV_PLATFORM)_x86-64.tar.gz +MQ_ARCHIVE_DEV_9.1.0.0=mqadv_dev910_$(MQ_ARCHIVE_DEV_PLATFORM)_$(MQ_DEV_ARCH).tar.gz + +############################################################################### +# Build targets +############################################################################### +.PHONY: vars +vars: +#ifeq "$(findstring ubuntu,$(BASE_IMAGE))","ubuntu" + @echo $(MQ_ARCHIVE_ARCH) + @echo $(MQ_ARCHIVE_TYPE) + @echo $(MQ_ARCHIVE) + +.PHONY: default +default: build-devserver test + +# Build all components (except incubating ones) +.PHONY: all +all: build-devserver build-advancedserver + +.PHONY: test-all +test-all: test-devserver test-advancedserver + +.PHONY: precommit +precommit: fmt lint all test-all + +.PHONY: devserver +devserver: build-devserver test-devserver + +# Build incubating components +.PHONY: incubating +incubating: build-explorer + +.PHONY: clean +clean: + rm -rf ./coverage + rm -rf ./build + rm -rf ./deps + +downloads/$(MQ_ARCHIVE_DEV): + $(info $(SPACER)$(shell printf $(TITLE)"Downloading IBM MQ Advanced for Developers "$(MQ_VERSION)$(END))) + mkdir -p downloads + cd downloads; curl -LO https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/$(MQ_ARCHIVE_DEV) + +downloads/$(MQ_SDK_ARCHIVE): + $(info $(SPACER)$(shell printf $(TITLE)"Downloading IBM MQ Advanced for Developers "$(MQ_VERSION)$(END))) + mkdir -p downloads + cd downloads; curl -LO https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqadv/$(MQ_SDK_ARCHIVE) + +.PHONY: downloads +downloads: downloads/$(MQ_ARCHIVE_DEV) downloads/$(MQ_SDK_ARCHIVE) + +.PHONY: deps +deps: + glide install --strip-vendor + +# Vendor Go dependencies for the Docker tests +test/docker/vendor: + cd test/docker && dep ensure -vendor-only + +.PHONY: build-cov +build-cov: + mkdir -p build + cd build; go test -c -covermode=count ../cmd/runmqserver + +# Shortcut to just run the unit tests +.PHONY: test-unit +test-unit: + docker build --target builder --file Dockerfile-server . + +.PHONY: test-advancedserver +test-advancedserver: test/docker/vendor + $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) on $(shell docker --version)"$(END))) + cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) EXPECTED_LICENSE=Production go test -parallel $(NUM_CPU) $(TEST_OPTS_DOCKER) + +.PHONY: build-devjmstest +build-devjmstest: + $(info $(SPACER)$(shell printf $(TITLE)"Build JMS tests for developer config"$(END))) + cd test/messaging && docker build --tag $(DEV_JMS_IMAGE) . + +.PHONY: test-devserver +test-devserver: test/docker/vendor + $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_DEVSERVER) on $(shell docker --version)"$(END))) + cd test/docker && TEST_IMAGE=$(MQ_IMAGE_DEVSERVER) EXPECTED_LICENSE=Developer DEV_JMS_IMAGE=$(DEV_JMS_IMAGE) go test -parallel $(NUM_CPU) -tags mqdev $(TEST_OPTS_DOCKER) + +coverage: + mkdir coverage + +.PHONY: test-advancedserver-cover +test-advancedserver-cover: test/docker/vendor coverage + $(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) with code coverage on $(shell docker --version)"$(END))) + rm -f ./coverage/unit*.cov + # Run unit tests with coverage, for each package under 'internal' + go list -f '{{.Name}}' ./internal/... | xargs -I {} go test -cover -covermode count -coverprofile ./coverage/unit-{}.cov ./internal/{} +# ls -1 ./cmd | xargs -I {} go test -cover -covermode count -coverprofile ./coverage/unit-{}.cov ./cmd/{}/... + echo 'mode: count' > ./coverage/unit.cov + tail -q -n +2 ./coverage/unit-*.cov >> ./coverage/unit.cov + go tool cover -html=./coverage/unit.cov -o ./coverage/unit.html + + rm -f ./test/docker/coverage/*.cov + rm -f ./coverage/docker.* + mkdir -p ./test/docker/coverage/ + cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER)-cover TEST_COVER=true go test $(TEST_OPTS_DOCKER) + echo 'mode: count' > ./coverage/docker.cov + tail -q -n +2 ./test/docker/coverage/*.cov >> ./coverage/docker.cov + go tool cover -html=./coverage/docker.cov -o ./coverage/docker.html + + echo 'mode: count' > ./coverage/combined.cov + tail -q -n +2 ./coverage/unit.cov ./coverage/docker.cov >> ./coverage/combined.cov + go tool cover -html=./coverage/combined.cov -o ./coverage/combined.html + +define docker-build-mq + # Create a temporary network to use for the build + $(DOCKER) network create build + # Start a web server to host the MQ downloadable (tar.gz) file + $(DOCKER) run \ + --rm \ + --name $(BUILD_SERVER_CONTAINER) \ + --network build \ + --network-alias build \ + --volume $(DOWNLOADS_DIR):/usr/share/nginx/html:ro \ + --detach \ + nginx:alpine + # Build the new image + $(DOCKER) build \ + --tag $1 \ + --file $2 \ + --network build \ + --build-arg MQ_URL=http://build:80/$3 \ + --build-arg BASE_IMAGE=$(BASE_IMAGE) \ + --build-arg BUILDER_IMAGE=$(MQ_IMAGE_GOLANG_SDK) \ + --build-arg IMAGE_REVISION="$(IMAGE_REVISION)" \ + --build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" \ + --label IBM_PRODUCT_ID=$4 \ + --label IBM_PRODUCT_NAME=$5 \ + --label IBM_PRODUCT_VERSION=$6 \ + --build-arg MQ_PACKAGES="$(MQ_PACKAGES)" \ + . ; $(DOCKER) kill $(BUILD_SERVER_CONTAINER) && $(DOCKER) network rm build +endef + +DOCKER_SERVER_VERSION=$(shell docker version --format "{{ .Server.Version }}") +DOCKER_CLIENT_VERSION=$(shell docker version --format "{{ .Client.Version }}") +.PHONY: docker-version +docker-version: + @test "$(word 1,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "17" || ("$(word 1,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -eq "17" && "$(word 2,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "05") || (echo "Error: Docker client 17.05 or greater is required" && exit 1) + @test "$(word 1,$(subst ., ,$(DOCKER_SERVER_VERSION)))" -ge "17" || ("$(word 1,$(subst ., ,$(DOCKER_SERVER_VERSION)))" -eq "17" && "$(word 2,$(subst ., ,$(DOCKER_CLIENT_VERSION)))" -ge "05") || (echo "Error: Docker server 17.05 or greater is required" && exit 1) + +.PHONY: build-advancedserver +build-advancedserver: MQ_SDK_ARCHIVE=$(MQ_ARCHIVE) +build-advancedserver: downloads/$(MQ_ARCHIVE) docker-version build-golang-sdk-ex + $(info $(SPACER)$(shell printf $(TITLE)"Build $(MQ_IMAGE_ADVANCEDSERVER)"$(END))) + $(call docker-build-mq,$(MQ_IMAGE_ADVANCEDSERVER),Dockerfile-server,$(MQ_ARCHIVE),"4486e8c4cc9146fd9b3ce1f14a2dfc5b","IBM MQ Advanced",$(MQ_VERSION)) + +.PHONY: build-devserver +# Target-specific variable to add web server into devserver image +ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" +build-devserver: MQ_PACKAGES=ibmmq-server ibmmq-java ibmmq-jre ibmmq-gskit ibmmq-msg-.* ibmmq-samples ibmmq-ams ibmmq-web +else +build-devserver: MQ_PACKAGES=MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm MQSeriesWeb-*.rpm +endif +build-devserver: MQ_SDK_ARCHIVE=$(MQ_ARCHIVE_DEV) +build-devserver: downloads/$(MQ_ARCHIVE_DEV) docker-version build-golang-sdk-ex + $(info $(shell printf $(TITLE)"Build $(MQ_IMAGE_DEVSERVER_BASE)"$(END))) + $(call docker-build-mq,$(MQ_IMAGE_DEVSERVER_BASE),Dockerfile-server,$(MQ_ARCHIVE_DEV),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)",$(MQ_VERSION)) + $(DOCKER) build --tag $(MQ_IMAGE_DEVSERVER) --build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" --build-arg IMAGE_REVISION="$(IMAGE_REVISION)" --build-arg BASE_IMAGE=$(MQ_IMAGE_DEVSERVER_BASE) --build-arg BUILDER_IMAGE=$(MQ_IMAGE_GOLANG_SDK) --file incubating/mqadvanced-server-dev/Dockerfile . + +.PHONY: build-advancedserver-cover +build-advancedserver-cover: docker-version + $(DOCKER) build --build-arg BASE_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) -t $(MQ_IMAGE_ADVANCEDSERVER)-cover -f Dockerfile-server.cover . + +.PHONY: build-explorer docker-pull +build-explorer: downloads/$(MQ_ARCHIVE_DEV) + $(call docker-build-mq,mq-explorer:latest-$(ARCH),incubating/mq-explorer/Dockerfile-mq-explorer,$(MQ_ARCHIVE_DEV),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)",$(MQ_VERSION)) + +.PHONY: build-sdk +build-sdk: downloads/$(MQ_SDK_ARCHIVE) build-sdk-ex + +.PHONY: build-sdk-ex +ifeq "$(findstring ubuntu,$(BASE_IMAGE))" "ubuntu" +build-sdk-ex: MQ_PACKAGES=ibmmq-sdk ibmmq-samples build-essential +else +build-sdk-ex: MQ_PACKAGES=MQSeriesRuntime-*.rpm MQSeriesSDK-*.rpm MQSeriesSamples*.rpm +endif +build-sdk-ex: docker-version docker-pull + $(call docker-build-mq,$(MQ_IMAGE_SDK),incubating/mq-sdk/Dockerfile,$(MQ_SDK_ARCHIVE),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers SDK (Non-Warranted)",$(MQ_VERSION)) + +.PHONY: build-golang-sdk +build-golang-sdk: downloads/$(MQ_SDK_ARCHIVE) build-golang-sdk-ex + +.PHONY: build-golang-sdk-ex +build-golang-sdk-ex: docker-version build-sdk-ex + $(DOCKER) build --build-arg BASE_IMAGE=$(MQ_IMAGE_SDK) -t $(MQ_IMAGE_GOLANG_SDK) -f incubating/mq-golang-sdk/Dockerfile . +# $(call docker-build-mq,$(MQ_IMAGE_GOLANG_SDK),incubating/mq-golang-sdk/Dockerfile,$(MQ_IMAGE_SDK),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers SDK (Non-Warranted)",$(MQ_VERSION)) + +docker-pull: + $(DOCKER) pull $(BASE_IMAGE) + +GO_PKG_DIRS = ./cmd ./internal ./test + +fmt: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS)) + go fmt $(addsuffix /..., $(GO_PKG_DIRS)) + +lint: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS)) + @# This expression is necessary because /... includes the vendor directory in golint + @# As of 11/04/2018 there is an open issue to fix it: https://github.com/golang/lint/issues/320 + golint -set_exit_status $(sort $(dir $(wildcard $(addsuffix /*/*.go, $(GO_PKG_DIRS))))) + +include formatting.mk diff --git a/incubating/mq-advanced-server-rhel/ansible/.gitignore b/incubating/mq-advanced-server-rhel/ansible/.gitignore deleted file mode 100644 index 9b0b900..0000000 --- a/incubating/mq-advanced-server-rhel/ansible/.gitignore +++ /dev/null @@ -1 +0,0 @@ -hosts \ No newline at end of file diff --git a/incubating/mq-advanced-server-rhel/ansible/rhel-build.yaml b/incubating/mq-advanced-server-rhel/ansible/rhel-build.yaml deleted file mode 100644 index 832ec9c..0000000 --- a/incubating/mq-advanced-server-rhel/ansible/rhel-build.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# © 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. ---- -# Sets up a server for building the Red Hat image. -- hosts: rhbuild - become: true - any_errors_fatal: true - tasks: - - name: install buildah - package: - name: buildah - state: present - when: ansible_distribution == "RedHat" - - name: install podman - package: - name: buildah - state: present - when: ansible_distribution == "RedHat" - - name: install golang - package: - name: golang - state: absent - - name: install make - package: - name: make - state: present - - name: install git - package: - name: git - state: present - - name: install golang 1.10 from TAR - unarchive: - src: "https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz" - dest: "/usr/local" - remote_src: yes - # TODO: Re-factor to use get_url first, so we can use the checksum - #checksum: sha256:fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035 - creates: /usr/local/go/doc/go1.10.html - - name: add golang to PATH - copy: - dest: "/etc/profile.d/golang.sh" - content: | - PATH=$PATH:/usr/local/go/bin - - name: install dep from GitHub - get_url: - url: https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 - dest: /usr/local/bin/dep - mode: 0755 - checksum: sha256:31144e465e52ffbc0035248a10ddea61a09bf28b00784fd3fdd9882c8cbb2315 - when: ansible_architecture == "x86_64" - # TODO: Install MQ SDK diff --git a/incubating/mq-advanced-server-rhel/buildah.sh b/incubating/mq-advanced-server-rhel/buildah.sh deleted file mode 100644 index cb51b85..0000000 --- a/incubating/mq-advanced-server-rhel/buildah.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/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_dev905_linux_x86-64.tar.gz -MQ_PACKAGES="MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesJava*.rpm MQSeriesJRE*.rpm MQSeriesGSKit*.rpm MQSeriesMsg*.rpm MQSeriesSamples*.rpm MQSeriesAMS-*.rpm" - -# Use a "scratch" container, so the resulting image has minimal files -# Resulting image won't have yum, for example -ctr=$(buildah from scratch) -scratchmnt=$(buildah mount $ctr) - -# Initialize yum for use with the scratch container -rpm --root $scratchmnt --initdb -yum install yum-utils -yumdownloader --destdir=/tmp redhat-release-server -rpm --root $scratchmnt -ihv /tmp/redhat-release-server*.rpm - -# Install the packages required by MQ -yum install -y --installroot=$scratchmnt \ - bash \ - bc \ - coreutils \ - file \ - findutils \ - gawk \ - glibc-common \ - grep \ - passwd \ - procps-ng \ - sed \ - tar \ - util-linux - -# Clean up cached files -yum clean all --installroot=$scratchmnt -rm -rf $scratchmnt/var/cache/yum/* - -groupadd --root $scratchmnt --system --gid 888 mqm -useradd --root $scratchmnt --system --uid 888 --gid mqm mqm -usermod --root $scratchmnt -G root mqm - -DIR_EXTRACT=$scratchmnt/tmp/extract -mkdir -p $scratchmnt/tmp/extract -tar -zxvf ${MQ_ARCHIVE} -C ${DIR_EXTRACT} -DIR_RPM=$(find ${DIR_EXTRACT} -name "*.rpm" -printf "%h\n" | sort -u | head -1) -DIR_RPM=${DIR_RPM#$scratchmnt} -#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#$scratchmnt} - -# Accept the MQ license -buildah run $ctr -- ${MQLICENSE} -text_only -accept - -buildah run $ctr -- bash -c "cd $DIR_RPM && 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 - -# Remove the directory structure under /var/mqm which was created by the installer -rm -rf $scratchmnt/var/mqm - -# Create the mount point for volumes -mkdir -p $scratchmnt/mnt/mqm - -# Create the directory for MQ configuration files -mkdir -p $scratchmnt/etc/mqm - -# Create a symlink for /var/mqm -> /mnt/mqm/data -buildah run $ctr ln -s /mnt/mqm/data /var/mqm - -# Optional: Set these values for the Bluemix 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 - -# 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/... -# Install the Go binaries into the image -cp runmqserver $scratchmnt/usr/local/bin/ -cp chkmq* $scratchmnt/usr/local/bin/ -cp NOTICES.txt $scratchmnt/opt/mqm/licenses/notices-container.txt -chmod ug+x $scratchmnt/usr/local/bin/runmqserver -chown mqm:mqm $scratchmnt/usr/local/bin/*mq* -chmod ug+xs $scratchmnt/usr/local/bin/chkmq* - -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.0.5.0" \ - --env AMQ_ADDITIONAL_JSON_LOG=1 \ - --env LANG=en_US.UTF-8 \ - --env LOG_FORMAT=basic \ - --entrypoint runmqserver \ - --user 888 \ - $ctr -buildah unmount $ctr -buildah commit $ctr mymq - -# TODO: Leaves the working container lying around. Good for dev. \ No newline at end of file diff --git a/incubating/mq-advanced-server-rhel/README.md b/mq-advanced-server-rhel/README.md similarity index 100% rename from incubating/mq-advanced-server-rhel/README.md rename to mq-advanced-server-rhel/README.md diff --git a/mq-advanced-server-rhel/go-build.sh b/mq-advanced-server-rhel/go-build.sh new file mode 100755 index 0000000..831ba41 --- /dev/null +++ b/mq-advanced-server-rhel/go-build.sh @@ -0,0 +1,47 @@ +#!/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. + +# Builds and tests the golang programs used by the MQ image. + +set -e + +cd $GOPATH/src/github.com/ibm-messaging/mq-container/ + +# Build and test the Go code +mkdir -p build +cd build + +rm -f chkmqready chkmqhealthy runmqserver runmqdevserver + +if [ "$MQDEV" = "TRUE" ]; then + # Build and test the Go code + go build -ldflags "-X \"main.ImageCreated=$(date --iso-8601=seconds)\" -X \"main.ImageRevision=$IMAGE_REVISION\" -X \"main.ImageSource=$IMAGE_SOURCE\"" --tags 'mqdev' ../cmd/runmqserver/ + go build ../cmd/runmqdevserver/ +else + go build -ldflags "-X \"main.ImageCreated=$(date --iso-8601=seconds)\" -X \"main.ImageRevision=$IMAGE_REVISION\" -X \"main.ImageSource=$IMAGE_SOURCE\"" ../cmd/runmqserver/ +fi + +go build ../cmd/chkmqready/ +go build ../cmd/chkmqhealthy/ +go test -v ../cmd/runmqserver/ +go test -v ../cmd/chkmqready/ +go test -v ../cmd/chkmqhealthy/ +if [ "$MQDEV" = "TRUE" ]; then + go test -v ../cmd/runmqdevserver +fi +go test -v ../internal/... +go vet ../cmd/... ../internal/... diff --git a/mq-advanced-server-rhel/go-buildah.sh b/mq-advanced-server-rhel/go-buildah.sh new file mode 100755 index 0000000..e689edf --- /dev/null +++ b/mq-advanced-server-rhel/go-buildah.sh @@ -0,0 +1,34 @@ +#!/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. + +# Run the Go build script inside the Go container, mounting the source +# directory in + +readonly tag=$1 +readonly dev=$2 + +IMAGE_REVISION=${IMAGE_REVISION:="Not Applicable"} +IMAGE_SOURCE=${IMAGE_SOURCE:="Not Applicable"} + +podman run \ + --volume ${PWD}:/go/src/github.com/ibm-messaging/mq-container/ \ + --env GOPATH=/go \ + --env IMAGE_REVISION="$IMAGE_REVISION" \ + --env IMAGE_SOURCE="$IMAGE_SOURCE" \ + --env MQDEV=${dev} \ + ${tag} \ + bash -c "cd /go/src/github.com/ibm-messaging/mq-container/ && ./mq-advanced-server-rhel/go-build.sh" diff --git a/mq-advanced-server-rhel/install-mq-rhel.sh b/mq-advanced-server-rhel/install-mq-rhel.sh new file mode 100755 index 0000000..c3c98d9 --- /dev/null +++ b/mq-advanced-server-rhel/install-mq-rhel.sh @@ -0,0 +1,62 @@ +#!/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 + +groupadd --root $scratchmnt --system --gid 888 mqm +useradd --root $scratchmnt --system --uid 888 --gid mqm mqm +usermod --root $scratchmnt -aG root mqm +usermod --root $scratchmnt -aG mqm root + +if [ ! -d ${dir_extract}/MQServer ]; then + mkdir -p ${dir_extract} + echo Extracting $archive + tar -zxf $archive -C ${dir_extract} + echo Extracting finished +fi + +# If MQ_PACKAGES isn't specifically set, then choose a valid set of defaults + + +# 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}/MQServer + +# 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 diff --git a/mq-advanced-server-rhel/mq-buildah.sh b/mq-advanced-server-rhel/mq-buildah.sh new file mode 100755 index 0000000..8f6a75c --- /dev/null +++ b/mq-advanced-server-rhel/mq-buildah.sh @@ -0,0 +1,115 @@ +#!/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 +# Usage +# mq-buildah.sh ARCHIVEFILE PACKAGES + +set -x +set -e + +############################################################################### +# 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) +readonly archive=downloads/$1 +readonly packages=$2 +readonly tag=$3 +readonly version=$4 +readonly mqdev=$5 + +# Initialize yum for use with the scratch container +rpm --root $mnt_mq --initdb + +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} --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} +rm -rf ${mnt_mq}/var/cache/yum/* + +# Install MQ server packages into the MQ builder image +./mq-advanced-server-rhel/install-mq-rhel.sh ${ctr_mq} "${mnt_mq}" "${archive}" "${packages}" + +# Remove the directory structure under /var/mqm which was created by the installer +rm -rf ${mnt_mq}/var/mqm + +# Create the directory for MQ configuration files +mkdir -p ${mnt_mq}/etc/mqm +chown 888:888 ${mnt_mq}/etc/mqm + +# Install the Go binaries into the image +install --mode 0750 --owner 888 --group 888 ./build/runmqserver ${mnt_mq}/usr/local/bin/ +install --mode 6750 --owner 888 --group 888 ./build/chk* ${mnt_mq}/usr/local/bin/ +install --mode 0750 --owner 888 --group 888 ./NOTICES.txt ${mnt_mq}/opt/mqm/licenses/notices-container.txt + +############################################################################### +# Final Buildah commands +############################################################################### + +if [ "$mqdev" = "TRUE" ]; then + OSTAG="mq messaging developer" + DISNAME="IBM MQ Advanced Server Developer Edition" +else + OSTAG="mq messaging" + DISNAME="IBM MQ Advanced Server" +fi + + + +buildah config \ + --port 1414/tcp \ + --port 9157/tcp \ + --os linux \ + --label architecture=x86_64 \ + --label io.openshift.tags="$OSTAG" \ + --label io.k8s.display-name="$DISNAME" \ + --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="${tag%:*}" \ + --label vendor="IBM" \ + --label version="$version" \ + --env AMQ_ADDITIONAL_JSON_LOG=1 \ + --env LANG=en_US.UTF-8 \ + --env LOG_FORMAT=basic \ + --entrypoint runmqserver \ + $ctr_mq +buildah unmount $ctr_mq +buildah commit $ctr_mq $tag diff --git a/mq-advanced-server-rhel/mq-golang-sdk-buildah.sh b/mq-advanced-server-rhel/mq-golang-sdk-buildah.sh new file mode 100755 index 0000000..e7a7c8d --- /dev/null +++ b/mq-advanced-server-rhel/mq-golang-sdk-buildah.sh @@ -0,0 +1,45 @@ +#!/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/$1 +readonly tag=$2 +# 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) + +# 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 +./mq-advanced-server-rhel/install-mq-rhel.sh ${ctr} "${mnt}" "${mq_archive}" "MQSeriesRuntime-*.rpm MQSeriesSDK-*.rpm MQSeriesSamples*.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} diff --git a/mq-advanced-server-rhel/mqdev-buildah.sh b/mq-advanced-server-rhel/mqdev-buildah.sh new file mode 100755 index 0000000..5e1a90c --- /dev/null +++ b/mq-advanced-server-rhel/mqdev-buildah.sh @@ -0,0 +1,81 @@ +#!/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 +# Usage +# mq-buildah.sh ARCHIVEFILE PACKAGES + +set -x +set -e + +############################################################################### +# 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 basetag=$1 +readonly ctr_mq=$(buildah from $basetag) +readonly mnt_mq=$(buildah mount $ctr_mq) +readonly tag=$2 +readonly version=$3 + + +useradd --root $mnt_mq --system --uid 889 --gid mqm admin +groupadd --root $mnt_mq --system --gid 890 mqclient +useradd --root $mnt_mq --system --uid 890 --gid mqclient mqclient + +buildah run $ctr -- echo admin:passw0rd | chpasswd + +mkdir -p $mnt_mq/run/runmqdevserver +chown 888:888 $mnt_mq/run/runmqdevserver + +# Copy runmqdevserver program +install --mode 0750 --owner 888 --group 888 ./build/runmqdevserver ${mnt_mq}/usr/local/bin/ + +# Copy template files +cp incubating/mqadvanced-server-dev/*.tpl ${mnt_mq}/etc/mqm/ + +# Copy web XML files for default developer configuration +cp -R incubating/mqadvanced-server-dev/web ${mnt_mq}/etc/mqm/web + +############################################################################### +# Final Buildah commands +############################################################################### + +buildah config \ + --port 1414/tcp \ + --port 9157/tcp \ + --port 9443/tcp \ + --os linux \ + --label architecture=x86_64 \ + --label io.openshift.tags="mq messaging developer" \ + --label io.k8s.display-name="IBM MQ Advanced Server Developer Edition" \ + --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="${tag%:*}" \ + --label vendor="IBM" \ + --label version="$version" \ + --env AMQ_ADDITIONAL_JSON_LOG=1 \ + --env LANG=en_US.UTF-8 \ + --env LOG_FORMAT=basic \ + --env MQ_ADMIN_PASSWORD=passw0rd \ + --env MQ_DEV=true \ + --entrypoint runmqdevserver \ + $ctr_mq +buildah unmount $ctr_mq +buildah commit $ctr_mq $tag +