Add basic versioning into main golang file (#151)
* Add basic versioning into main golang file * Add versioning set test * address Arthur's comments
This commit is contained in:
@@ -20,10 +20,13 @@ ARG BUILDER_IMAGE=mq-golang-sdk:9.0.5.0-x86_64-ubuntu-16.04
|
||||
###############################################################################
|
||||
FROM $BUILDER_IMAGE as builder
|
||||
WORKDIR /go/src/github.com/ibm-messaging/mq-container/
|
||||
ARG IMAGE_REVISION="Not specified"
|
||||
ARG IMAGE_CREATED="Not specified"
|
||||
ARG IMAGE_SOURCE="Not specified"
|
||||
COPY cmd/ ./cmd
|
||||
COPY internal/ ./internal
|
||||
COPY vendor/ ./vendor
|
||||
RUN go build ./cmd/runmqserver/
|
||||
RUN go build -ldflags "-X \"main.ImageCreated=$IMAGE_CREATED\" -X \"main.ImageRevision=$IMAGE_REVISION\" -X \"main.ImageSource=$IMAGE_SOURCE\"" ./cmd/runmqserver/
|
||||
RUN go build ./cmd/chkmqready/
|
||||
RUN go build ./cmd/chkmqhealthy/
|
||||
# Run all unit tests
|
||||
|
||||
9
Makefile
9
Makefile
@@ -59,6 +59,10 @@ 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 remote get-url origin)
|
||||
IMAGE_CREATED=$(shell date -u +%Y-%m-%dT%H:%M:%S%:z)
|
||||
|
||||
|
||||
ifneq (,$(findstring Microsoft,$(shell uname -r)))
|
||||
@@ -218,6 +222,9 @@ define docker-build-mq
|
||||
--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_CREATED="$(IMAGE_CREATED)" \
|
||||
--build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" \
|
||||
--label IBM_PRODUCT_ID=$4 \
|
||||
--label IBM_PRODUCT_NAME=$5 \
|
||||
--label IBM_PRODUCT_VERSION=$6 \
|
||||
@@ -248,7 +255,7 @@ endif
|
||||
build-devserver: downloads/$(MQ_ARCHIVE_DEV) docker-version build-golang-sdk
|
||||
$(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 BASE_IMAGE=$(MQ_IMAGE_DEVSERVER_BASE) --build-arg BUILDER_IMAGE=$(MQ_IMAGE_GOLANG_SDK) --file incubating/mqadvanced-server-dev/Dockerfile .
|
||||
$(DOCKER) build --tag $(MQ_IMAGE_DEVSERVER) --build-arg IMAGE_SOURCE="$(IMAGE_SOURCE)" --build-arg IMAGE_REVISION="$(IMAGE_REVISION)" --build-arg IMAGE_CREATED="$(IMAGE_CREATED)" --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
|
||||
|
||||
@@ -75,6 +75,9 @@ func doMain() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Print out versioning information
|
||||
logVersionInfo()
|
||||
|
||||
err = postInit(name)
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
|
||||
68
cmd/runmqserver/version.go
Normal file
68
cmd/runmqserver/version.go
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
© 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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
)
|
||||
|
||||
var (
|
||||
ImageCreated = "Not specified"
|
||||
ImageRevision = "Not specified"
|
||||
ImageSource = "Not specified"
|
||||
)
|
||||
|
||||
func logDateStamp() {
|
||||
log.Printf("Image created: %v", ImageCreated)
|
||||
}
|
||||
|
||||
func logGitRepo() {
|
||||
log.Printf("Image revision: %v", ImageRevision)
|
||||
}
|
||||
|
||||
func logGitCommit() {
|
||||
log.Printf("Image source: %v", ImageSource)
|
||||
}
|
||||
|
||||
func logMQVersion() {
|
||||
mqVersion, _, err := command.Run("dspmqver", "-b", "-f", "2")
|
||||
if err != nil {
|
||||
log.Printf("Error Getting MQ version: %v", strings.TrimSuffix(string(mqVersion), "\n"))
|
||||
}
|
||||
|
||||
mqBuild, _, err := command.Run("dspmqver", "-b", "-f", "4")
|
||||
if err != nil {
|
||||
log.Printf("Error Getting MQ build: %v", strings.TrimSuffix(string(mqBuild), "\n"))
|
||||
}
|
||||
mqLicense, _, err := command.Run("dspmqver", "-b", "-f", "8192")
|
||||
if err != nil {
|
||||
log.Printf("Error Getting MQ license: %v", strings.TrimSuffix(string(mqLicense), "\n"))
|
||||
}
|
||||
|
||||
log.Printf("MQ version: %v", strings.TrimSuffix(mqVersion, "\n"))
|
||||
log.Printf("MQ level: %v", strings.TrimSuffix(mqBuild, "\n"))
|
||||
log.Printf("MQ license: %v", strings.TrimSuffix(mqLicense, "\n"))
|
||||
}
|
||||
|
||||
func logVersionInfo() {
|
||||
logDateStamp()
|
||||
logGitRepo()
|
||||
logGitCommit()
|
||||
logMQVersion()
|
||||
}
|
||||
@@ -19,12 +19,15 @@ ARG BUILDER_IMAGE=mq-golang-sdk:9.0.5.0-x86_64-ubuntu-16.04
|
||||
# Build stage to build Go code
|
||||
###############################################################################
|
||||
FROM $BUILDER_IMAGE as builder
|
||||
ARG IMAGE_REVISION="Not specified"
|
||||
ARG IMAGE_CREATED="Not specified"
|
||||
ARG IMAGE_SOURCE="Not specified"
|
||||
WORKDIR /go/src/github.com/ibm-messaging/mq-container/
|
||||
COPY cmd/ ./cmd
|
||||
COPY internal/ ./internal
|
||||
COPY vendor/ ./vendor
|
||||
# Re-build runmqserver, with code tagged with 'mqdev' enabled
|
||||
RUN go build --tags 'mqdev' ./cmd/runmqserver
|
||||
RUN go build -ldflags "-X \"main.ImageCreated=$IMAGE_CREATED\" -X \"main.ImageRevision=$IMAGE_REVISION\" -X \"main.ImageSource=$IMAGE_SOURCE\"" --tags 'mqdev' ./cmd/runmqserver
|
||||
RUN go build ./cmd/runmqdevserver/
|
||||
# Run all unit tests
|
||||
RUN go test -v ./cmd/runmqdevserver/...
|
||||
|
||||
@@ -648,3 +648,119 @@ func TestCorrectLicense(t *testing.T) {
|
||||
t.Errorf("Expected license to be '%s' but was '%s", expectedLicense, license)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersioning(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cli, err := client.NewEnvClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
containerConfig := container.Config{
|
||||
Env: []string{"LICENSE=accept"},
|
||||
}
|
||||
id := runContainer(t, cli, &containerConfig)
|
||||
defer cleanContainer(t, cli, id)
|
||||
waitForReady(t, cli, id)
|
||||
|
||||
// Get whole logs and check versioning system
|
||||
l := inspectLogs(t, cli, id)
|
||||
scanner := bufio.NewScanner(strings.NewReader(l))
|
||||
|
||||
total := 6
|
||||
foundCreated := false
|
||||
foundRevision := false
|
||||
foundSource := false
|
||||
foundMQVersion := false
|
||||
foundMQLevel := false
|
||||
foundMQLicense := false
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.Contains(line, "Image created:") && !foundCreated {
|
||||
total--
|
||||
foundCreated = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify created
|
||||
_, err := time.Parse(time.RFC3339, data)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to validate Image created (%v) - %v", data, err)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(line, "Image revision:") && !foundRevision {
|
||||
total--
|
||||
foundRevision = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify revision
|
||||
pattern := regexp.MustCompile("^[a-fA-F0-9]{40}$")
|
||||
if !pattern.MatchString(data) {
|
||||
t.Errorf("Failed to validate revision (%v)", data)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(line, "Image source:") && !foundSource {
|
||||
total--
|
||||
foundSource = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify source
|
||||
if !strings.Contains(data, "github") {
|
||||
t.Errorf("Failed to validate source (%v)", data)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(line, "MQ version:") && !foundMQVersion {
|
||||
total--
|
||||
foundMQVersion = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify MQ version
|
||||
pattern := regexp.MustCompile("^\\d+\\.\\d+\\.\\d+\\.\\d+$")
|
||||
if !pattern.MatchString(data) {
|
||||
t.Errorf("Failed to validate mq version (%v)", data)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(line, "MQ level:") && !foundMQLevel {
|
||||
total--
|
||||
foundMQLevel = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify MQ version
|
||||
pattern := regexp.MustCompile("^p\\d{3}-.+$")
|
||||
if !pattern.MatchString(data) {
|
||||
t.Errorf("Failed to validate mq level (%v)", data)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(line, "MQ license:") && !foundMQLicense {
|
||||
total--
|
||||
foundMQLicense = true
|
||||
dataAr := strings.Split(line, " ")
|
||||
data := dataAr[len(dataAr)-1]
|
||||
|
||||
// Verify MQ version
|
||||
if data != "Developer" && data != "Production" {
|
||||
t.Errorf("Failed to validate mq license (%v)", data)
|
||||
}
|
||||
}
|
||||
|
||||
// end loop early
|
||||
if total == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !foundCreated || !foundRevision || !foundSource || !foundMQVersion || !foundMQLevel || !foundMQLicense {
|
||||
t.Errorf("Failed to find one or more version strings: created(%v) revision(%v) source(%v) mqversion(%v) mqlevel(%v) mqlicense(%v)", foundCreated, foundRevision, foundSource, foundMQVersion, foundMQLevel, foundMQLicense)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user