Combined Jenkins job to publish aws resilient and non resilient helm charts

This commit is contained in:
Olu Shiyanbade 2022-08-24 17:01:44 +01:00
parent 4c6584ed83
commit f60bc6237d
7 changed files with 316 additions and 12 deletions

View File

@ -1,17 +1,20 @@
#
# Copyright (c) 2019-present Sonatype, Inc. All rights reserved.
# Includes the third-party code listed at http://links.sonatype.com/products/clm/attributions.
# "Sonatype" is a trademark of Sonatype, Inc.
# Copyright (c) 2020-present Sonatype, Inc. All rights reserved.
#
# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License Version 2.0.
# You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the Apache License Version 2.0 is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
#
# FROM docker-all.repo.sonatype.com/alpine:latest
# LABEL maintainer="operations-group@sontype.com"
FROM docker-all.repo.sonatype.com/alpine/helm:3.9.3
# RUN apk update
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
# WORKDIR /app
# COPY ./src ./
RUN mkdir /.local /.cache && chmod 777 /.local /.cache
# EXPOSE 8080
# CMD ["./runit"]

31
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2020-present Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
@Library(['private-pipeline-library', 'jenkins-shared', 'int-jenkins-shared']) _
dockerizedBuildPipeline(
prepare: {
githubStatusUpdate('pending')
},
buildAndTest: {
sh './build.sh'
},
skipVulnerabilityScan: true,
archiveArtifacts: 'docs/*',
testResults: ['**/test-output.xml'],
onSuccess: {
buildNotifications(currentBuild, env, 'main')
},
onFailure: {
buildNotifications(currentBuild, env, 'main')
}
)

145
Jenkinsfile-Release Normal file
View File

@ -0,0 +1,145 @@
/*
* Copyright (c) 2020-present Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
@Library(['private-pipeline-library', 'jenkins-shared', 'int-jenkins-shared']) _
final jira = [
versionPrefix: '', project: 'INT', projectId: '12410',
credentialId : 'jenkins-jira', autoRelease: true, failOnError: true
]
final jiraVersionMappings = [
'nexus-repository-manager-single-instance': 'helm-nxrm',
'nexus-repository-manager-aws-resilient-single-instance': 'helm-nxrm-aws-resiliency'
]
final chartLocation = [
'nexus-repository-manager-single-instance': 'single-inst-oss-pro-kubernetes',
'nexus-repository-manager-aws-resilient-single-instance': 'aws-single-instance-resiliency'
]
properties([
parameters([
choice(
choices: ['', 'nexus-repository-manager-single-instance', 'nexus-repository-manager-aws-resilient-single-instance'],
name: 'chart',
description: 'Chart to deploy.',
),
string(
name: 'appVersion',
description: 'Version of the application image, like "1.139.0"',
),
string(
name: 'chartVersion',
description: '(Optional) Version of the Chart, like "139.0.0". If omitted, it will be calculated from the appVersion.',
),
])
])
final chartVersion = calculateChartVersion(params.chartVersion, params.appVersion)
dockerizedBuildPipeline(
prepare: {
if (! params.chart) {
error('Chart parameter is required.')
}
if (! params.appVersion) {
error('The appVersion is required.')
}
githubStatusUpdate('pending')
},
buildAndTest: {
sonatypeZionGitConfig()
runSafely "git checkout ${gitBranch(env)}"
runSafely "./upgrade.sh ./${chartLocation[params.chart]} ${chartVersion} ${params.appVersion}"
runSafely './build.sh'
runSafely 'git add aws-single-instance-resiliency single-inst-oss-pro-kubernetes'
},
skipVulnerabilityScan: true,
archiveArtifacts: 'docs/*',
testResults: [],
deployCondition: { true },
deploy: {
runSafely 'git add docs'
runSafely "git commit -m 'Release Update for ${params.chart} ${chartVersion}'"
sshagent(credentials: [sonatypeZionCredentialsId()]) {
runSafely 'git push'
}
},
postDeploy: {
// Verify Index.yaml
String version = verifyIndexYamlAndTarFile(params.chart)
// Set Jira Fix Version
jira.versionPrefix = jiraVersionMappings[chart]
jiraSetFixVersion(jira, version)
// Create tags
String tagName = "${chart}-${version}"
runSafely "git tag -a ${tagName} -m 'Release Update: ${version}'"
sshagent(credentials: [sonatypeZionCredentialsId()]) {
runSafely "git push origin ${tagName}"
}
},
onSuccess: {
buildNotifications(currentBuild, env, 'main')
},
onFailure: {
buildNotifications(currentBuild, env, 'main')
}
)
String verifyIndexYamlAndTarFile(String chart) {
// Get current version
def indexFile = readYaml file: 'docs/index.yaml'
String version = indexFile.entries[chart][0].version
// Check tar file
String repo_url = 'https://sonatype.github.io/helm3-charts/'
verifyDownloadLinks(
urlParts: [repo_url, chart, '-', version],
urlSuffixes: ['.tgz'], retryCount: 2, retryDelay: 60
)
// Get repository version
def response = httpRequest "${repo_url}/index.yaml"
def repositoryIndexFile = readYaml text:response.content
String repositoryVersion = repositoryIndexFile.entries[chart][0].version
if (!version.equals(repositoryVersion)) {
error "Released version: ${version} is different " +
"from helm repository version: ${repositoryVersion}"
}
return repositoryVersion
}
String calculateChartVersion(final String chartVersion, final String appVersion) {
if (chartVersion) {
return chartVersion
}
if (! appVersion) {
error 'Failed to calculate chartVersion with no appVersion.'
}
final versionParts = parseVersionString(appVersion)
final chartMajor = versionParts[1]
final chartMinor = versionParts[2]
if (! chartMajor || ! chartMinor) {
error "Failed to calculate chartVersion from appVersion: ${appVersion}"
}
return [chartMajor, chartMinor, '0'].join('.')
}

View File

@ -1,6 +1,6 @@
apiVersion: v2
name: nxrm-aws-resiliency
description: Helm chart for a Resilient Nexus Repository deployment in AWS
description: Resilient AWS Deployment of Sonatype Nexus Repository Manager - Universal Binary repository
# A chart can be either an 'application' or a 'library' chart.
#
@ -22,3 +22,22 @@ version: 41.1.0
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "3.41.1"
keywords:
- artifacts
- dependency
- management
- sonatype
- nexus
- repository
- quickstart
- ci
- repository-manager
- nexus3
home: https://www.sonatype.com/nexus-repository-oss
icon: https://sonatype.github.io/helm3-charts/NexusRepo_Vertical.svg
sources:
- https://github.com/sonatype/nexus-public
maintainers:
- email: support@sonatype.com
name: Sonatype

33
build.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/sh
#
# Copyright (c) 2020-present Sonatype, Inc. All rights reserved.
#
# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License Version 2.0.
# You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the Apache License Version 2.0 is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
#
helm plugin install https://github.com/quintush/helm-unittest
set -e
# lint yaml of charts
helm lint ./aws-single-instance-resiliency
helm lint ./single-inst-oss-pro-kubernetes
# unit test
(cd ./aws-single-instance-resiliency; helm unittest -3 -t junit -o test-output.xml .)
(cd ./single-inst-oss-pro-kubernetes; helm unittest -3 -t junit -o test-output.xml .)
# package the charts into tgz archives
helm package ./aws-single-instance-resiliency --destination docs
helm package ./single-inst-oss-pro-kubernetes --destination docs
# index the existing tgz archives
cd docs
helm repo index . --url https://sonatype.github.io/helm3-charts

34
docs/index.md Normal file
View File

@ -0,0 +1,34 @@
## Helm3 Charts for Sonatype Products
### AWS Single-Instance Resilient Nexus Repository Manager Chart
These charts will deploy a Nexus Repository Manager instance to an AWS EKS cluster.
The current release has been tested on AWS EKS running Kubernetes version 1.21
### Single-Instance Nexus Repository Manager OSS/Pro Kubernetes Chart
These charts are designed to work out of the box with minikube using both Ingress
and Ingress DNS addons.
The current releases have been tested on minikube v1.25.1 running Kubernetes v1.23.1.
### Add the Sonatype Repo to Your Helm
`helm repo add sonatype https://sonatype.github.io/helm3-charts/`
### Install a Server
- Single-Instance Nexus Repository Manager OSS/Pro: `helm install nexus-repo sonatype/nexus-repository-manager`
- AWS Single-Instance Resilient Nexus Repository Manager: `helm install nxrm sonatype/nxrm-aws-resiliency --values values.yaml`
- Nexus IQ: `helm install nexus-iq sonatype/nexus-iq-server`
### Get the Values for Configuring a Chart
- Single-Instance Nexus Repository Manager OSS/Pro: `helm show values sonatype/nexus-repository-manager`
- AWS Single-Instance Resilient Nexus Repository Manager: `helm show values sonatype/nxrm-aws-resiliency`
- Nexus IQ: `helm show values sonatype/nexus-iq-server`
Capture that output as your own `values.yaml` file, and provide it to the `helm install`
command with the `-f` option.
### Source
Visit https://github.com/sonatype/helm3-charts.

39
upgrade.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
#
# Copyright (c) 2020-present Sonatype, Inc. All rights reserved.
#
# This program is licensed to you under the Apache License Version 2.0,
# and you may not use this file except in compliance with the Apache License Version 2.0.
# You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the Apache License Version 2.0 is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
#
if [ $# != 3 ]; then
echo "Usage: $0 <dir> <chart-version> <app-version>"
exit 1
fi
DIR="$1"
CHART_VERSION="$2"
APP_VERSION="$3"
OUTPUT_FILE=$(mktemp)
cat "$DIR/Chart.yaml" \
| sed -E "s/version: .+/version: $CHART_VERSION/" \
| sed -E "s/appVersion: .+/appVersion: $APP_VERSION/" \
> "$OUTPUT_FILE"
mv "$OUTPUT_FILE" "$DIR/Chart.yaml"
cat "$DIR/values.yaml" \
| sed -E "s/^ tag: .+$/ tag: $APP_VERSION/" \
> "$OUTPUT_FILE"
mv "$OUTPUT_FILE" "$DIR/values.yaml"
git diff "$DIR"