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

Introduce maven central mirror parameter #192

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion applications/argocd/petclinic/helm/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ String getDockerRegistryCredentials() { 'registry-user' }

<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }
String getCesBuildLibVersion() { '1.64.1' }
String getCesBuildLibVersion() { '2.2.0' }
String getGitOpsBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibVersion() { '0.4.0'}
String getHelmChartRepository() { "${env.SCMM_URL}/repo/3rd-party-dependencies/spring-boot-helm-chart-with-dependency" }
Expand All @@ -40,7 +40,13 @@ properties([
])

node {

mvn = cesBuildLib.MavenWrapper.new(this)
</#noparse>
<#if jenkins.mavenCentralMirror?has_content>
mvn.useMirrors([name: 'maven-central-mirror', mirrorOf: 'central', url: env.${namePrefixForEnvVars}MAVEN_CENTRAL_MIRROR])
</#if>
<#noparse>

catchError {

Expand Down
7 changes: 6 additions & 1 deletion applications/argocd/petclinic/plain-k8s/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ String getDockerRegistryCredentials() { 'registry-user' }
</#if>
<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib" }
String getCesBuildLibVersion() { '1.64.1' }
String getCesBuildLibVersion() { '2.2.0' }
String getGitOpsBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/gitops-build-lib" }
String getGitOpsBuildLibVersion() { '0.4.0'}

Expand All @@ -32,6 +32,11 @@ properties([
node {

mvn = cesBuildLib.MavenWrapper.new(this)
</#noparse>
<#if jenkins.mavenCentralMirror?has_content>
mvn.useMirrors([name: 'maven-central-mirror', mirrorOf: 'central', url: env.${namePrefixForEnvVars}MAVEN_CENTRAL_MIRROR])
</#if>
<#noparse>

catchError {

Expand Down
9 changes: 8 additions & 1 deletion exercises/petclinic-helm/Jenkinsfile.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ String getDockerRegistryCredentials() { 'registry-user' }
</#if>
<#noparse>
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }
String getCesBuildLibVersion() { '1.64.1' }
String getCesBuildLibVersion() { '2.2.0' }
String getHelmChartRepository() { "${env.SCMM_URL}/repo/3rd-party-dependencies/spring-boot-helm-chart-with-dependency" }
String getHelmChartVersion() { "1.0.0" }
String getMainBranch() { 'main' }
Expand All @@ -33,7 +33,14 @@ properties([
])

node {

mvn = cesBuildLib.MavenWrapper.new(this)
</#noparse>
<#if jenkins.mavenCentralMirror?has_content>
mvn.useMirrors([name: 'maven-central-mirror', mirrorOf: 'central', url: env.${namePrefixForEnvVars}MAVEN_CENTRAL_MIRROR])
</#if>
<#noparse>


catchError {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class GitopsPlaygroundCli implements Runnable {
private String jenkinsMetricsUsername
@Option(names = ['--jenkins-metrics-password'], description = 'Mandatory when --jenkins-url is set and monitoring enabled')
private String jenkinsMetricsPassword
@Option(names = ['--maven-central-mirror'], description = 'URL for maven mirror, used by applications built in Jenkins')
private String mavenCentralMirror

// args group scm
@Option(names = ['--scmm-url'], description = 'The host of your external scm-manager')
Expand Down Expand Up @@ -364,6 +366,7 @@ class GitopsPlaygroundCli implements Runnable {
password: jenkinsPassword,
metricsUsername: jenkinsMetricsUsername,
metricsPassword: jenkinsMetricsPassword,
mavenCentralMirror: mavenCentralMirror,
],
scmm : [
url : scmmUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class ApplicationConfigurator {
- Also upgrade plugins. See docs/developers.md
*/
version: '5.0.17'
]
],
mavenCentralMirror: '',
],
scmm : [
internal: true, // Set dynamically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Schema {
String password = ""
String metricsUsername = ""
String metricsPassword = ""
String mavenCentralMirror = ""
}

static class ScmmSchema {
Expand Down
4 changes: 4 additions & 0 deletions src/main/groovy/com/cloudogu/gitops/features/Jenkins.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class Jenkins extends Feature {
globalPropertyManager.setGlobalProperty("${config.application['namePrefixForEnvVars']}REGISTRY_PATH", config.registry['path'] as String)
}

if (config.jenkins['mavenCentralMirror']) {
globalPropertyManager.setGlobalProperty("${config.application['namePrefixForEnvVars']}MAVEN_CENTRAL_MIRROR", config.jenkins['mavenCentralMirror'] as String)
}

globalPropertyManager.setGlobalProperty("${config.application['namePrefixForEnvVars']}K8S_VERSION", ApplicationConfigurator.K8S_VERSION)

if (userManager.isUsingCasSecurityRealm()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ class ArgoCD extends Feature {
host : config.scmm['internal'] ? 'scmm-scm-manager.default.svc.cluster.local' : config.scmm['host'],
protocol: config.scmm['internal'] ? 'http' : config.scmm['protocol'],
],
jenkins : [
mavenCentralMirror : config.jenkins['mavenCentralMirror'],
],
exampleApps : [
petclinic: [
baseDomain: config.features['exampleApps']['petclinic']['baseDomain']
Expand Down
14 changes: 12 additions & 2 deletions src/test/groovy/com/cloudogu/gitops/features/JenkinsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class JenkinsTest {
metricsPassword: 'metrics-pw',
helm : [
version: '4.8.1'
]
],
mavenCentralMirror: ''
],
registry : [
url : 'reg-url',
Expand Down Expand Up @@ -111,7 +112,8 @@ class JenkinsTest {
verify(globalPropertyManager, never()).setGlobalProperty(eq('MY_PREFIX_REGISTRY_PULL_PATH'), anyString())
verify(globalPropertyManager, never()).setGlobalProperty(eq('MY_PREFIX_REGISTRY_PUSH_URL'), anyString())
verify(globalPropertyManager, never()).setGlobalProperty(eq('MY_PREFIX_REGISTRY_PUSH_PATH'), anyString())

verify(globalPropertyManager, never()).setGlobalProperty(eq('MAVEN_CENTRAL_MIRROR'), anyString())

schnatterer marked this conversation as resolved.
Show resolved Hide resolved
verify(userManager).createUser('metrics-usr', 'metrics-pw')
verify(userManager).grantPermission('metrics-usr', UserManager.Permissions.METRICS_VIEW)

Expand Down Expand Up @@ -179,6 +181,14 @@ class JenkinsTest {
assertThat(env['BASE_URL']).isNotEqualTo('null')
}

@Test
void 'Sets maven mirror '() {
config.jenkins['mavenCentralMirror'] = 'http://test'
createJenkins().install()

verify(globalPropertyManager).setGlobalProperty(eq('MY_PREFIX_MAVEN_CENTRAL_MIRROR'), eq("http://test"))
}

protected Map<String, String> getEnvAsMap() {
commandExecutor.environment.collectEntries { it.split('=') }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ArgoCDTest {
urlSeparatorHyphen : false,
mirrorRepos : false
],
jenkins : [
mavenCentralMirror: '',
],
scmm : [
internal: true,
protocol: 'https',
Expand Down Expand Up @@ -454,7 +457,7 @@ class ArgoCDTest {
void 'Prepares repos for air-gapped mode'() {
config['features']['monitoring']['active'] = false
config.application['mirrorRepos'] = true

createArgoCD().install()

Map repos = parseActualYaml(actualHelmValuesFile)['argo-cd']['configs']['repositories'] as Map
Expand Down Expand Up @@ -483,7 +486,7 @@ class ArgoCDTest {
k8sCommands.assertExecuted('kubectl create namespace monitoring')
k8sCommands.assertExecuted("kubectl apply -f ${crdPath}")
}

@Test
void 'Applies Prometheus ServiceMonitor CRD from GitHub before installing'() {
config['features']['monitoring']['active'] = true
Expand All @@ -493,7 +496,7 @@ class ArgoCDTest {
k8sCommands.assertExecuted('kubectl create namespace monitoring')
k8sCommands.assertExecuted("kubectl apply -f https://raw.githubusercontent.com/prometheus-community/helm-charts/kube-prometheus-stack-42.0.3/charts/kube-prometheus-stack/charts/crds/crds/crd-servicemonitors.yaml")
}

@Test
void 'If urlSeparatorHyphen is set, ensure that hostnames are build correctly '() {
config.application['remote'] = true
Expand Down Expand Up @@ -602,7 +605,20 @@ class ArgoCDTest {
tag: latest
""")
}


@Test
void 'Write maven mirror into jenkinsfiles'() {
config.jenkins['mavenCentralMirror'] = 'http://test'
createArgoCD().install()


for (def petclinicRepo : petClinicRepos) {
assertThat(new File(petclinicRepo.absoluteLocalRepoTmpDir, 'Jenkinsfile').text).contains(
'mvn.useMirrors([name: \'maven-central-mirror\', mirrorOf: \'central\', url: env.MAVEN_CENTRAL_MIRROR])'
)
}
}

private void assertArgoCdYamlPrefixes(String scmmUrl, String expectedPrefix) {
assertAllYamlFiles(new File(argocdRepo.getAbsoluteLocalRepoTmpDir()), 'projects', 4) { Path file ->
def yaml = parseActualYaml(file.toString())
Expand Down