From 539596d37aee445980465516681d3f3aadcae192 Mon Sep 17 00:00:00 2001 From: "marcis.pauls" Date: Fri, 28 Jun 2019 14:53:47 +0300 Subject: [PATCH] updated nexus to 3.17.0 --- Dockerfile | 75 +++++++++++-------- README.md | 22 +++++- resources/conf/addUpdatescript.groovy | 57 -------------- resources/jmxremote.password.tmpl | 1 + resources/nexus.sh | 7 +- resources/provision.sh | 102 ++++++++++++++++++-------- 6 files changed, 139 insertions(+), 125 deletions(-) delete mode 100644 resources/conf/addUpdatescript.groovy create mode 100644 resources/jmxremote.password.tmpl diff --git a/Dockerfile b/Dockerfile index bb7d0ba..bbce972 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM sonatype/nexus3:3.12.1 +FROM sonatype/nexus3:3.17.0 ENV LDAP_ENABLED=true \ @@ -24,18 +24,34 @@ ENV LDAP_ENABLED=true \ LDAP_USER_BASE_DN=ou=people \ LDAP_USER_REAL_NAME_ATTRIBUTE=cn \ LDAP_GROUP_MEMBER_FORMAT='${dn}' \ - NEXUS_CREATE_CUSTOM_ROLES=false + NEXUS_CREATE_CUSTOM_ROLES=false \ + NEXUS_JMX_PASSWORD=adopnexusjmx \ + DOCKERIZE_VERSION=v0.6.1 USER root -# Install groovy -RUN yum install -y zip unzip -RUN yum install -y which +RUN yum install -y epel-release + +RUN yum install -y \ + yum-plugin-fastestmirror-1.1.31-50.el7 \ + yum-utils-1.1.31-50.el7 \ + yum-plugin-ovl-1.1.31-50.el7 \ + systemd-libs-219-62.el7_6.6 \ + systemd-219-62.el7_6.6 \ + gnupg2-2.0.22-5.el7_5 \ + bind-license-9.9.4-74.el7_6.1Z \ + zip \ + unzip \ + which \ + jq + RUN curl -s get.sdkman.io | bash RUN source "$HOME/.sdkman/bin/sdkman-init.sh" -RUN yes | /bin/bash -l -c "sdk install groovy 2.4.15" +RUN yes | /bin/bash -l -c "sdk install groovy 2.4.17" -ENV PATH="/root/.sdkman/candidates/groovy/2.4.15/bin:${PATH}" +RUN curl -Ls https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar -C /usr/local/bin -xz + +ENV PATH="/root/.sdkman/candidates/groovy/2.4.17/bin:${PATH}" RUN export PATH COPY resources/nexus.sh /usr/local/bin/ @@ -43,31 +59,28 @@ COPY resources/provision.sh /usr/local/bin/ COPY resources/ /resources/ COPY resources/conf/grapeConfig.xml /root/.groovy/ -RUN yum update -y yum-plugin-fastestmirror-1.1.31-50.el7 \ - yum-utils-1.1.31-50.el7 \ - yum-plugin-ovl-1.1.31-50.el7 \ - systemd-libs-219-62.el7_6.2 \ - systemd-219-62.el7_6.2 \ - gnupg2-2.0.22-5.el7_5 \ - bind-license-9.9.4-72.el7 - -RUN grape install org.sonatype.nexus nexus-rest-client 3.6.0-02 \ - && grape install org.sonatype.nexus nexus-rest-jackson2 3.6.0-02 \ - && grape install org.sonatype.nexus nexus-script 3.6.0-02 \ - && grape install org.jboss.spec.javax.servlet jboss-servlet-api_3.1_spec 1.0.0.Final \ - && grape install com.fasterxml.jackson.core jackson-core 2.8.6 \ - && grape install com.fasterxml.jackson.core jackson-databind 2.8.6 \ - && grape install com.fasterxml.jackson.core jackson-annotations 2.8.6 \ - && grape install com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider 2.8.6 \ - && grape install org.jboss.spec.javax.ws.rs jboss-jaxrs-api_2.0_spec 1.0.1.Beta1 \ - && grape install org.jboss.spec.javax.annotation jboss-annotations-api_1.2_spec 1.0.0.Final \ - && grape install javax.activation activation 1.1.1 \ +RUN grape install org.jboss.spec.javax.ws.rs jboss-jaxrs-api_2.0_spec 1.0.1.Final \ + && grape install org.jboss.spec.javax.servlet jboss-servlet-api_3.1_spec 1.0.2.Final \ + && grape install org.jboss.spec.javax.annotation jboss-annotations-api_1.2_spec 1.0.2.Final \ + && grape install javax.activation activation 1.1 \ + && grape install net.jcip jcip-annotations 1.0 \ + && grape install org.jboss.logging jboss-logging-annotations 2.2.0.Final \ + && grape install org.jboss.logging jboss-logging-processor 2.2.0.Final \ + && grape install com.sun.xml.bind jaxb-impl 2.3.2 \ + && grape install org.apache.james apache-mime4j 0.6.1 \ + && grape install org.sonatype.nexus nexus-rest-client 3.17.0-01 \ + && grape install org.sonatype.nexus nexus-rest-jackson2 3.17.0-01 \ + && grape install org.sonatype.nexus nexus-script 3.17.0-01 \ + && grape install com.fasterxml.jackson.core jackson-core 2.9.2 \ + && grape install com.fasterxml.jackson.core jackson-databind 2.9.2 \ + && grape install com.fasterxml.jackson.core jackson-annotations 2.9.2 \ + && grape install com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider 2.9.2 \ + && grape install javax.activation activation 1.1 \ && grape install net.jcip jcip-annotations 1.0 \ - && grape install org.jboss.logging jboss-logging-annotations 2.0.1.Final \ - && grape install org.jboss.logging jboss-logging-processor 2.0.1.Final \ - && grape install com.sun.xml.bind jaxb-impl 2.2.7 \ - && grape install com.sun.mail javax.mail 1.5.6 \ - && grape install org.apache.james apache-mime4j 0.6 + && grape install org.jboss.logging jboss-logging-annotations 2.2.0.Final \ + && grape install org.jboss.logging jboss-logging-processor 2.2.0.Final \ + && grape install com.sun.xml.bind jaxb-impl 2.3.2 \ + && grape install com.sun.mail javax.mail 1.6.1 RUN chmod u+x /usr/local/bin/nexus.sh && chmod u+x /usr/local/bin/provision.sh diff --git a/README.md b/README.md index 855a402..b336aee 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ #Supported tags and respective Dockerfile links -- [`0.2.0` (*0.2.0/Dockerfile*)](https://github.com/Accenture/adop-nexus/blob/master/Dockerfile.md) +- [`3.17.0` (*3.17.0/Dockerfile*)](https://github.com/Accenture/adop-nexus/blob/master/Dockerfile) # What is adop-nexus? -We have upgarded the nexus version to 3.7.1 and hence this image will enable the features of the latest version. To read more please cclick on the link -> https://books.sonatype.com/nexus-book/3.0/reference/ +We have upgraded the nexus3 version to 3.17.0 and hence this image will enable the features of the latest version. To read more please cclick on the link -> https://books.sonatype.com/nexus-book/3.0/reference/ ![logo](http://blog.sonatype.com/wp-content/uploads/2010/01/nexus-small.png) @@ -103,14 +103,28 @@ Additionally, the image reads the following LDAP environment variables if you wa * `USER_AGENT`, if set, you can enable Basic Authentication. [How do I enable WWW-Authenticate headers for content 401 responses] (https://support.sonatype.com/hc/en-us/articles/213465078-How-do-I-enable-WWW-Authenticate-headers-for-content-401-responses) + # JMX Monitoring +It is possible to leverage JMX monitoring of Nexus if so desired. This requires launching Nexus with several JVM options +wrapped into an env variable INSTALL4J_ADD_VM_PARAMS (https://github.com/sonatype/docker-nexus3/blob/master/README.md#notes) +Basic authentication is supported. + +Default password is adopnexusjmx. This can be changed using an environment variable NEXUS_JMX_PASSWORD. + +Example launch with JMX with auth enabled: + + $ docker run -d -p 8081:8081 \ + --name nexus \ + -e NEXUS_JMX_PASSWORD="topsecret" \ + -e INSTALL4J_ADD_VM_PARAMS="-Xms1200m -Xmx1200m -XX:MaxDirectMemorySize=2g -Djava.util.prefs.userRoot=${NEXUS_DATA}/javaprefs -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=15666 -Dcom.sun.management.jmxremote.rmi.port=15666 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/resources/jmxremote.password -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost" \ + accenture/adop-nexus # License Please view [licence information](LICENCE.md) for the software contained on this image. #Supported Docker versions -This image is officially supported on Docker version 1.9.1. -Support for older versions (down to 1.6) is provided on a best-effort basis. +This image is officially supported on Docker version 18.09.4. +Support for older versions (down to 1.9) is provided on a best-effort basis. # User feedback diff --git a/resources/conf/addUpdatescript.groovy b/resources/conf/addUpdatescript.groovy deleted file mode 100644 index b9b39bf..0000000 --- a/resources/conf/addUpdatescript.groovy +++ /dev/null @@ -1,57 +0,0 @@ -import javax.ws.rs.NotFoundException -import javax.ws.rs.NotAllowedException -import org.sonatype.nexus.script.ScriptClient -import org.sonatype.nexus.script.ScriptXO - -import org.jboss.resteasy.client.jaxrs.BasicAuthentication -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder - -CliBuilder cli = new CliBuilder( - usage: 'groovy addUpdateScript.groovy -u admin -p admin123 -f scriptFile.groovy [-n explicitName] [-h nx3Url]') -cli.with { - u longOpt: 'username', args: 1, required: true, 'A User with permission to use the NX3 Script resource' - p longOpt: 'password', args: 1, required: true, 'Password for given User' - f longOpt: 'file', args: 1, required: true, 'Script file to send to NX3' - h longOpt: 'host', args: 1, 'NX3 host url (including port if necessary). Defaults to http://localhost:8081' - n longOpt: 'name', args: 1, 'Name to store Script file under. Defaults to the name of the Script file.' -} -def options = cli.parse(args) -if (!options) { - return -} - -def file = new File(options.f) -assert file.exists() - -def host = options.h ?: 'http://localhost:8081' -def resource = 'service/' - -ScriptClient scripts = new ResteasyClientBuilder() - .build() - .register(new BasicAuthentication(options.u, options.p)) - .target("$host/$resource") - .proxy(ScriptClient) - -String name = options.n ?: file.name - -// Look to see if a script with this name already exists so we can update if necessary -boolean newScript = true -try { - scripts.read(name) - newScript = false - println "Existing Script named '$name' will be updated" -} -catch (NotFoundException e) { - println "Script named '$name' will be created" -} - -def script = new ScriptXO(name, file.text, 'groovy') -if (newScript) { - scripts.add(script) -} -else { - scripts.edit(name, script) -} - -println "Stored scripts are now: ${scripts.browse().collect { it.name }}" - diff --git a/resources/jmxremote.password.tmpl b/resources/jmxremote.password.tmpl new file mode 100644 index 0000000..833e1ab --- /dev/null +++ b/resources/jmxremote.password.tmpl @@ -0,0 +1 @@ +monitorRole {{ .Env.NEXUS_JMX_PASSWORD }} diff --git a/resources/nexus.sh b/resources/nexus.sh index 42a3075..f10fc2e 100644 --- a/resources/nexus.sh +++ b/resources/nexus.sh @@ -18,13 +18,12 @@ fi chown nexus:nexus "${NEXUS_DATA}" chown -R nexus:nexus $(ls ${NEXUS_DATA} | awk -v NEXUS_DATA="${NEXUS_DATA}/" '{if($1 != "blobs"){ print NEXUS_DATA$1 }}') -if [ ! -f ${NEXUS_DATA}/current_local_password ]; then - echo admin123 > ${NEXUS_DATA}/current_local_password -fi +# Dockerizing jmxpassword file +dockerize -template /resources/jmxremote.password.tmpl:/resources/jmxremote.password +chown -R nexus:nexus /resources && chmod 600 /resources/jmxremote.password echo "Executing provision.sh" nohup /usr/local/bin/provision.sh & # Start nexus as the nexus user su -c "${SONATYPE_DIR}/start-nexus-repository-manager.sh" -s /bin/sh nexus - diff --git a/resources/provision.sh b/resources/provision.sh index b1b3ef0..e7abccd 100755 --- a/resources/provision.sh +++ b/resources/provision.sh @@ -6,15 +6,6 @@ # fail if anything errors set -e -username=admin - -if [ -f ${NEXUS_DATA}/current_local_password ]; then - password=$(<${NEXUS_DATA}/current_local_password) -else - echo "[ERR] File ${NEXUS_DATA}/current_local_password doesn't exist. This file contain your current local password." - exit 1 -fi - nexus_host=http://localhost:8081/$NEXUS_CONTEXT pretty_sleep() { @@ -32,34 +23,42 @@ echo "* Waiting for the Nexus3 to become available - this can take a few minutes TOOL_SLEEP_TIME=30 until [[ $(curl -I -s -u "${username}":"${password}" localhost:8081/${NEXUS_CONTEXT}/|head -n 1|cut -d$' ' -f2) == 200 ]]; do pretty_sleep ${TOOL_SLEEP_TIME} Nexus3; done +username=admin + +if [ -f ${NEXUS_DATA}/admin.password ]; then + password=$(<${NEXUS_DATA}/admin.password) +else + echo "[ERR] File ${NEXUS_DATA}/admin.password doesn't exist. This file contain your current local password." + exit 1 +fi + function addAndRunScript() { name=$1 file=$2 eval args="${3:-false}" - classPath=$(find /root/.groovy/grapes -name *.jar) - groovy -cp $(echo $classPath | sed 's/ /:/g') -Dgroovy.grape.report.downloads=true resources/conf/addUpdatescript.groovy -u "$username" -p "$password" -n "$name" -f "$file" -h "$nexus_host" + content=$( ${NEXUS_DATA}/current_local_password + echo ${NEXUS_ADMIN_PASSWORD} > ${NEXUS_DATA}/admin.password fi - printf "\nProvisioning Scripts Completed\n\n"