Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from sonatype:main #19

Merged
merged 30 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a277eff
NEXUS-42431-Alpine
mburkert3 Jun 5, 2024
24d3c88
Change groupID to 200
mburkert3 Jun 6, 2024
6b2e71e
Change DOCKER_TYPE to alpine
mburkert3 Jun 7, 2024
ab8b316
NEXUS-42419 Alpine Images
mburkert3 Jun 9, 2024
67403bf
NEXUS-42419 Alpine Images
mburkert3 Jun 9, 2024
5f35ba1
NEXUS-42419 Alpine Images
mburkert3 Jun 9, 2024
3474faa
Remove Java8 Alpine
mburkert3 Jun 10, 2024
1e3df47
Remove Java8 Alpine
mburkert3 Jun 10, 2024
ed420a2
Delete Java8 Alpine Dockerfile
mburkert3 Jun 10, 2024
7fbab56
Rename
mburkert3 Jun 11, 2024
43cd20b
Rename Dockerfile.alpine.java11
mburkert3 Jun 11, 2024
7963398
Update Jenkinsfile.alpine
mburkert3 Jun 11, 2024
18da6a9
Add docker-nexus3-alpine scan
mburkert3 Jun 12, 2024
7a718e0
Add docker-nexus3-alpine scan
mburkert3 Jun 12, 2024
51fc28b
Add docker-nexus3-alpine scan
mburkert3 Jun 12, 2024
58d2a81
Change Alpine Docker-nexus3 logic
mburkert3 Jun 13, 2024
92c2a9e
Change Alpine Docker-nexus3 logic
mburkert3 Jun 13, 2024
2bc127c
Merge pull request #198 from sonatype/NEXUS-42419-Alpine-Release
mburkert3 Jun 14, 2024
c50a420
Add Alpine Description
mburkert3 Jun 14, 2024
09620ae
Add Alpine Description
mburkert3 Jun 14, 2024
1f34e11
NEXUS-43198: Added support for alpine tags in SBOM release pipeline (…
jlhuerfanor Jun 18, 2024
36e3c5c
Update README.md
mburkert3 Jun 18, 2024
9989547
update nexus.vmoptions
tsawan Jun 18, 2024
2d26247
Merge pull request #196 from sonatype/NEXUS-42431-Alpine
tsawan Jun 18, 2024
77a9588
fixing alpine images
codetreras Jun 19, 2024
05d3b64
fixing alpine image sha for java 17
codetreras Jun 19, 2024
98eb54f
removing java 8 alpine image
codetreras Jun 19, 2024
ec2dd05
removing alpine temp Jenkins file
codetreras Jun 19, 2024
db0309f
Merge pull request #200 from sonatype/NEXUS-42416
mburkert3 Jun 25, 2024
e45349f
Merge pull request #205 from sonatype/hotfix-alpine-image
codetreras Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions Dockerfile.alpine.java11
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2016-present Sonatype, Inc.
#
# 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.

FROM alpine

LABEL name="Nexus Repository Manager" \
maintainer="Sonatype <[email protected]>" \
vendor=Sonatype \
version="3.69.0-02" \
release="3.69.0" \
url="https://sonatype.com" \
summary="The Nexus Repository Manager server \
with universal support for popular component formats." \
description="The Nexus Repository Manager server \
with universal support for popular component formats." \
run="docker run -d --name NAME \
-p 8081:8081 \
IMAGE" \
stop="docker stop NAME" \
com.sonatype.license="Apache License, Version 2.0" \
com.sonatype.name="Nexus Repository Manager base image" \
io.k8s.description="The Nexus Repository Manager server \
with universal support for popular component formats." \
io.k8s.display-name="Nexus Repository Manager" \
io.openshift.expose-services="8081:8081" \
io.openshift.tags="Sonatype,Nexus,Repository Manager"

ARG NEXUS_VERSION=3.69.0-02
ARG JAVA_VERSION=java11
ARG NEXUS_DOWNLOAD_URL=https://download.sonatype.com/nexus/3/nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz
ARG NEXUS_DOWNLOAD_SHA256_HASH=4a22cd3f2a2bd3fef46e2f13b57abfcca9e6244c36cee8c2aac226a333524c07

# configure nexus runtime
ENV SONATYPE_DIR=/opt/sonatype
ENV NEXUS_HOME=${SONATYPE_DIR}/nexus \
NEXUS_DATA=/nexus-data \
NEXUS_CONTEXT='' \
SONATYPE_WORK=${SONATYPE_DIR}/sonatype-work \
DOCKER_TYPE='alpine'

# Install Java & tar
RUN apk add openjdk11 tar procps gzip curl shadow \
&& apk cache clean \
&& groupadd --gid 200 -r nexus \
&& useradd --uid 200 -r nexus -g nexus -s /bin/false -d /opt/sonatype/nexus -c 'Nexus Repository Manager user'

WORKDIR ${SONATYPE_DIR}

# Download nexus & setup directories
RUN curl -L ${NEXUS_DOWNLOAD_URL} --output nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
&& echo "${NEXUS_DOWNLOAD_SHA256_HASH} nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz" > nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& sha256sum -c nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& tar xvf nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
&& rm -f nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& mv nexus-${NEXUS_VERSION} $NEXUS_HOME \
&& chown -R nexus:nexus ${SONATYPE_WORK} \
&& mv ${SONATYPE_WORK}/nexus3 ${NEXUS_DATA} \
&& ln -s ${NEXUS_DATA} ${SONATYPE_WORK}/nexus3

# Removing java memory settings from nexus.vmoptions since now we use INSTALL4J_ADD_VM_PARAMS
RUN sed -i '/^-Xms/d;/^-Xmx/d;/^-XX:MaxDirectMemorySize/d' $NEXUS_HOME/bin/nexus.vmoptions

RUN echo "#!/bin/bash" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& echo "cd /opt/sonatype/nexus" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& echo "exec ./bin/nexus run" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& chmod a+x ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& sed -e '/^nexus-context/ s:$:${NEXUS_CONTEXT}:' -i ${NEXUS_HOME}/etc/nexus-default.properties

RUN apk del gzip shadow

VOLUME ${NEXUS_DATA}

EXPOSE 8081
USER nexus

ENV INSTALL4J_ADD_VM_PARAMS="-Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -Djava.util.prefs.userRoot=${NEXUS_DATA}/javaprefs"

CMD ["/opt/sonatype/nexus/bin/nexus", "run"]
89 changes: 89 additions & 0 deletions Dockerfile.alpine.java17
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2016-present Sonatype, Inc.
#
# 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.

FROM alpine

LABEL name="Nexus Repository Manager" \
maintainer="Sonatype <[email protected]>" \
vendor=Sonatype \
version="3.69.0-02" \
release="3.69.0" \
url="https://sonatype.com" \
summary="The Nexus Repository Manager server \
with universal support for popular component formats." \
description="The Nexus Repository Manager server \
with universal support for popular component formats." \
run="docker run -d --name NAME \
-p 8081:8081 \
IMAGE" \
stop="docker stop NAME" \
com.sonatype.license="Apache License, Version 2.0" \
com.sonatype.name="Nexus Repository Manager base image" \
io.k8s.description="The Nexus Repository Manager server \
with universal support for popular component formats." \
io.k8s.display-name="Nexus Repository Manager" \
io.openshift.expose-services="8081:8081" \
io.openshift.tags="Sonatype,Nexus,Repository Manager"

ARG NEXUS_VERSION=3.69.0-02
ARG JAVA_VERSION=java17
ARG NEXUS_DOWNLOAD_URL=https://download.sonatype.com/nexus/3/nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz
ARG NEXUS_DOWNLOAD_SHA256_HASH=59ed008f74dea1a7f1a36dd896ea552c1d35ff537ec8e5669addd87776ecc7e2

# configure nexus runtime
ENV SONATYPE_DIR=/opt/sonatype
ENV NEXUS_HOME=${SONATYPE_DIR}/nexus \
NEXUS_DATA=/nexus-data \
NEXUS_CONTEXT='' \
SONATYPE_WORK=${SONATYPE_DIR}/sonatype-work \
DOCKER_TYPE='alpine'

# Install Java & tar
RUN apk add openjdk17 tar procps gzip curl shadow \
&& apk cache clean \
&& groupadd --gid 200 -r nexus \
&& useradd --uid 200 -r nexus -g nexus -s /bin/false -d /opt/sonatype/nexus -c 'Nexus Repository Manager user'

WORKDIR ${SONATYPE_DIR}

# Download nexus & setup directories
RUN curl -L ${NEXUS_DOWNLOAD_URL} --output nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
&& echo "${NEXUS_DOWNLOAD_SHA256_HASH} nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz" > nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& sha256sum -c nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& tar xvf nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
&& rm -f nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz.sha256 \
&& mv nexus-${NEXUS_VERSION} $NEXUS_HOME \
&& chown -R nexus:nexus ${SONATYPE_WORK} \
&& mv ${SONATYPE_WORK}/nexus3 ${NEXUS_DATA} \
&& ln -s ${NEXUS_DATA} ${SONATYPE_WORK}/nexus3

# Removing java memory settings from nexus.vmoptions since now we use INSTALL4J_ADD_VM_PARAMS
RUN sed -i '/^-Xms/d;/^-Xmx/d;/^-XX:MaxDirectMemorySize/d' $NEXUS_HOME/bin/nexus.vmoptions

RUN echo "#!/bin/bash" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& echo "cd /opt/sonatype/nexus" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& echo "exec ./bin/nexus run" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& chmod a+x ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
&& sed -e '/^nexus-context/ s:$:${NEXUS_CONTEXT}:' -i ${NEXUS_HOME}/etc/nexus-default.properties

RUN apk del gzip shadow

VOLUME ${NEXUS_DATA}

EXPOSE 8081
USER nexus

ENV INSTALL4J_ADD_VM_PARAMS="-Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -Djava.util.prefs.userRoot=${NEXUS_DATA}/javaprefs"

CMD ["/opt/sonatype/nexus/bin/nexus", "run"]
77 changes: 50 additions & 27 deletions Jenkinsfile-Internal-Release
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ properties([
])

node('ubuntu-zion') {
def commitId, commitDate, version, imageId, branch
def commitId, commitDate, version, imageId, alpineImageId, branch
def imageName = 'sonatype/nexus3',
archiveName = 'docker-nexus3'

Expand All @@ -32,6 +32,14 @@ node('ubuntu-zion') {
def DOCKERFILE_JAVA_8 = 'Dockerfile'
def DOCKERFILE_JAVA_11 = 'Dockerfile.java11'
def DOCKERFILE_JAVA_17 = 'Dockerfile.java17'
def DOCKERFILE_ALPINE_JAVA_11 = 'Dockerfile.alpine.java11'
def DOCKERFILE_ALPINE_JAVA_17 = 'Dockerfile.alpine.java17'

def dockerfileMap = [
(OPENJDK8) : [DOCKERFILE_JAVA_8],
(OPENJDK11): [DOCKERFILE_JAVA_11, DOCKERFILE_ALPINE_JAVA_11],
(OPENJDK17): [DOCKERFILE_JAVA_17, DOCKERFILE_ALPINE_JAVA_17]
]

try {
stage('Preparation') {
Expand All @@ -52,41 +60,46 @@ node('ubuntu-zion') {
if (params.nexus_repository_manager_version) {
stage('Update Repository Manager Version') {
OsTools.runSafe(this, "git checkout ${branch}")
def javaVersionsDockerfilesMap = [
(JAVA_8): DOCKERFILE_JAVA_8,
(JAVA_11): DOCKERFILE_JAVA_11,
(JAVA_17): DOCKERFILE_JAVA_17
]
javaVersionsDockerfilesMap.each { javaVersion, dockerfile ->
updateRepositoryManagerVersion("${pwd()}/${dockerfile}", javaVersion)
dockerfileMap.each { javaVersion, dockerfiles ->
dockerfiles.each { dockerfile ->
updateRepositoryManagerVersion("${pwd()}/${dockerfile}", javaVersion)
}
}
version = getShortVersion(params.nexus_repository_manager_version)
}
}
}
stage('Build') {
def dockerfilesMap = [
(OPENJDK8): DOCKERFILE_JAVA_8,
(OPENJDK11): DOCKERFILE_JAVA_11,
(OPENJDK17): DOCKERFILE_JAVA_17
]
def dockerfilePath = dockerfilesMap.get(params.java_version)
def dockerfilePath = dockerfileMap[params.java_version][0]
def alpineDockerfilePath = params.java_version == OPENJDK8 ? null : dockerfileMap[params.java_version][1]

stage('Build UBI Image') {
def baseImage = extractBaseImage(dockerfilePath)
def baseImageRefFactory = load 'scripts/BaseImageReference.groovy'
def baseImageReference = baseImageRefFactory.build(this, baseImage as String)
def baseImageReferenceStr = baseImageReference.getReference()
def hash = OsTools.runSafe(this, "docker build --quiet --label base-image-ref='${baseImageReferenceStr}' --no-cache --tag ${imageName} . -f ${dockerfilePath}")
imageId = hash.split(':')[1]
}
if (params.java_version != OPENJDK8) {
stage('Build Alpine Image') {
def hash = OsTools.runSafe(this, "docker build --quiet --no-cache --tag ${imageName}-alpine . -f ${alpineDockerfilePath}")
alpineImageId = hash.split(':')[1]
}
}
if (params.scan_for_policy_violations) {
stage('Evaluate Policies') {
runEvaluation({ stage ->
def isAlpine = alpineDockerfilePath != null && alpineDockerfilePath.contains('alpine')
def iqApplicationName = isAlpine ? 'docker-nexus3-alpine' : 'docker-nexus3'
def imageToScan = isAlpine ? "${imageName}-alpine" : imageName

nexusPolicyEvaluation(
iqStage: stage,
iqApplication: 'docker-nexus3',
iqScanPatterns: [[scanPattern: "container:${imageName}"]],
failBuildOnNetworkError: true,
)}, 'release')
iqStage: stage,
iqApplication: iqApplicationName,
iqScanPatterns: [[scanPattern: "container:${imageToScan}"]],
failBuildOnNetworkError: true,
)
}, 'release')
}
}
if (currentBuild.result == 'FAILURE') {
Expand All @@ -108,11 +121,22 @@ node('ubuntu-zion') {
]
def javaVersionSuffix = javaVersionSuffixesMap.get(params.java_version)

sh "docker tag ${imageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}"
// Push UBI images
sh "docker tag ${imageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}-ubi"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}-ubi"
if (params.java_version == OPENJDK8) {
sh "docker tag ${imageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}"
sh "docker tag ${imageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-ubi"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-ubi"
}

// Push Alpine images
if (params.java_version != OPENJDK8) {
sh "docker tag ${alpineImageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}-alpine"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-${javaVersionSuffix}-alpine"
if (params.java_version == OPENJDK11) {
sh "docker tag ${alpineImageId} docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-alpine"
sh "docker push docker-all.repo.sonatype.com/sonatype-internal/nexus3:${version}-alpine"
}
}
}
}
Expand Down Expand Up @@ -159,7 +183,7 @@ def updateRepositoryManagerVersion(dockerFileLocation, javaVersion) {
}
else {
// default URL
def defaultUrl = /https:\/\/download-staging.sonatype.com\/nexus\/3\/nexus-\$\{NEXUS_VERSION\}-\$\{JAVA_VERSION\}-unix\.tar\.gz/
def defaultUrl = /https:\/\/download-staging.sonatype.com\/nexus\/3\/nexus-\$\{NEXUS_VERSION\}-unix\.tar\.gz/
dockerFile = dockerFile.replaceAll(nexusUrlRegex, "\$1${defaultUrl}")

def normalizedUrl = "a".replaceAll(/./, "${defaultUrl}")
Expand All @@ -171,7 +195,6 @@ def updateRepositoryManagerVersion(dockerFileLocation, javaVersion) {
dockerFile = dockerFile.replaceAll(shaRegex, "\$1${sha}")

writeFile(file: dockerFileLocation, text: dockerFile)

}

def getSha(url) {
Expand All @@ -182,7 +205,7 @@ def getSha(url) {
return sha
}

def extractBaseImage (dockerFileLocation) {
def extractBaseImage(dockerFileLocation) {
def dockerFile = readFile(file: dockerFileLocation)
def baseImageRegex = "FROM\\s+([^\\s]+)"
def usedImages = dockerFile =~ baseImageRegex
Expand Down
Loading