Skip to content

Commit 1640120

Browse files
authored
Merge pull request #26 from cloudogu/feature/folder_structure_strategy
Feature/folder structure strategy
2 parents d1375b0 + 45dbcdc commit 1640120

21 files changed

+534
-257
lines changed

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Support different base path in destination gitops repository with `destinationRootPath` #26
12+
- Support different folder strategies with `folderStructureStrategy` #26
13+
- Optional `credentialsId` for build images #19
14+
- Add option for other mainbranches in helm git repositories #19
15+
16+
### Changed
17+
18+
- Bump default cesBuildLib version to 1.62.0 #26
19+
- Bump default kubectl image to 'lachlanevenson/k8s-kubectl:v1.24.8' #26
20+
- Bump default helm image to 'ghcr.io/cloudogu/helm:3.11.1-2' #26
21+
22+
### Removed
23+
24+
- Disable kubeval and helm kubeval in default config, because they are deprecated (we will introduce another linting tool later) #26
25+
26+
### Fixed
27+
- Add namespace to argo helm release #19
28+
29+
## 0.0.1 - 0.1.3
30+
31+
No change log provided. See GitHub release pages for details, e.g.
32+
https://github.com/cloudogu/gitops-build-lib/releases/tag/0.1.3

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!groovy
2-
@Library('github.com/cloudogu/ces-build-lib@1.45.0')
2+
@Library('github.com/cloudogu/ces-build-lib@1.62.0')
33
import com.cloudogu.ces.cesbuildlib.*
44

55
node('docker') {

README.md

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Or if you want to chat with us about gitops in general, visit us [here](https://
2323
- [GitOps tool](#gitops-tool)
2424
- [Flux v1](#flux-v1)
2525
- [ArgoCD](#argocd)
26-
- [Default Folder Structure](#default-folder-structure)
26+
- [Default Folder Structure in source repository](#default-folder-structure-in-source-repository)
2727
- [Plain-k8s](#plain-k8s)
2828
- [Helm](#helm)
2929
- [GitOps-Config](#gitops-config)
@@ -35,6 +35,7 @@ Or if you want to chat with us about gitops in general, visit us [here](https://
3535
- [Helm deployment](#helm-deployment)
3636
- [Conventions for helm deployment](#conventions-for-helm-deployment)
3737
- [`helm template` with ArgoCD application](#helm-template-with-argocd-application)
38+
- [Folder Structure in destination gitops repository](#folder-structure-in-destination-gitops-repository)
3839
- [Extra Files](#extra-files)
3940
- [SCM-Provider](#scm-provider)
4041
- [Validators](#validators)
@@ -101,15 +102,29 @@ def gitopsConfig = [
101102
repositoryUrl: 'gitops'
102103
],
103104
application: 'spring-petclinic',
104-
gitopsTool: 'FLUX' /* or 'ARGO' */
105+
gitopsTool: 'FLUX' /* or 'ARGO' */,
106+
stages: [
107+
staging: [
108+
namespace: 'staging',
109+
deployDirectly: true
110+
],
111+
production: [
112+
namespace: 'production',
113+
deployDirectly: false
114+
]
115+
],
116+
deployments: [
117+
plain : []
118+
]
119+
]
105120
]
106121
107122
deployViaGitops(gitopsConfig)
108123
```
109124

110125
### More options
111126

112-
The following is an example of a small and yet complete **gitops-config** for a helm-deployment of an application.
127+
The following is an example shows all options of a **gitops-config** for a helm-deployment of an application.
113128
This would lead to a deployment of your staging environment by updating the resources of "staging" folder within your
114129
gitops-folder in git. For production it will open a PR with the changes.
115130

@@ -129,16 +144,19 @@ def gitopsConfig = [
129144
mainBranch: 'master' /* Default: 'main' */,
130145
deployments: [
131146
sourcePath: 'k8s' /* Default: 'k8s' */,
147+
destinationRootPath: '.' /* Default: '.' */,
132148
/* See docs for helm or plain k8s deployment options */
133149
helm : [
134150
repoType : 'HELM',
135151
credentialsId : 'creds',
152+
mainBranch : 'main', /* Default: 'main' */,
136153
repoUrl : <helmChartRepository>,
137154
chartName: <helmChartName>,
138155
version : <helmChartVersion>,
139156
updateValues : [[fieldPath: "image.name", newValue: imageName]]
140157
]
141158
],
159+
folderStructureStrategy: 'GLOBAL_ENV', /* or ENV_PER_APP */
142160
stages: [
143161
staging: [
144162
namespace: 'my-staging',
@@ -262,7 +280,7 @@ See [Example of ArgoCD application in GitOps Playground](https://github.com/clou
262280

263281
---
264282

265-
## Default Folder Structure
283+
## Default Folder Structure in source repository
266284

267285
A default project structure in your application repo could look like the examples below. Make sure you have your k8s
268286
and/or helm resources bundled in a folder. This specific resources folder (here `k8s`) will later be specified by the
@@ -317,7 +335,7 @@ First of all there are some mandatory properties e.g. the information about your
317335
* `gitopsTool: 'ARGO'` - Name of the gitops tool. Currently supporting `'FLUX'` (for now only fluxV1) and `'ARGO'`.
318336
* and some optional parameters (below are the defaults) for the configuration of the dependency to the ces-build-lib or the default name for the git branch:
319337
* `cesBuildLibRepo: 'https://github.com/cloudogu/ces-build-lib'`
320-
* `cesBuildLibVersion: '1.45.0'`
338+
* `cesBuildLibVersion: '1.62.0'`
321339
* `mainBranch: 'main'`
322340
323341
---
@@ -326,40 +344,37 @@ First of all there are some mandatory properties e.g. the information about your
326344
The GitOps-build-lib uses some docker images internally (To run Helm or Kubectl commands and specific Validators inside a docker container).
327345
All of these have set default images, but you can change them if you wish to.
328346
347+
```groovy
348+
def gitopsConfig = [
349+
buildImages: [
350+
// These are used to run helm and kubectl commands in the core logic
351+
helm: 'ghcr.io/cloudogu/helm:3.5.4-1',
352+
kubectl: 'lachlanevenson/k8s-kubectl:v1.19.3',
353+
// These are used for each specific validator via an imageRef property inside the validators config. See [Validators] for examples.
354+
kubeval: 'ghcr.io/cloudogu/helm:3.5.4-1',
355+
helmKubeval: 'ghcr.io/cloudogu/helm:3.5.4-1',
356+
yamllint: 'cytopia/yamllint:1.25-0.7'
357+
]
358+
]
359+
```
360+
361+
Optional - if image is in a private repository, you can pass a `credentialsId` for pulling images.
362+
329363
```groovy
330364
def gitopsConfig = [
331365
buildImages: [
332-
// These are used to run helm and kubectl commands in the core logic
333-
//
334366
helm: [
335-
image: 'ghcr.io/cloudogu/helm:3.5.4-1'
336-
credentialsId: 'myCredentials' (optional - only needed if image is in a private repository. CredentialsId is getting pulled from Jenkins credentials)
367+
image: 'ghcr.io/cloudogu/helm:3.11.1-2',
368+
credentialsId: 'myCredentials'
337369
],
338-
kubectl: [
339-
image: 'lachlanevenson/k8s-kubectl:v1.19.3'
340-
credentialsId: 'myCredentials' (optional - only needed if image is in a private repository. CredentialsId is getting pulled from Jenkins credentials)
341-
],
342-
// These are used for each specific validator via an imageRef property inside the validators config. See [Validators] for examples.
343-
kubeval: [
344-
image: 'ghcr.io/cloudogu/helm:3.5.4-1'
345-
credentialsId: 'myCredentials' (optional - only needed if image is in a private repository. CredentialsId is getting pulled from Jenkins credentials)
346-
],
347-
helmKubeval: [
348-
image: 'ghcr.io/cloudogu/helm:3.5.4-1'
349-
credentialsId: 'myCredentials' (optional - only needed if image is in a private repository. CredentialsId is getting pulled from Jenkins credentials)
350-
],
351-
yamllint: [
352-
image: 'cytopia/yamllint:1.25-0.7'
353-
credentialsId: 'myCredentials' (optional - only needed if image is in a private repository. CredentialsId is getting pulled from Jenkins credentials)
354-
]
370+
// ...
355371
]
356372
]
357373
```
358374

359375
## Stages
360376
The GitOps-build-lib supports builds on multiple stages. A stage is defined by a name and contains a namespace (used to
361-
generate the resources) and a deployment-flag. If no stages is passed into the gitops-config by the user, the default
362-
is set to:
377+
generate the resources) and a deployment-flag:
363378

364379
```groovy
365380
def gitopsConfig = [
@@ -376,7 +391,6 @@ def gitopsConfig = [
376391
]
377392
```
378393

379-
The defaults above can be overwritten by providing an entry for 'stages' within your config.
380394
If it is set to deploy directly it will commit and push to your desired `gitops-folder` and therefore triggers a deployment. If it is set to false
381395
it will create a PR on your `gitops-folder`. **Remember** there are important conventions regarding namespaces and the folder structure (see [namespaces](#namespaces)).
382396

@@ -509,6 +523,7 @@ The deployment has to contain the path of your k8s resources within the applicat
509523
def gitopsConfig = [
510524
deployments: [
511525
sourcePath: 'k8s', // path of k8s resources in application repository. Default: 'k8s'
526+
destinationRootPath: '.', // Root-Subfolder in the gitops repository, where the following folders for stages and apps shall be created. Default: '.'
512527
// Either "plain" or "helm" is mandatory
513528
plain: [], // use plain if you only have, as the name suggests, plain k8s resources
514529
helm: [] // or if you want to deploy a helm release use `helm`
@@ -601,6 +616,29 @@ We decided to generate plain k8s Resources from Helm applications before we push
601616

602617
---
603618

619+
## Folder Structure in destination gitops repository
620+
621+
You can customize in which path the final manifests of the application will be created in the gitops repository. For this, you can modify the following parameters:
622+
```groovy
623+
def gitopsConfig = [
624+
deployments: [
625+
destinationRootPath: '.' /* Default: '.' */
626+
],
627+
folderStructureStrategy: 'GLOBAL_ENV' /* Default: 'GLOBAL_ENV', or ENV_PER_APP */
628+
]
629+
```
630+
* `destinationRootPath`: Specifies in which subfolder the following folders of `folderStructureStrategy` are created. Defaults to the root of the repository.
631+
* `folderStructureStrategy`: Possible values:
632+
* `GLOBAL_ENV`: The manifests will be commited into `$DESTINATION_ROOT_PATH/STAGE_NAME/APP_NAME/` in the destination gitops repository
633+
* `ENV_PER_APP`: The manifests will be commited into `$DESTINATION_ROOT_PATH/APP_NAME/STAGE_NAME/` in the destination gitops repository
634+
635+
636+
Example for **Global Environments** vs **Environment per App** ([Source](https://github.com/cloudogu/gitops-patterns#implementing-release-promotion)):
637+
638+
![Global Envs](https://github.com/cloudogu/gitops-talks/blob/1744c1d/images/global-environments.svg)
639+
![Env per app](https://github.com/cloudogu/gitops-talks/blob/1744c1d/images/environment-per-app.svg)
640+
641+
---
604642

605643
## Extra Files
606644

pom.xml

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,77 +12,59 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<jacoco.version>0.8.5</jacoco.version>
16-
<maven.compiler.target>1.8</maven.compiler.target>
17-
<maven.compiler.source>1.8</maven.compiler.source>
15+
<jacoco.version>0.8.8</jacoco.version>
16+
<maven.compiler.target>11</maven.compiler.target>
17+
<maven.compiler.source>11</maven.compiler.source>
1818
</properties>
1919

2020
<dependencies>
21-
<dependency>
22-
<groupId>com.cloudbees</groupId>
23-
<artifactId>groovy-cps</artifactId>
24-
<version>1.21</version>
25-
</dependency>
26-
2721
<dependency>
2822
<groupId>org.codehaus.groovy</groupId>
2923
<artifactId>groovy-all</artifactId>
30-
<version>2.4.11</version>
24+
<version>2.4.21</version>
25+
<!-- Current version can be found out via Jenkins Groovy console: println GroovySystem.version-->
3126
</dependency>
3227

3328
<dependency>
3429
<groupId>org.codehaus.groovy</groupId>
3530
<artifactId>groovy-yaml</artifactId>
36-
<version>3.0.7</version>
31+
<version>3.0.15</version>
3732
<scope>test</scope>
3833
</dependency>
3934

4035

4136
<dependency>
4237
<groupId>org.junit.jupiter</groupId>
4338
<artifactId>junit-jupiter</artifactId>
44-
<version>5.6.2</version>
39+
<version>5.9.2</version>
4540
<scope>test</scope>
4641
</dependency>
4742

4843
<dependency>
4944
<groupId>org.mockito</groupId>
5045
<artifactId>mockito-junit-jupiter</artifactId>
51-
<version>3.4.6</version>
46+
<version>5.1.1</version>
5247
<scope>test</scope>
5348
</dependency>
5449

5550
<dependency>
5651
<groupId>org.assertj</groupId>
5752
<artifactId>assertj-core</artifactId>
58-
<version>3.17.0</version>
53+
<version>3.24.2</version>
5954
<scope>test</scope>
6055
</dependency>
6156

6257
<dependency>
6358
<groupId>com.lesfurets</groupId>
6459
<artifactId>jenkins-pipeline-unit</artifactId>
65-
<version>1.8</version>
60+
<version>1.17</version>
6661
<scope>test</scope>
6762
</dependency>
6863

6964
<dependency>
7065
<groupId>org.spockframework</groupId>
7166
<artifactId>spock-core</artifactId>
72-
<version>1.1-groovy-2.4</version>
73-
<scope>test</scope>
74-
</dependency>
75-
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
76-
<groupId>net.bytebuddy</groupId>
77-
<artifactId>byte-buddy</artifactId>
78-
<version>1.10.13</version>
79-
<scope>test</scope>
80-
</dependency>
81-
<dependency> <!-- enables mocking of classes without default constructor (together with
82-
CGLIB) -->
83-
<groupId>org.objenesis</groupId>
84-
<artifactId>objenesis</artifactId>
85-
<version>2.5.1</version>
67+
<version>1.3-groovy-2.4</version>
8668
<scope>test</scope>
8769
</dependency>
8870

@@ -91,7 +73,7 @@
9173
<groupId>com.github.cloudogu</groupId>
9274
<artifactId>ces-build-lib</artifactId>
9375
<!-- Keep this version in sync with the one used in Jenkinsfile -->
94-
<version>1.45.0</version>
76+
<version>1.62.0</version>
9577
<!-- Don't ship this dependency with the app -->
9678
<optional>true</optional>
9779
<!-- Don't inherit this dependency! -->
@@ -126,20 +108,20 @@
126108
<plugins>
127109
<plugin>
128110
<artifactId>maven-compiler-plugin</artifactId>
129-
<version>3.8.0</version>
111+
<version>3.11.0</version>
130112
<configuration>
131113
<compilerId>groovy-eclipse-compiler</compilerId>
132114
</configuration>
133115
<dependencies>
134116
<dependency>
135117
<groupId>org.codehaus.groovy</groupId>
136118
<artifactId>groovy-eclipse-compiler</artifactId>
137-
<version>3.3.0-01</version>
119+
<version>3.7.0</version>
138120
</dependency>
139121
<dependency>
140122
<groupId>org.codehaus.groovy</groupId>
141123
<artifactId>groovy-eclipse-batch</artifactId>
142-
<version>2.5.6-01</version>
124+
<version>2.5.14-02</version>
143125
</dependency>
144126
</dependencies>
145127
</plugin>
@@ -159,7 +141,7 @@
159141
<plugin>
160142
<groupId>org.apache.maven.plugins</groupId>
161143
<artifactId>maven-source-plugin</artifactId>
162-
<version>3.0.1</version>
144+
<version>3.2.1</version>
163145
<executions>
164146
<execution>
165147
<id>attach-sources</id>

0 commit comments

Comments
 (0)