From d87676e1a23951f1cd554ac5a33a642347a8b462 Mon Sep 17 00:00:00 2001 From: Anton Lisovenko Date: Thu, 30 Jul 2020 15:10:52 +0100 Subject: [PATCH 1/5] Fixing the image: using the official image as a base --- Dockerfile | 20 +-- mmsconfiguration/edit_mms_configuration.go | 155 ------------------ .../edit_mms_configuration_test.go | 82 --------- scripts/docker-entry-point.sh | 56 ------- 4 files changed, 5 insertions(+), 308 deletions(-) delete mode 100755 mmsconfiguration/edit_mms_configuration.go delete mode 100755 mmsconfiguration/edit_mms_configuration_test.go delete mode 100755 scripts/docker-entry-point.sh diff --git a/Dockerfile b/Dockerfile index fddbaba..c186a9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,19 +4,12 @@ ARG BASE_REGISTRY=nexus-docker-secure.levelup-nexus.svc.cluster.local:18082 ARG BASE_IMAGE=redhat/ubi/ubi7 ARG BASE_TAG=7.8 -FROM golang:1.13 as builder - -USER root -RUN mkdir /build -ADD . /build/ -WORKDIR /build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -a -i -o ./output/mmsconfiguration ./mmsconfiguration +ARG VERSION -##### +FROM quay.io/mongodb/mongodb-enterprise-init-ops-manager:${VERSION} as official FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} -ARG VERSION LABEL name="MongoDB Enterprise Ops Manager Init" \ maintainer="support@mongodb.com" \ @@ -26,12 +19,9 @@ LABEL name="MongoDB Enterprise Ops Manager Init" \ summary="MongoDB Enterprise Ops Manager Init Image" \ description="Startup Scripts for MongoDB Enterprise Ops Manager" -RUN mkdir /scripts && mkdir -p /licenses - -COPY --from=builder /build/output/mmsconfiguration /scripts/ -COPY scripts/docker-entry-point.sh /scripts/ - -COPY LICENSE /licenses/mongodb-enterprise-ops-manager +COPY --from=official /scripts/mmsconfiguration /scripts/ +COPY --from=official /scripts/docker-entry-point.sh /scripts/ +COPY --from=official /licenses/mongodb-enterprise-ops-manager /licenses/ USER 2000 ENTRYPOINT [ "/bin/cp", "-f", "/scripts/docker-entry-point.sh", "/scripts/mmsconfiguration", "/opt/scripts/" ] diff --git a/mmsconfiguration/edit_mms_configuration.go b/mmsconfiguration/edit_mms_configuration.go deleted file mode 100755 index faa8626..0000000 --- a/mmsconfiguration/edit_mms_configuration.go +++ /dev/null @@ -1,155 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "strings" -) - -const ( - mmsJvmParamsVar = "JAVA_MMS_UI_OPTS" - backupDaemonJvmParamsVar = "JAVA_DAEMON_OPTS" - omPropertyPrefix = "OM_PROP_" - lineBreak = "\n" - commentPrefix = "#" - propOverwriteFmt = "%s=\"${%s} %s\"" - backupDaemon = "BACKUP_DAEMON" -) - -func updateConfFile(confFile string) error { - confFilePropertyName := mmsJvmParamsVar - if _, isBackupDaemon := os.LookupEnv(backupDaemon); isBackupDaemon { - confFilePropertyName = backupDaemonJvmParamsVar - } - - customJvmParamsVar := "CUSTOM_" + confFilePropertyName - jvmParams, jvmParamsEnvVarExists := os.LookupEnv(customJvmParamsVar) - - if !jvmParamsEnvVarExists || jvmParams == "" { - fmt.Printf("%s not specified, not modifying %s\n", customJvmParamsVar, confFile) - return nil - } - - newMmsJvmParams := fmt.Sprintf(propOverwriteFmt, confFilePropertyName, confFilePropertyName, jvmParams) - fmt.Printf("Appending %s to %s\n", newMmsJvmParams, confFile) - - err := appendLinesToFile(confFile, getJvmParamDocString()+newMmsJvmParams+lineBreak) - return err -} - -func updatePropertiesFile(propertiesFile string) error { - newProperties := getOmPropertiesFromEnvVars() - - // If there are no exported mms properties, we can stop here - if len(newProperties) == 0 { - return nil - } - - lines, err := readLinesFromFile(propertiesFile) - if err != nil { - return err - } - - lines = updateMmsProperties(lines, newProperties) - fmt.Printf("Updating configuration properties file %s\n", propertiesFile) - err = writeLinesToFile(propertiesFile, lines) - return err -} - -func readLinesFromFile(name string) ([]string, error) { - input, err := ioutil.ReadFile(name) - if err != nil { - return nil, fmt.Errorf("error reading file %s: %v", name, err) - } - return strings.Split(string(input), lineBreak), nil -} - -func writeLinesToFile(name string, lines []string) error { - output := strings.Join(lines, lineBreak) - - err := ioutil.WriteFile(name, []byte(output), 0775) - if err != nil { - return fmt.Errorf("error writing to file %s: %v", name, err) - } - return nil -} - -func appendLinesToFile(name string, lines string) error { - f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - return fmt.Errorf("error opening file %s: %v", name, err) - } - - if _, err = f.WriteString(lines); err != nil { - return fmt.Errorf("error writing to file %s: %v", name, err) - } - - err = f.Close() - return err - -} - -func getOmPropertiesFromEnvVars() map[string]string { - props := map[string]string{} - for _, pair := range os.Environ() { - if !strings.HasPrefix(pair, omPropertyPrefix) { - continue - } - - p := strings.SplitN(pair, "=", 2) - key := strings.Replace(p[0], omPropertyPrefix, "", 1) - key = strings.ReplaceAll(key, "_", ".") - props[key] = p[1] - } - return props -} - -func updateMmsProperties(lines []string, newProperties map[string]string) []string { - seenProperties := map[string]bool{} - - // Overwrite existing properties - for i, line := range lines { - if strings.HasPrefix(line, commentPrefix) || !strings.Contains(line, "=") { - continue - } - - key := strings.Split(line, "=")[0] - if newVal, ok := newProperties[key]; ok { - lines[i] = fmt.Sprintf("%s=%s", key, newVal) - fmt.Printf("Setting %s=%s\n", key, newVal) - seenProperties[key] = true - } - } - - // Add new properties - for key, val := range newProperties { - if _, ok := seenProperties[key]; !ok { - lines = append(lines, fmt.Sprintf("%s=%s", key, val)) - fmt.Printf("Added %s=%s\n", key, val) - } - } - return lines -} - -func getJvmParamDocString() string { - commentMarker := strings.Repeat("#", 55) - return fmt.Sprintf("%s\n## This is the custom JVM configuration set by the Operator\n%s\n\n", commentMarker, commentMarker) -} - -func main() { - if len(os.Args) < 3 { - fmt.Printf("Incorrect arguments %s, must specify path to conf file and path to properties file"+lineBreak, os.Args[1:]) - os.Exit(1) - } - confFile := os.Args[1] - propertiesFile := os.Args[2] - if err := updateConfFile(confFile); err != nil { - fmt.Println(err) - os.Exit(1) - } - if err := updatePropertiesFile(propertiesFile); err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/mmsconfiguration/edit_mms_configuration_test.go b/mmsconfiguration/edit_mms_configuration_test.go deleted file mode 100755 index 2812ab5..0000000 --- a/mmsconfiguration/edit_mms_configuration_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "math/rand" - "os" - "strings" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestEditMmsConfiguration_UpdateConfFile_Mms(t *testing.T) { - confFile := _createTestConfFile() - _ = os.Setenv("CUSTOM_JAVA_MMS_UI_OPTS", "-Xmx4000m -Xms4000m") - err := updateConfFile(confFile) - assert.NoError(t, err) - updatedContent := _readLinesFromFile(confFile) - assert.Equal(t, updatedContent[7], "JAVA_MMS_UI_OPTS=\"${JAVA_MMS_UI_OPTS} -Xmx4000m -Xms4000m\"") -} - -func TestEditMmsConfiguration_UpdateConfFile_BackupDaemon(t *testing.T) { - confFile := _createTestConfFile() - _ = os.Setenv("BACKUP_DAEMON", "something") - _ = os.Setenv("CUSTOM_JAVA_DAEMON_OPTS", "-Xmx4000m -Xms4000m") - err := updateConfFile(confFile) - assert.NoError(t, err) - updatedContent := _readLinesFromFile(confFile) - assert.Equal(t, updatedContent[7], "JAVA_DAEMON_OPTS=\"${JAVA_DAEMON_OPTS} -Xmx4000m -Xms4000m\"") -} - -func TestEditMmsConfiguration_UpdatePropertiesFile(t *testing.T) { - val := fmt.Sprintf("test%d", rand.Intn(1000)) - key := "OM_PROP_test_edit_mms_configuration_get_om_props" - _ = os.Setenv(key, val) - props := getOmPropertiesFromEnvVars() - assert.Equal(t, props["test.edit.mms.configuration.get.om.props"], val) - _ = os.Unsetenv(key) -} - -func TestEditMmsConfiguration_GetOmPropertiesFromEnvVars(t *testing.T) { - _ = os.Setenv("OM_PROP_mms_test_prop", "somethingNew") - _ = os.Setenv("OM_PROP_mms_test_prop_new", "400") - - propFile := _createTestPropertiesFile() - err := updatePropertiesFile(propFile) - assert.NoError(t, err) - - updatedContent := _readLinesFromFile(propFile) - assert.Equal(t, updatedContent[0], "mms.prop=1234") - assert.Equal(t, updatedContent[1], "mms.test.prop5=") - assert.Equal(t, updatedContent[2], "mms.test.prop=somethingNew") - assert.Equal(t, updatedContent[3], "mms.test.prop.new=400") -} - -func _createTestConfFile() string { - contents := "JAVA_MMS_UI_OPTS=\"${JAVA_MMS_UI_OPTS} -Xmx4352m -Xss328k -Xms4352m -XX:NewSize=600m -Xmn1500m -XX:ReservedCodeCacheSize=128m -XX:-OmitStackTraceInFastThrow\"\n" - contents += "JAVA_DAEMON_OPTS= \"${JAVA_DAEMON_OPTS} -DMONGO.BIN.PREFIX=\"\n\n" - return _writeTempFileWithContent(contents, "conf") -} - -func _createTestPropertiesFile() string { - contents := "mms.prop=1234\nmms.test.prop5=\nmms.test.prop=something" - return _writeTempFileWithContent(contents, "prop") -} - -func _readLinesFromFile(name string) []string { - content, _ := ioutil.ReadFile(name) - return strings.Split(string(content), "\n") -} - -func _writeTempFileWithContent(content string, prefix string) string { - tmpfile, _ := ioutil.TempFile("", prefix) - - _, _ = tmpfile.WriteString(content) - - _ = tmpfile.Close() - - return tmpfile.Name() - -} diff --git a/scripts/docker-entry-point.sh b/scripts/docker-entry-point.sh deleted file mode 100755 index 669380c..0000000 --- a/scripts/docker-entry-point.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# the function reacting on SIGTERM command sent by the container on its shutdown. Redirects the signal -# to the child process ("tail" in this case) -cleanup () { - echo "Caught SIGTERM signal." - kill -TERM "$child" -} - -# we need to change the Home directory for current bash so that the gen key was found correctly -# (the key is searched in "${HOME}/.mongodb-mms/gen.key") -HOME=${MMS_HOME} - -# Execute script that updates properties and conf file used to start ops manager -echo "Updating configuration properties file ${MMS_PROP_FILE} and conf file ${MMS_CONF_FILE}" -/opt/scripts/mmsconfiguration ${MMS_CONF_FILE} ${MMS_PROP_FILE} - -if [[ -z ${BACKUP_DAEMON+x} ]]; then - echo "Starting Ops Manager" - ${MMS_HOME}/bin/mongodb-mms start_mms || { - echo "Startup of Ops Manager failed with code $?" - if [[ -f ${MMS_LOG_DIR}/mms0-startup.log ]]; then - echo - echo "mms0-startup.log:" - echo - cat "${MMS_LOG_DIR}/mms0-startup.log" - fi - if [[ -f ${MMS_LOG_DIR}/mms0.log ]]; then - echo - echo "mms0.log:" - echo - cat "${MMS_LOG_DIR}/mms0.log" - fi - if [[ -f ${MMS_LOG_DIR}/mms-migration.log ]]; then - echo - echo "mms-migration.log" - echo - cat "${MMS_LOG_DIR}/mms-migration.log" - fi - exit 1 - } - - trap cleanup SIGTERM - tail -F -n 1000 "${MMS_LOG_DIR}/mms0.log" "${MMS_LOG_DIR}/mms0-startup.log" "${MMS_LOG_DIR}/mms-migration.log" & -else - echo "Starting Ops Manager Backup Daemon" - ${MMS_HOME}/bin/mongodb-mms start_backup_daemon - trap cleanup SIGTERM - - tail -F "${MMS_LOG_DIR}/daemon.log" & -fi - -child=$! -wait "$child" -- GitLab From a2798b43c79016cbe9aed9d3b5d32bfe659ae20f Mon Sep 17 00:00:00 2001 From: Anton Lisovenko Date: Fri, 31 Jul 2020 09:52:01 +0100 Subject: [PATCH 2/5] using shell script from local /scripts directory --- Dockerfile | 4 +-- scripts/docker-entry-point.sh | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 scripts/docker-entry-point.sh diff --git a/Dockerfile b/Dockerfile index c186a9b..d520a73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG BASE_REGISTRY=nexus-docker-secure.levelup-nexus.svc.cluster.local:18082 ARG BASE_IMAGE=redhat/ubi/ubi7 ARG BASE_TAG=7.8 -ARG VERSION +ARG VERSION=1.0.1 FROM quay.io/mongodb/mongodb-enterprise-init-ops-manager:${VERSION} as official @@ -20,8 +20,8 @@ LABEL name="MongoDB Enterprise Ops Manager Init" \ description="Startup Scripts for MongoDB Enterprise Ops Manager" COPY --from=official /scripts/mmsconfiguration /scripts/ -COPY --from=official /scripts/docker-entry-point.sh /scripts/ COPY --from=official /licenses/mongodb-enterprise-ops-manager /licenses/ +COPY ./scripts/docker-entry-point.sh /scripts/ USER 2000 ENTRYPOINT [ "/bin/cp", "-f", "/scripts/docker-entry-point.sh", "/scripts/mmsconfiguration", "/opt/scripts/" ] diff --git a/scripts/docker-entry-point.sh b/scripts/docker-entry-point.sh new file mode 100755 index 0000000..669380c --- /dev/null +++ b/scripts/docker-entry-point.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# the function reacting on SIGTERM command sent by the container on its shutdown. Redirects the signal +# to the child process ("tail" in this case) +cleanup () { + echo "Caught SIGTERM signal." + kill -TERM "$child" +} + +# we need to change the Home directory for current bash so that the gen key was found correctly +# (the key is searched in "${HOME}/.mongodb-mms/gen.key") +HOME=${MMS_HOME} + +# Execute script that updates properties and conf file used to start ops manager +echo "Updating configuration properties file ${MMS_PROP_FILE} and conf file ${MMS_CONF_FILE}" +/opt/scripts/mmsconfiguration ${MMS_CONF_FILE} ${MMS_PROP_FILE} + +if [[ -z ${BACKUP_DAEMON+x} ]]; then + echo "Starting Ops Manager" + ${MMS_HOME}/bin/mongodb-mms start_mms || { + echo "Startup of Ops Manager failed with code $?" + if [[ -f ${MMS_LOG_DIR}/mms0-startup.log ]]; then + echo + echo "mms0-startup.log:" + echo + cat "${MMS_LOG_DIR}/mms0-startup.log" + fi + if [[ -f ${MMS_LOG_DIR}/mms0.log ]]; then + echo + echo "mms0.log:" + echo + cat "${MMS_LOG_DIR}/mms0.log" + fi + if [[ -f ${MMS_LOG_DIR}/mms-migration.log ]]; then + echo + echo "mms-migration.log" + echo + cat "${MMS_LOG_DIR}/mms-migration.log" + fi + exit 1 + } + + trap cleanup SIGTERM + tail -F -n 1000 "${MMS_LOG_DIR}/mms0.log" "${MMS_LOG_DIR}/mms0-startup.log" "${MMS_LOG_DIR}/mms-migration.log" & +else + echo "Starting Ops Manager Backup Daemon" + ${MMS_HOME}/bin/mongodb-mms start_backup_daemon + trap cleanup SIGTERM + + tail -F "${MMS_LOG_DIR}/daemon.log" & +fi + +child=$! +wait "$child" -- GitLab From d251f0af97674bb9ada135754a708fff07cf3187 Mon Sep 17 00:00:00 2001 From: Anton Lisovenko Date: Fri, 31 Jul 2020 14:27:20 +0100 Subject: [PATCH 3/5] using 1.0.0 base image (as it was used by Operator 1.5.3) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d520a73..02071c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG BASE_REGISTRY=nexus-docker-secure.levelup-nexus.svc.cluster.local:18082 ARG BASE_IMAGE=redhat/ubi/ubi7 ARG BASE_TAG=7.8 -ARG VERSION=1.0.1 +ARG VERSION=1.0.0 FROM quay.io/mongodb/mongodb-enterprise-init-ops-manager:${VERSION} as official -- GitLab From 979b09cf5c751b822f36b98a829c1f49507e7f94 Mon Sep 17 00:00:00 2001 From: Anton Lisovenko Date: Fri, 31 Jul 2020 15:50:48 +0100 Subject: [PATCH 4/5] download.json --- download.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/download.json b/download.json index 92e0570..48f65aa 100755 --- a/download.json +++ b/download.json @@ -1,8 +1,9 @@ { "resources": [ { - "url": "docker://docker.io/golang@sha256:2841da2227dc15e18ca5ec1e95f3cb166005361c0eb0313ce82d2e5ccff116dd", - "tag": "golang:1.13" + "url": "docker://quay.io/mongodb/mongodb-enterprise-init-ops-manager@sha256:3577d0279a4a6fa409374d5a11a986ea93bf015a998fffe8a78de4d78c3e6b0d", + "tag": "quay.io/mongodb/mongodb-enterprise-init-ops-manager:1.0.0" } ] } + -- GitLab From 1f5be9b04a913f86588eab50e18d9269b1ce6c2e Mon Sep 17 00:00:00 2001 From: Matt Vasquez Date: Fri, 31 Jul 2020 22:08:46 +0000 Subject: [PATCH 5/5] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 20beed0..047c547 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,3 @@ @Library('DCCSCR@master') _ -dccscrPipeline(version: "1.5.3") +dccscrPipeline(version: "1.0.1") -- GitLab