diff --git a/Dockerfile b/Dockerfile index fddbabad2bacc675adbad810b3b1db0ace2d2fa2..02071c224e9616a79002ba83f49aadfdcfde3eb0 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 +ARG VERSION=1.0.0 -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 - -##### +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 /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/Jenkinsfile b/Jenkinsfile index 20beed0d2b8e7bca05480e31a5e0d2356ebcb379..047c547e6c023997c99f97c5cac7f8f2a2a02f73 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,3 @@ @Library('DCCSCR@master') _ -dccscrPipeline(version: "1.5.3") +dccscrPipeline(version: "1.0.1") diff --git a/download.json b/download.json index 92e05705926deacea5e62bc3773bdbeaba255629..48f65aa40c375e1f43c8b7ce99532bc32672a4ed 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" } ] } + diff --git a/mmsconfiguration/edit_mms_configuration.go b/mmsconfiguration/edit_mms_configuration.go deleted file mode 100755 index faa862647537155c94c5e0e3ed3d0a4cbd082d7a..0000000000000000000000000000000000000000 --- 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 2812ab56843fdb0df4810fed366bd90a52037121..0000000000000000000000000000000000000000 --- 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() - -}