From bc54e57a2c7bb2de59dbaa16a4498bd1fd5e71c9 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 4 Mar 2021 14:19:50 +0100 Subject: [PATCH 01/11] added extra resources Signed-off-by: Marek Markiewka --- .../fluxv1/helm/k8s/production/configMap.yaml | 18 ++++++++++++++++++ .../helm/k8s/production/secrets/secret.yaml | 11 +++++++++++ .../helm/k8s/production/secrets/secret2.yaml | 11 +++++++++++ .../fluxv1/helm/k8s/staging/configMap.yaml | 18 ++++++++++++++++++ .../helm/k8s/staging/secrets/secret.yaml | 11 +++++++++++ .../helm/k8s/staging/secrets/secret2.yaml | 11 +++++++++++ 6 files changed, 80 insertions(+) create mode 100644 applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml diff --git a/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml new file mode 100644 index 00000000..66e5f0c2 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: configmap-sample + namespace: fluxv1-production +data: + # property-like keys; each key maps to a simple value + player_initial_lives: "3" + ui_properties_file_name: "user-interface.properties" + + # file-like keys + game.properties: | + enemy.types=aliens,monsters + player.maximum-lives=5 + user-interface.properties: | + color.good=purple + color.bad=yellow + allow.textmode=true \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml new file mode 100644 index 00000000..f948e88d --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-1-sample + namespace: fluxv1-production + annotations: + kubernetes.io/service-account.name: "sa-name" +type: kubernetes.io/service-account-token +data: + # You can include additional key value pairs as you do with Opaque Secrets + extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml new file mode 100644 index 00000000..5ae7a805 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-2-sample + namespace: fluxv1-production + annotations: + kubernetes.io/service-account.name: "sa-name" +type: kubernetes.io/service-account-token +data: + # You can include additional key value pairs as you do with Opaque Secrets + extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml new file mode 100644 index 00000000..0b9cb188 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: configmap-sample + namespace: fluxv1-staging +data: + # property-like keys; each key maps to a simple value + player_initial_lives: "3" + ui_properties_file_name: "user-interface.properties" + + # file-like keys + game.properties: | + enemy.types=aliens,monsters + player.maximum-lives=5 + user-interface.properties: | + color.good=purple + color.bad=yellow + allow.textmode=true \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml new file mode 100644 index 00000000..ac4138ff --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-1-sample + namespace: fluxv1-staging + annotations: + kubernetes.io/service-account.name: "sa-name" +type: kubernetes.io/service-account-token +data: + # You can include additional key value pairs as you do with Opaque Secrets + extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml new file mode 100644 index 00000000..9f568572 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-2-sample + namespace: fluxv1-staging + annotations: + kubernetes.io/service-account.name: "sa-name" +type: kubernetes.io/service-account-token +data: + # You can include additional key value pairs as you do with Opaque Secrets + extra: YmFyCg== \ No newline at end of file From 7b4a62e6e4396ef1e0905825926aa4ffa24df154 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 4 Mar 2021 16:53:44 +0100 Subject: [PATCH 02/11] fixed gitopsconfig Signed-off-by: Marek Markiewka --- applications/petclinic/fluxv1/helm/Jenkinsfile | 4 ++-- applications/petclinic/fluxv1/plain-k8s/Jenkinsfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index c89d0515..a89cbb9f 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -10,7 +10,7 @@ String getDockerRegistryBaseUrl() { "localhost:30000" } String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' } // TODO change back to scmm repo String getCesBuildLibVersion() { 'bugfix/location_for_prId' } String getGitOpsBuildLibRepo() { 'https://github.com/cloudogu/gitops-build-lib' } // TODO change to scmm repo? -String getGitOpsBuildLibVersion() { 'feature/helm-git' } +String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } String getHelmChartRepository() { 'http://scmm-scm-manager.default.svc.cluster.local/scm/repo/common/spring-boot-helm-chart' } String getHelmChartName() { "springboot" } String getHelmChartVersion() { "1.0.0" } @@ -77,7 +77,7 @@ node { application: application, mainBranch: mainBranch, deployments: [ - sourcePath: 'k8s' + sourcePath: 'k8s', helm : [ repoType : 'HELM', credentialsId : 'creds', diff --git a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile index d869215f..7d75f7f6 100644 --- a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile +++ b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile @@ -11,7 +11,7 @@ String getDockerRegistryBaseUrl() { "localhost:30000" } String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' } // TODO change back to scmm repo String getCesBuildLibVersion() { 'bugfix/location_for_prId' } String getGitOpsBuildLibRepo() { 'https://github.com/cloudogu/gitops-build-lib' } // TODO change to scmm repo? -String getGitOpsBuildLibVersion() { 'feature/helm-git' } +String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } String getMainBranch() { 'main' } // images, helm also offers kubeval @@ -83,7 +83,7 @@ node { sourcePath: 'k8s', plain: [ updateImages: [ - [ deploymentFilename: "deployment.yaml", + [ filename: "deployment.yaml", containerName: application, imageName: imageName ] ] From fb9c581ae2ca0484a979283e85c2bcec91833a30 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 4 Mar 2021 20:44:59 +0100 Subject: [PATCH 03/11] refactor jenkinsfiles Signed-off-by: Marek Markiewka --- applications/nginx/fluxv1/Jenkinsfile | 365 ++++-------------- .../petclinic/fluxv1/helm/Jenkinsfile | 7 +- 2 files changed, 71 insertions(+), 301 deletions(-) diff --git a/applications/nginx/fluxv1/Jenkinsfile b/applications/nginx/fluxv1/Jenkinsfile index acad1a2b..1370a4be 100644 --- a/applications/nginx/fluxv1/Jenkinsfile +++ b/applications/nginx/fluxv1/Jenkinsfile @@ -1,39 +1,49 @@ #!groovy String getApplication() { "nginx" } -String getCesBuildLibVersion() { '1.44.3' } -String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' } String getScmManagerCredentials() { 'scmm-user' } -String getKubectlImage() { 'lachlanevenson/k8s-kubectl:v1.19.3' } String getConfigRepositoryUrl() { "http://scmm-scm-manager/scm/repo/fluxv1/gitops" } -String getConfigRepositoryPRUrl() { 'http://scmm-scm-manager/scm/api/v2/pull-requests/fluxv1/gitops' } +String getConfigRepositoryPRBaseUrl() { 'http://scmm-scm-manager/scm' } +String getConfigRepositoryPRRepo() { 'fluxv1/gitops' } +String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' } // TODO change back to scmm repo +String getCesBuildLibVersion() { 'bugfix/location_for_prId' } +String getGitOpsBuildLibRepo() { 'https://github.com/cloudogu/gitops-build-lib' } // TODO change to scmm repo? +String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } String getHelmChartRepository() { "https://charts.bitnami.com/bitnami" } String getHelmChartName() { "nginx" } String getHelmChartVersion() { "8.0.0" } String getMainBranch() { 'main' } +cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}", + retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo]) +).com.cloudogu.ces.cesbuildlib + +gitOpsBuildLib = library(identifier: "gitops-build-lib@${gitOpsBuildLibVersion}", + retriever: modernSCM([$class: 'GitSCMSource', remote: gitOpsBuildLibRepo]) +).com.cloudogu.gitops.gitopsbuildlib + +properties([ + // Keep only the last 10 build to preserve space + disableConcurrentBuilds() +]) + node('docker') { - cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}", - retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo]) - ).com.cloudogu.ces.cesbuildlib - properties([ - // Keep only the last 10 build to preserve space - disableConcurrentBuilds() - ]) + def git = cesBuildLib.Git.new(this) // In this chart we don't need to set properties in HelmRelease's "values" field. // We leave this mechanism in place as an example. - helmValuesFromFile = [] - fileConfigmaps = [ - [name : "index", - file : "../index.html", - stage: ["staging", "production"] - ] - ] + // helmValuesFromFile = [] + + // fileConfigmaps = [ + // [name : "index", + // file : "../index.html", + // stage: ["staging", "production"] + // ] + // ] timeout(activity: true, time: 30, unit: 'MINUTES') { @@ -47,291 +57,52 @@ node('docker') { stage('Deploy') { if (env.BRANCH_NAME in [mainBranch]) { def gitopsConfig = [ - scmmCredentialsId: scmManagerCredentials, - scmmConfigRepoUrl: configRepositoryUrl, - scmmPullRequestUrl: configRepositoryPRUrl + scmmCredentialsId : scmManagerCredentials, + scmmConfigRepoUrl : configRepositoryUrl, + scmmPullRequestBaseUrl: configRepositoryPRBaseUrl, + scmmPullRequestRepo: configRepositoryPRRepo, + cesBuildLibRepo: cesBuildLibRepo, + cesBuildLibVersion: cesBuildLibVersion, + application: application, + mainBranch: mainBranch, + deployments: [ + sourcePath: 'k8s', + helm : [ + repoType : 'HELM', + credentialsId : 'creds', + repoUrl : helmChartRepository, + chartName: helmChartName, + version : helmChartVersion, + ] + ], + // stages consists of [ $branchName: [ $deployConfig ]] + // where $deployConfig is an array which consists of $deployDirectly + // + // deployDirectly: true -> deploys directly + // deployDirectly: false -> creates a PR (default) + stages: [ + staging: [ deployDirectly: true ], + production: [ deployDirectly: false ], + ], + helmValuesFromFile: [], + fileConfigmaps: [ + [name : "index", + file : "../index.html", + stage: ["staging", "production"] + ] + ] ] - def helmChart = [ - repoType: 'HELM', - repoUrl: helmChartRepository, - chartName: helmChartName, - version: helmChartVersion - ] - - String pushedChanges = pushToConfigRepo(gitopsConfig, helmChart) - setBuildDescription createBuildDescription(pushedChanges) + deployViaGitops(gitopsConfig) } else { - setBuildDescription 'No push to gitOps repo, because neither on develop branch nor "forceDeployStaging" param set' - } - } - } - } -} - -private setBuildDescription(String description) { - echo "Setting build description: ${description}" - currentBuild.description = description -} - -String pushToConfigRepo(Map gitopsConfig, Map helmChart) { - - def git = cesBuildLib.Git.new(this, scmManagerCredentials) - def changesOnGitOpsRepo = '' - - // Query and store info about application repo before cloning into gitops repo - def applicationRepo = GitRepo.create(git) - - git.committerName = 'Jenkins' - git.committerEmail = 'jenkins@cloudogu.com' - - def configRepoTempDir = '.configRepoTempDir' - - try { - - dir(configRepoTempDir) { - - git url: gitopsConfig.scmmConfigRepoUrl, branch: mainBranch, changelog: false, poll: false - git.fetch() - - def repoChanges = new HashSet() - repoChanges += createApplicationForStageAndPushToBranch 'staging', mainBranch, applicationRepo, git, gitopsConfig, helmChart + // setBuildDescription 'No push to gitOps repo, because neither on develop branch nor "forceDeployStaging" param set' + echo 'Skipping deploy, because build not successful or not on main branch' - git.checkoutOrCreate(application) - repoChanges += createApplicationForStageAndPushToBranch 'production', application, applicationRepo, git, gitopsConfig, helmChart - - changesOnGitOpsRepo = aggregateChangesOnGitOpsRepo(repoChanges) - - if (changesOnGitOpsRepo) { - createPullRequest(gitopsConfig) + } } } - } finally { - sh "rm -rf ${configRepoTempDir}" - } - - return changesOnGitOpsRepo -} - -String createApplicationForStageAndPushToBranch(String stage, String branch, GitRepo applicationRepo, def git, Map gitOpsConfig, Map helmChart) { - - String commitPrefix = stage == 'staging' ? '[S] ' : '' - - sh "mkdir -p ${stage}/${application}" - // copy extra resources like sealed secrets - echo "Copying extra resources from application repo to gitOps Repo: 'k8s/${stage}/*' to '${stage}/${application}'" - sh "cp ${env.WORKSPACE}/k8s/${stage}/*.yaml fluxv1-${stage}/${application}/ || true" - - writeFile file: "${stage}/${application}/helmRelease.yaml", text: createHelmRelease(helmChart, "fluxv1-${stage}", createFromFileValues(stage)) - writeFile file: "${stage}/${application}/valuesMap.yaml", text: createConfigMap("values.yaml", "${env.WORKSPACE}/k8s/values-${stage}.yaml", "${application}-helm-operator-values", "fluxv1-${stage}") - - writeFile file: "${stage}/${application}/sharedValuesMap.yaml", text: createConfigMap("values.yaml", "${env.WORKSPACE}/k8s/values-shared.yaml", "${application}-shared-helm-operator-values", "fluxv1-${stage}") - - creatFileConfigmaps(stage) - - git.add('.') - if (git.areChangesStagedForCommit()) { - git.commit(commitPrefix + createApplicationCommitMessage(git, applicationRepo), applicationRepo.authorName, applicationRepo.authorEmail) - - // If some else pushes between the pull above and this push, the build will fail. - // So we pull if push fails and try again - git.pushAndPullOnFailure("origin ${branch}") - return "${stage} (${git.commitHashShort})" - } else { - echo "No changes on gitOps repo for ${stage} (branch: ${branch}). Not committing or pushing." - return '' - } -} - -private String aggregateChangesOnGitOpsRepo(changes) { - // Remove empty - (changes - '') - // and concat into string - .join('; ') -} - -String createApplicationCommitMessage(def git, def applicationRepo) { - String issueIds = (applicationRepo.commitMessage =~ /#\d*/).collect { "${it} " }.join('') - - String[] urlSplit = applicationRepo.repositoryUrl.split('/') - def repoNamespace = urlSplit[-2] - def repoName = urlSplit[-1] - String message = "${issueIds}${repoNamespace}/${repoName}@${applicationRepo.commitHash}" - List additions = [] - - if (!additions.isEmpty()) { - // Highlight commits that ran with non-default parameters - message = "* ${message}\n\n${additions.join('\n')}" - } - - return message -} - -void createPullRequest(Map gitopsConfig) { - withCredentials([usernamePassword(credentialsId: gitopsConfig.scmmCredentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USER')]) { - echo 'creating pull request' - String script = - 'curl -s -o /dev/null -w "%{http_code}" ' + - "-u ${GIT_USER}:${GIT_PASSWORD} " + - '-H "Content-Type: application/vnd.scmm-pullRequest+json;v=2" ' + - '--data \'{"title": "created by service ' + application + '", "source": "' + application + '", "target": "' + mainBranch + '"}\' ' + - gitopsConfig.scmmPullRequestUrl - - // For debugging the quotation of the shell script, just do: echo script - String http_code = sh returnStdout: true, script: script - - // At this point we could write a mail to the last committer that his commit triggered a new or updated GitOps PR - - echo "http_code: ${http_code}" - // PR exists if we get 409 - if (http_code != "201" && http_code != "409") { - unstable 'Could not create pull request' - } - } -} - -private String createBuildDescription(String pushedChanges) { - String description = '' - - description += "${description ? '\n' : ''}GitOps commits: " - - if (pushedChanges) { - description += pushedChanges - } else { - description += 'No changes' - } - - return description -} - -String createHelmRelease(Map helmChart, String namespace, String extraValues) { - return """apiVersion: helm.fluxcd.io/v1 -kind: HelmRelease -metadata: - name: ${application} - namespace: ${namespace} - annotations: - fluxcd.io/automated: "false" -spec: - releaseName: ${application} - chart: - repository: ${helmChart.repoUrl} - name: ${helmChart.chartName} - version: ${helmChart.version} - - valuesFrom: - - configMapKeyRef: - name: ${application}-shared-helm-operator-values - namespace: ${namespace} - key: values.yaml - optional: false - - configMapKeyRef: - name: ${application}-helm-operator-values - namespace: ${namespace} - key: values.yaml - optional: false -""" -} - -String createFromFileValues(String stage) { - String values = "" - - helmValuesFromFile.each { - if (stage in it['stage']) { - values = fileToInlineYaml(it['key'], "${env.WORKSPACE}/k8s/${it['file']}") - } - } - return values -} - -void creatFileConfigmaps(String stage) { - fileConfigmaps.each { - if(stage in it['stage']) { - String key = it['file'].split('/').last() - writeFile file: "${stage}/${application}/${it['name']}.yaml", text: createConfigMap(key, "${env.WORKSPACE}/k8s/${it['file']}", it['name'], "fluxv1-${stage}") - } - } -} - -String createConfigMap(String key, String filePath, String name, String namespace) { - String configMap = "" - withKubectl { - String script = "KUBECONFIG=${writeKubeConfig()} kubectl create configmap ${name} " + - "--from-file=${key}=${filePath} " + - "--dry-run=client -o yaml -n ${namespace}" - - configMap = sh returnStdout: true, script: script - } - return configMap -} - -// Dummy kubeConfig, so we can use `kubectl --dry-run=client` -String writeKubeConfig() { - String kubeConfigPath = "${pwd()}/.kube/config" - echo "Writing $kubeConfigPath" - writeFile file: kubeConfigPath, text: """apiVersion: v1 -clusters: -- cluster: - certificate-authority-data: DATA+OMITTED - server: https://localhost - name: self-hosted-cluster -contexts: -- context: - cluster: self-hosted-cluster - user: svcs-acct-dply - name: svcs-acct-context -current-context: svcs-acct-context -kind: Config -preferences: {} -users: -- name: svcs-acct-dply - user: - token: DATA+OMITTED""" - - return kubeConfigPath -} - -void withKubectl(Closure body) { - cesBuildLib.Docker.new(this).image(kubectlImage) - // Allow accessing WORKSPACE even when we are in a child dir (using "dir() {}") - .inside("${pwd().equals(env.WORKSPACE) ? '' : "-v ${env.WORKSPACE}:${env.WORKSPACE}"}") { - body() - } -} - -String fileToInlineYaml(String key, String filePath) { - String values = "" - String indent = " " - - def fileContent = readFile filePath - values += "\n ${key}: |\n${indent}" - values += fileContent.split("\\n").join("\n" + indent) - - return values -} - -/** Queries and stores info about current repo and HEAD commit */ -class GitRepo { - - static GitRepo create(git) { - // Constructors can't be used in Jenkins pipelines due to CPS - // https://www.jenkins.io/doc/book/pipeline/cps-method-mismatches/#constructors - return new GitRepo(git.commitAuthorName, git.commitAuthorEmail, git.commitHashShort, git.commitMessage, git.repositoryUrl) } - - GitRepo(String authorName, String authorEmail, String commitHash, String commitMessage, String repositoryUrl) { - this.authorName = authorName - this.authorEmail = authorEmail - this.commitHash = commitHash - this.commitMessage = commitMessage - this.repositoryUrl = repositoryUrl - } - - final String authorName - final String authorEmail - final String commitHash - final String commitMessage - final String repositoryUrl } -def cesBuildLib \ No newline at end of file +def cesBuildLib +def gitOpsBuildLib \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index a89cbb9f..89875d91 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -79,12 +79,12 @@ node { deployments: [ sourcePath: 'k8s', helm : [ - repoType : 'HELM', + repoType : 'GIT', credentialsId : 'creds', - repoUrl : helmChartRepository}, + repoUrl : helmChartRepository, chartName: helmChartName, version : helmChartVersion, - extraResources: ['config, secrets'], // files or folders relative to deployments.path. Default empty array. + extraResources: ['configMap.yaml, secrets'], // files or folders relative to deployments.path.${stage} Default empty array. updateValues : [[fieldPath: "image.name", newValue: imageName]] ] ], @@ -96,7 +96,6 @@ node { stages: [ staging: [ deployDirectly: true ], production: [ deployDirectly: false ], - qa: [ ] ] ] From 872a7d960666a0fbe7df8fc89e5dbd306549f08b Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Mon, 8 Mar 2021 18:32:11 +0100 Subject: [PATCH 04/11] plain bugfix Signed-off-by: Marek Markiewka --- README.md | 2 +- applications/nginx/fluxv1/Jenkinsfile | 20 ++++++++++++++----- .../petclinic/fluxv1/helm/Jenkinsfile | 2 +- .../fluxv1/helm/k8s/production/configMap.yaml | 4 ++-- .../helm/k8s/production/secrets/secret.yaml | 11 ++++------ .../helm/k8s/production/secrets/secret2.yaml | 11 ++++------ .../fluxv1/helm/k8s/staging/configMap.yaml | 4 ++-- .../helm/k8s/staging/secrets/secret.yaml | 11 ++++------ .../helm/k8s/staging/secrets/secret2.yaml | 11 ++++------ jenkins/values.yaml | 12 +++++------ 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 18dc9459..c93b5f94 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ TODO not reachable via 30006! * remote: `scripts/get-remote-url nginx fluxv1-staging` * Production * local: [localhost:30007](http://localhost:30007) - * remote: `scripts/get-remote-url nginx fluxv1-staging` + * remote: `scripts/get-remote-url nginx fluxv1-production` ##### PetClinic via Flux V2 diff --git a/applications/nginx/fluxv1/Jenkinsfile b/applications/nginx/fluxv1/Jenkinsfile index 1370a4be..aec8f63a 100644 --- a/applications/nginx/fluxv1/Jenkinsfile +++ b/applications/nginx/fluxv1/Jenkinsfile @@ -73,6 +73,8 @@ node('docker') { repoUrl : helmChartRepository, chartName: helmChartName, version : helmChartVersion, + // extraResources: [], // convention: ${sourcePath}/stages.it} all files and folders will be copied + ] ], // stages consists of [ $branchName: [ $deployConfig ]] @@ -81,13 +83,21 @@ node('docker') { // deployDirectly: true -> deploys directly // deployDirectly: false -> creates a PR (default) stages: [ - staging: [ deployDirectly: true ], - production: [ deployDirectly: false ], + staging: [ + namespace: 'fluxv1-staging', // Default: key-name. e.g. staging + deployDirectly: true + ], + production: [ + namespace: 'fluxv1-production', // Default: key-name. e.g. production + deployDirectly: false + ], ], - helmValuesFromFile: [], - fileConfigmaps: [ + // helmValuesFromFile: [], Optional + fileConfigmaps: [ //TODO configmapsFromFiles; [name : "index", - file : "../index.html", + sourceFilePath : "../index.html", // relative to deployments.sourcePath + // additional feature in the future. current default folder is '../generated-resources' + // destinationFilePath: "../generated-resources/html/" // realtive to deployments.sourcePath stage: ["staging", "production"] ] ] diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index 89875d91..92b8e93f 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -84,7 +84,7 @@ node { repoUrl : helmChartRepository, chartName: helmChartName, version : helmChartVersion, - extraResources: ['configMap.yaml, secrets'], // files or folders relative to deployments.path.${stage} Default empty array. + // extraResources: [], // convention: ${sourcePath}/stages.it} all files and folders will be copied updateValues : [[fieldPath: "image.name", newValue: imageName]] ] ], diff --git a/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml index 66e5f0c2..f2051b4f 100644 --- a/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml @@ -11,8 +11,8 @@ data: # file-like keys game.properties: | enemy.types=aliens,monsters - player.maximum-lives=5 + player.maximum-lives=5 user-interface.properties: | color.good=purple color.bad=yellow - allow.textmode=true \ No newline at end of file + allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml index f948e88d..a746a9c3 100644 --- a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml @@ -1,11 +1,8 @@ apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= kind: Secret metadata: - name: secret-1-sample + name: sample-secret-1 namespace: fluxv1-production - annotations: - kubernetes.io/service-account.name: "sa-name" -type: kubernetes.io/service-account-token -data: - # You can include additional key value pairs as you do with Opaque Secrets - extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml index 5ae7a805..9fdc7766 100644 --- a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml @@ -1,11 +1,8 @@ apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= kind: Secret metadata: - name: secret-2-sample + name: sample-secret-2 namespace: fluxv1-production - annotations: - kubernetes.io/service-account.name: "sa-name" -type: kubernetes.io/service-account-token -data: - # You can include additional key value pairs as you do with Opaque Secrets - extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml index 0b9cb188..d2a27274 100644 --- a/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml @@ -11,8 +11,8 @@ data: # file-like keys game.properties: | enemy.types=aliens,monsters - player.maximum-lives=5 + player.maximum-lives=5 user-interface.properties: | color.good=purple color.bad=yellow - allow.textmode=true \ No newline at end of file + allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml index ac4138ff..ce7b9053 100644 --- a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml @@ -1,11 +1,8 @@ apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= kind: Secret metadata: - name: secret-1-sample + name: sample-secret-1 namespace: fluxv1-staging - annotations: - kubernetes.io/service-account.name: "sa-name" -type: kubernetes.io/service-account-token -data: - # You can include additional key value pairs as you do with Opaque Secrets - extra: YmFyCg== \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml index 9f568572..e720fd47 100644 --- a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml +++ b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml @@ -1,11 +1,8 @@ apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= kind: Secret metadata: - name: secret-2-sample + name: sample-secret-2 namespace: fluxv1-staging - annotations: - kubernetes.io/service-account.name: "sa-name" -type: kubernetes.io/service-account-token -data: - # You can include additional key value pairs as you do with Opaque Secrets - extra: YmFyCg== \ No newline at end of file diff --git a/jenkins/values.yaml b/jenkins/values.yaml index 17453496..177211b9 100644 --- a/jenkins/values.yaml +++ b/jenkins/values.yaml @@ -77,13 +77,13 @@ controller: } - script: | multibranchPipelineJob('fluxv1-petclinic-helm') { - branchSources { - git { - id('fluxv1-petclinic-helm') - remote('http://scmm-scm-manager/scm/repo/fluxv1/petclinic-helm') - credentialsId('scmm-user') + branchSources { + git { + id('fluxv1-petclinic-helm') + remote('http://scmm-scm-manager/scm/repo/fluxv1/petclinic-helm') + credentialsId('scmm-user') + } } - } } - script: | multibranchPipelineJob('fluxv1-nginx') { From 6a97c0666308ac0aa4046447df7c5b2c84f7e957 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Wed, 10 Mar 2021 17:02:27 +0100 Subject: [PATCH 05/11] adjusted to helm repo type Signed-off-by: Marek Markiewka --- applications/nginx/fluxv1/Jenkinsfile | 30 +++++-------------- .../petclinic/fluxv1/helm/Jenkinsfile | 8 +++-- .../fluxv1/helm/k8s/production/configMap.yaml | 18 ----------- .../helm/k8s/production/secrets/secret.yaml | 8 ----- .../helm/k8s/production/secrets/secret2.yaml | 8 ----- .../fluxv1/helm/k8s/staging/configMap.yaml | 18 ----------- .../helm/k8s/staging/secrets/secret.yaml | 8 ----- .../helm/k8s/staging/secrets/secret2.yaml | 8 ----- .../fluxv1/helm/k8s/values-production.yaml | 3 -- .../fluxv1/helm/k8s/values-staging.yaml | 3 -- scripts/destroy.sh | 1 - 11 files changed, 13 insertions(+), 100 deletions(-) delete mode 100644 applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/values-production.yaml delete mode 100644 applications/petclinic/fluxv1/helm/k8s/values-staging.yaml diff --git a/applications/nginx/fluxv1/Jenkinsfile b/applications/nginx/fluxv1/Jenkinsfile index aec8f63a..cc7d05b1 100644 --- a/applications/nginx/fluxv1/Jenkinsfile +++ b/applications/nginx/fluxv1/Jenkinsfile @@ -29,22 +29,8 @@ properties([ node('docker') { - - def git = cesBuildLib.Git.new(this) - // In this chart we don't need to set properties in HelmRelease's "values" field. - // We leave this mechanism in place as an example. - - // helmValuesFromFile = [] - - // fileConfigmaps = [ - // [name : "index", - // file : "../index.html", - // stage: ["staging", "production"] - // ] - // ] - timeout(activity: true, time: 30, unit: 'MINUTES') { catchError { @@ -73,8 +59,6 @@ node('docker') { repoUrl : helmChartRepository, chartName: helmChartName, version : helmChartVersion, - // extraResources: [], // convention: ${sourcePath}/stages.it} all files and folders will be copied - ] ], // stages consists of [ $branchName: [ $deployConfig ]] @@ -93,19 +77,19 @@ node('docker') { ], ], // helmValuesFromFile: [], Optional - fileConfigmaps: [ //TODO configmapsFromFiles; - [name : "index", - sourceFilePath : "../index.html", // relative to deployments.sourcePath - // additional feature in the future. current default folder is '../generated-resources' - // destinationFilePath: "../generated-resources/html/" // realtive to deployments.sourcePath - stage: ["staging", "production"] + fileConfigmaps: [ + [ + name : "index", + sourceFilePath : "../index.html", // relative to deployments.sourcePath + // additional feature in the future. current default folder is '../generated-resources' + // destinationFilePath: "../generated-resources/html/" // realtive to deployments.sourcePath + stage: ["staging", "production"] ] ] ] deployViaGitops(gitopsConfig) } else { - // setBuildDescription 'No push to gitOps repo, because neither on develop branch nor "forceDeployStaging" param set' echo 'Skipping deploy, because build not successful or not on main branch' } diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index 92b8e93f..ab25af26 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -94,8 +94,12 @@ node { // deployDirectly: true -> deploys directly // deployDirectly: false -> creates a PR (default) stages: [ - staging: [ deployDirectly: true ], - production: [ deployDirectly: false ], + 'fluxv1-staging': [ + deployDirectly: true + ], + 'fluxv1-production': [ + deployDirectly: false + ], ] ] diff --git a/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml deleted file mode 100644 index f2051b4f..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/production/configMap.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: configmap-sample - namespace: fluxv1-production -data: - # property-like keys; each key maps to a simple value - player_initial_lives: "3" - ui_properties_file_name: "user-interface.properties" - - # file-like keys - game.properties: | - enemy.types=aliens,monsters - player.maximum-lives=5 - user-interface.properties: | - color.good=purple - color.bad=yellow - allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml deleted file mode 100644 index a746a9c3..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -data: - password.txt: MWYyZDFlMmU2N2Rm - username.txt: YWRtaW4= -kind: Secret -metadata: - name: sample-secret-1 - namespace: fluxv1-production diff --git a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml deleted file mode 100644 index 9fdc7766..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/production/secrets/secret2.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -data: - password.txt: MWYyZDFlMmU2N2Rm - username.txt: YWRtaW4= -kind: Secret -metadata: - name: sample-secret-2 - namespace: fluxv1-production diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml deleted file mode 100644 index d2a27274..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/staging/configMap.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: configmap-sample - namespace: fluxv1-staging -data: - # property-like keys; each key maps to a simple value - player_initial_lives: "3" - ui_properties_file_name: "user-interface.properties" - - # file-like keys - game.properties: | - enemy.types=aliens,monsters - player.maximum-lives=5 - user-interface.properties: | - color.good=purple - color.bad=yellow - allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml deleted file mode 100644 index ce7b9053..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -data: - password.txt: MWYyZDFlMmU2N2Rm - username.txt: YWRtaW4= -kind: Secret -metadata: - name: sample-secret-1 - namespace: fluxv1-staging diff --git a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml deleted file mode 100644 index e720fd47..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/staging/secrets/secret2.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -data: - password.txt: MWYyZDFlMmU2N2Rm - username.txt: YWRtaW4= -kind: Secret -metadata: - name: sample-secret-2 - namespace: fluxv1-staging diff --git a/applications/petclinic/fluxv1/helm/k8s/values-production.yaml b/applications/petclinic/fluxv1/helm/k8s/values-production.yaml deleted file mode 100644 index 9ad8c64e..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/values-production.yaml +++ /dev/null @@ -1,3 +0,0 @@ -service: - port: 80 - nodePort: 30005 \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/values-staging.yaml b/applications/petclinic/fluxv1/helm/k8s/values-staging.yaml deleted file mode 100644 index a30998ed..00000000 --- a/applications/petclinic/fluxv1/helm/k8s/values-staging.yaml +++ /dev/null @@ -1,3 +0,0 @@ -service: - port: 80 - nodePort: 30004 \ No newline at end of file diff --git a/scripts/destroy.sh b/scripts/destroy.sh index bd9b1f03..2725271a 100755 --- a/scripts/destroy.sh +++ b/scripts/destroy.sh @@ -48,7 +48,6 @@ function removeK8sResources() { } function cleanup () { - kubectl delete crd/helmreleases.helm.fluxcd.io || true kubectl delete customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io || true kubectl delete customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io || true kubectl delete apiservice.apiregistration.k8s.io/v1alpha1.argoproj.io || true From 524601271e7a763cdf0372643c20f93b84ca27a0 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Wed, 10 Mar 2021 17:06:57 +0100 Subject: [PATCH 06/11] adjusted to helm repo type Signed-off-by: Marek Markiewka --- .../helm/k8s/fluxv1-production/configMap.yaml | 18 ++++++++++++++++++ .../k8s/fluxv1-production/secrets/secret.yaml | 8 ++++++++ .../k8s/fluxv1-production/secrets/secret2.yaml | 8 ++++++++ .../helm/k8s/fluxv1-staging/configMap.yaml | 18 ++++++++++++++++++ .../k8s/fluxv1-staging/secrets/secret.yaml | 8 ++++++++ .../k8s/fluxv1-staging/secrets/secret2.yaml | 8 ++++++++ .../helm/k8s/values-fluxv1-production.yaml | 3 +++ .../fluxv1/helm/k8s/values-fluxv1-staging.yaml | 3 +++ 8 files changed, 74 insertions(+) create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-production/configMap.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret2.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/configMap.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret2.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/values-fluxv1-production.yaml create mode 100644 applications/petclinic/fluxv1/helm/k8s/values-fluxv1-staging.yaml diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/configMap.yaml new file mode 100644 index 00000000..f2051b4f --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/configMap.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: configmap-sample + namespace: fluxv1-production +data: + # property-like keys; each key maps to a simple value + player_initial_lives: "3" + ui_properties_file_name: "user-interface.properties" + + # file-like keys + game.properties: | + enemy.types=aliens,monsters + player.maximum-lives=5 + user-interface.properties: | + color.good=purple + color.bad=yellow + allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret.yaml new file mode 100644 index 00000000..a746a9c3 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= +kind: Secret +metadata: + name: sample-secret-1 + namespace: fluxv1-production diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret2.yaml new file mode 100644 index 00000000..9fdc7766 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-production/secrets/secret2.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= +kind: Secret +metadata: + name: sample-secret-2 + namespace: fluxv1-production diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/configMap.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/configMap.yaml new file mode 100644 index 00000000..d2a27274 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/configMap.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: configmap-sample + namespace: fluxv1-staging +data: + # property-like keys; each key maps to a simple value + player_initial_lives: "3" + ui_properties_file_name: "user-interface.properties" + + # file-like keys + game.properties: | + enemy.types=aliens,monsters + player.maximum-lives=5 + user-interface.properties: | + color.good=purple + color.bad=yellow + allow.textmode=true diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret.yaml new file mode 100644 index 00000000..ce7b9053 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= +kind: Secret +metadata: + name: sample-secret-1 + namespace: fluxv1-staging diff --git a/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret2.yaml b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret2.yaml new file mode 100644 index 00000000..e720fd47 --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/fluxv1-staging/secrets/secret2.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + password.txt: MWYyZDFlMmU2N2Rm + username.txt: YWRtaW4= +kind: Secret +metadata: + name: sample-secret-2 + namespace: fluxv1-staging diff --git a/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-production.yaml b/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-production.yaml new file mode 100644 index 00000000..9ad8c64e --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-production.yaml @@ -0,0 +1,3 @@ +service: + port: 80 + nodePort: 30005 \ No newline at end of file diff --git a/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-staging.yaml b/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-staging.yaml new file mode 100644 index 00000000..a30998ed --- /dev/null +++ b/applications/petclinic/fluxv1/helm/k8s/values-fluxv1-staging.yaml @@ -0,0 +1,3 @@ +service: + port: 80 + nodePort: 30004 \ No newline at end of file From 8f91da7c555a5343869a7ac142c78f8ce560d42e Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 11 Mar 2021 10:55:55 +0100 Subject: [PATCH 07/11] added extra files for plain Signed-off-by: Marek Markiewka --- .../petclinic/fluxv1/plain-k8s/Jenkinsfile | 24 ++++++++++++------- .../petclinic/fluxv1/plain-k8s/index.html | 11 +++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 applications/petclinic/fluxv1/plain-k8s/index.html diff --git a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile index 7d75f7f6..019d20e0 100644 --- a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile +++ b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile @@ -89,15 +89,23 @@ node { ] ] ], - // stages consists of [ $branchName: [ $deployConfig ]] - // where $deployConfig is an array which consists of $deployDirectly - // - // deployDirectly: true -> deploys directly - // deployDirectly: false -> creates a PR (default) stages: [ - staging: [ deployDirectly: true ], - production: [ deployDirectly: false ], - qa: [ ] + staging: [ + namespace: 'fluxv1-staging', + deployDirectly: true ], + production: [ + namespace: 'fluxv1-production', + deployDirectly: false ], + qa: [ + namespace: 'fluxv1-qa' + ] + ], + fileConfigmaps: [ + [ + name : "index-plain", + sourceFilePath : "../index.html", + stage: ["staging", "production", "qa"] + ] ] ] diff --git a/applications/petclinic/fluxv1/plain-k8s/index.html b/applications/petclinic/fluxv1/plain-k8s/index.html new file mode 100644 index 00000000..11c20888 --- /dev/null +++ b/applications/petclinic/fluxv1/plain-k8s/index.html @@ -0,0 +1,11 @@ + + + + + + k8s-gitops-playground + + +

Hello cloudogu gitops playground!

+ + \ No newline at end of file From 6d5ee8d0c08836d71d0a6b0538cb5e547a0490ff Mon Sep 17 00:00:00 2001 From: thoppenheidt Date: Thu, 11 Mar 2021 11:44:55 +0100 Subject: [PATCH 08/11] removed debugging echo --- scripts/jenkins/init-jenkins.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/jenkins/init-jenkins.sh b/scripts/jenkins/init-jenkins.sh index a1bb55c2..f6c6aeea 100755 --- a/scripts/jenkins/init-jenkins.sh +++ b/scripts/jenkins/init-jenkins.sh @@ -64,7 +64,6 @@ function waitForJenkins() { HTTP_CODE="0" while [[ "${HTTP_CODE}" -ne "200" ]]; do HTTP_CODE="$(curl -s -L -o /dev/null -w ''%{http_code}'' "${JENKINS_URL}/login")" || true - echo ${HTTP_CODE} echo -n "." sleep 2 done From dfd391a1b4d02a96b2c2ce8b015008b9b3a9f444 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 11 Mar 2021 12:07:11 +0100 Subject: [PATCH 09/11] removed chartPath from config Signed-off-by: Marek Markiewka --- applications/petclinic/fluxv1/helm/Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index db71b9da..e8e8852e 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -82,7 +82,6 @@ node { repoType : 'GIT', credentialsId : 'creds', repoUrl : helmChartRepository, - chartPath: helmChartName, version : helmChartVersion, updateValues : [[fieldPath: "image.name", newValue: imageName]] ] From 47d481167e5ede57c8c3d6f8f4938ec532feb177 Mon Sep 17 00:00:00 2001 From: Marek Markiewka Date: Thu, 11 Mar 2021 12:08:37 +0100 Subject: [PATCH 10/11] removed old comments Signed-off-by: Marek Markiewka --- applications/nginx/fluxv1/Jenkinsfile | 14 +++----------- applications/petclinic/fluxv1/helm/Jenkinsfile | 5 ----- .../petclinic/fluxv1/plain-k8s/Jenkinsfile | 3 --- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/applications/nginx/fluxv1/Jenkinsfile b/applications/nginx/fluxv1/Jenkinsfile index cc7d05b1..7f9ccf97 100644 --- a/applications/nginx/fluxv1/Jenkinsfile +++ b/applications/nginx/fluxv1/Jenkinsfile @@ -61,28 +61,20 @@ node('docker') { version : helmChartVersion, ] ], - // stages consists of [ $branchName: [ $deployConfig ]] - // where $deployConfig is an array which consists of $deployDirectly - // - // deployDirectly: true -> deploys directly - // deployDirectly: false -> creates a PR (default) stages: [ staging: [ - namespace: 'fluxv1-staging', // Default: key-name. e.g. staging + namespace: 'fluxv1-staging', deployDirectly: true ], production: [ - namespace: 'fluxv1-production', // Default: key-name. e.g. production + namespace: 'fluxv1-production', deployDirectly: false ], ], - // helmValuesFromFile: [], Optional fileConfigmaps: [ [ name : "index", - sourceFilePath : "../index.html", // relative to deployments.sourcePath - // additional feature in the future. current default folder is '../generated-resources' - // destinationFilePath: "../generated-resources/html/" // realtive to deployments.sourcePath + sourceFilePath : "../index.html", stage: ["staging", "production"] ] ] diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index e8e8852e..8fa36949 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -86,11 +86,6 @@ node { updateValues : [[fieldPath: "image.name", newValue: imageName]] ] ], - // stages consists of [ $branchName: [ $deployConfig ]] - // where $deployConfig is an array which consists of $deployDirectly - // - // deployDirectly: true -> deploys directly - // deployDirectly: false -> creates a PR (default) stages: [ 'fluxv1-staging': [ deployDirectly: true diff --git a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile index 5346821f..8a1a7365 100644 --- a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile +++ b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile @@ -14,8 +14,6 @@ String getGitOpsBuildLibRepo() { 'http://scmm-scm-manager/scm/repo/common/gitops String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } String getMainBranch() { 'main' } -// images, helm also offers kubeval - cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}", retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo]) ).com.cloudogu.ces.cesbuildlib @@ -68,7 +66,6 @@ node { stage('Deploy') { if (isBuildSuccessful() && env.BRANCH_NAME in [mainBranch]) { - // TODO set validation def gitopsConfig = [ scmmCredentialsId: scmManagerCredentials, scmmConfigRepoUrl: configRepositoryUrl, From e731b56630c1e89d4e5014604cfb137611241ac3 Mon Sep 17 00:00:00 2001 From: thoppenheidt Date: Thu, 11 Mar 2021 12:24:02 +0100 Subject: [PATCH 11/11] updated git ops build lib version --- applications/nginx/fluxv1/Jenkinsfile | 2 +- applications/petclinic/fluxv1/helm/Jenkinsfile | 2 +- applications/petclinic/fluxv1/plain-k8s/Jenkinsfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/nginx/fluxv1/Jenkinsfile b/applications/nginx/fluxv1/Jenkinsfile index 7f9ccf97..30db9156 100644 --- a/applications/nginx/fluxv1/Jenkinsfile +++ b/applications/nginx/fluxv1/Jenkinsfile @@ -8,7 +8,7 @@ String getConfigRepositoryPRRepo() { 'fluxv1/gitops' } String getCesBuildLibRepo() { 'https://github.com/cloudogu/ces-build-lib/' } // TODO change back to scmm repo String getCesBuildLibVersion() { 'bugfix/location_for_prId' } String getGitOpsBuildLibRepo() { 'https://github.com/cloudogu/gitops-build-lib' } // TODO change to scmm repo? -String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } +String getGitOpsBuildLibVersion() { '0.0.7' } String getHelmChartRepository() { "https://charts.bitnami.com/bitnami" } String getHelmChartName() { "nginx" } String getHelmChartVersion() { "8.0.0" } diff --git a/applications/petclinic/fluxv1/helm/Jenkinsfile b/applications/petclinic/fluxv1/helm/Jenkinsfile index 8fa36949..f6d221b1 100644 --- a/applications/petclinic/fluxv1/helm/Jenkinsfile +++ b/applications/petclinic/fluxv1/helm/Jenkinsfile @@ -10,7 +10,7 @@ String getDockerRegistryBaseUrl() { "localhost:30000" } String getCesBuildLibRepo() { 'http://scmm-scm-manager/scm/repo/common/ces-build-lib/' } String getCesBuildLibVersion() { '1.45.1' } String getGitOpsBuildLibRepo() { 'http://scmm-scm-manager/scm/repo/common/gitops-build-lib' } -String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } +String getGitOpsBuildLibVersion() { '0.0.7' } String getHelmChartRepository() { 'http://scmm-scm-manager.default.svc.cluster.local/scm/repo/common/spring-boot-helm-chart' } String getHelmChartName() { "springboot" } String getHelmChartVersion() { "1.0.0" } diff --git a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile index 8a1a7365..adea5de3 100644 --- a/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile +++ b/applications/petclinic/fluxv1/plain-k8s/Jenkinsfile @@ -11,7 +11,7 @@ String getDockerRegistryBaseUrl() { "localhost:30000" } String getCesBuildLibRepo() { 'http://scmm-scm-manager/scm/repo/common/ces-build-lib/' } String getCesBuildLibVersion() { '1.45.1' } String getGitOpsBuildLibRepo() { 'http://scmm-scm-manager/scm/repo/common/gitops-build-lib' } -String getGitOpsBuildLibVersion() { 'feature/helm-repo-type' } +String getGitOpsBuildLibVersion() { '0.0.7' } String getMainBranch() { 'main' } cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}",