Skip to content

Commit 8bf4e5a

Browse files
authored
Merge pull request #221 from cloudogu/feature/registry_parameter
BREAKING: Refactor params registry-push + pull to registry-proxy
2 parents c5e42d8 + 43c67b1 commit 8bf4e5a

File tree

15 files changed

+233
-345
lines changed

15 files changed

+233
-345
lines changed

applications/argocd/petclinic/helm/Jenkinsfile.ftl

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ String getApplication() { "spring-petclinic-helm" }
44
String getScmManagerCredentials() { 'scmm-user' }
55
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
66
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
7-
<#if registry.twoRegistries>
8-
String getDockerRegistryPullBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PULL_URL }
9-
String getDockerRegistryPullCredentials() { 'registry-pull-user' }
10-
String getDockerRegistryPushBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PUSH_URL }
11-
String getDockerRegistryPushPath() { env.${namePrefixForEnvVars}REGISTRY_PUSH_PATH }
12-
String getDockerRegistryPushCredentials() { 'registry-push-user' }
13-
<#else>
7+
148
String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
159
String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
1610
String getDockerRegistryCredentials() { 'registry-user' }
11+
12+
<#if registry.twoRegistries>
13+
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
14+
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
1715
</#if>
1816

1917
<#noparse>
@@ -66,33 +64,24 @@ node {
6664
stage('Docker') {
6765
String imageTag = createImageTag()
6866
</#noparse>
69-
<#if registry.twoRegistries>
70-
<#noparse>
71-
String pathPrefix = !dockerRegistryPushPath?.trim() ? "" : "${dockerRegistryPushPath}/"
72-
imageName = "${dockerRegistryPushBaseUrl}/${pathPrefix}${application}:${imageTag}"
73-
docker.withRegistry("http://${dockerRegistryPullBaseUrl}", dockerRegistryPullCredentials) {
74-
image = docker.build(imageName, '.')
75-
}
76-
</#noparse>
77-
<#else>
7867
<#noparse>
7968
String pathPrefix = !dockerRegistryPath?.trim() ? "" : "${dockerRegistryPath}/"
8069
imageName = "${dockerRegistryBaseUrl}/${pathPrefix}${application}:${imageTag}"
81-
image = docker.build(imageName, '.')
8270
</#noparse>
83-
</#if>
84-
85-
if (isBuildSuccessful()) {
8671
<#if registry.twoRegistries>
8772
<#noparse>
88-
docker.withRegistry("http://${dockerRegistryPushBaseUrl}", dockerRegistryPushCredentials) {
73+
docker.withRegistry("http://${dockerRegistryProxyBaseUrl}", dockerRegistryProxyCredentials) {
74+
image = docker.build(imageName, '.')
75+
}
8976
</#noparse>
9077
<#else>
9178
<#noparse>
92-
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
79+
image = docker.build(imageName, '.')
9380
</#noparse>
9481
</#if>
9582
<#noparse>
83+
if (isBuildSuccessful()) {
84+
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
9685
image.push()
9786
}
9887
} else {

applications/argocd/petclinic/plain-k8s/Jenkinsfile.ftl

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ String getApplication() { 'spring-petclinic-plain' }
44
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
55
String getScmManagerCredentials() { 'scmm-user' }
66
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
7-
<#if registry.twoRegistries>
8-
String getDockerRegistryPullBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PULL_URL }
9-
String getDockerRegistryPullCredentials() { 'registry-pull-user' }
10-
String getDockerRegistryPushBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PUSH_URL }
11-
String getDockerRegistryPushPath() { env.${namePrefixForEnvVars}REGISTRY_PUSH_PATH }
12-
String getDockerRegistryPushCredentials() { 'registry-push-user' }
13-
<#else>
7+
148
String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
159
String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
1610
String getDockerRegistryCredentials() { 'registry-user' }
11+
12+
<#if registry.twoRegistries>
13+
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
14+
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
1715
</#if>
16+
1817
<#noparse>
1918
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib" }
2019
String getCesBuildLibVersion() { '2.2.0' }
@@ -57,33 +56,24 @@ node {
5756
stage('Docker') {
5857
String imageTag = createImageTag()
5958
</#noparse>
60-
<#if registry.twoRegistries>
61-
<#noparse>
62-
String pathPrefix = !dockerRegistryPushPath?.trim() ? "" : "${dockerRegistryPushPath}/"
63-
imageName = "${dockerRegistryPushBaseUrl}/${pathPrefix}${application}:${imageTag}"
64-
docker.withRegistry("http://${dockerRegistryPullBaseUrl}", dockerRegistryPullCredentials) {
65-
image = docker.build(imageName, '.')
66-
}
67-
</#noparse>
68-
<#else>
6959
<#noparse>
7060
String pathPrefix = !dockerRegistryPath?.trim() ? "" : "${dockerRegistryPath}/"
71-
imageName = "${dockerRegistryBaseUrl}/${pathPrefix}${application}:${imageTag}"
72-
image = docker.build(imageName, '.')
61+
imageName = "${dockerRegistryBaseUrl}/${pathPrefix}${application}:${imageTag}"
7362
</#noparse>
74-
</#if>
75-
76-
if (isBuildSuccessful()) {
7763
<#if registry.twoRegistries>
7864
<#noparse>
79-
docker.withRegistry("http://${dockerRegistryPushBaseUrl}", dockerRegistryPushCredentials) {
65+
docker.withRegistry("http://${dockerRegistryProxyBaseUrl}", dockerRegistryProxyCredentials) {
66+
image = docker.build(imageName, '.')
67+
}
8068
</#noparse>
8169
<#else>
8270
<#noparse>
83-
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
71+
image = docker.build(imageName, '.')
8472
</#noparse>
8573
</#if>
8674
<#noparse>
75+
if (isBuildSuccessful()) {
76+
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
8777
image.push()
8878
}
8979
} else {
@@ -136,7 +126,7 @@ node {
136126
]
137127
<#noparse>
138128
addSpecificGitOpsConfig(gitopsConfig)
139-
129+
140130
deployViaGitops(gitopsConfig)
141131
} else {
142132
echo 'Skipping deploy, because build not successful or not on main branch'
@@ -157,9 +147,9 @@ void addSpecificGitOpsConfig(gitopsConfig) {
157147
cesBuildLibRepo: cesBuildLibRepo,
158148
cesBuildLibVersion: cesBuildLibVersion,
159149
cesBuildLibCredentialsId: scmManagerCredentials,
160-
161-
162-
// The GitOps playground provides parameters for overwriting the build images used by gitops-build-lib, so
150+
151+
152+
// The GitOps playground provides parameters for overwriting the build images used by gitops-build-lib, so
163153
// it also works in an offline context.
164154
// Those parameters overwrite the following parameters.
165155
// If you can access the internet, you can rely on the defaults, which load the images from public registries.
@@ -193,7 +183,7 @@ def loadLibraries() {
193183
// @Library(["github.com/cloudogu/ces-build-lib@${cesBuildLibVersion}", "github.com/cloudogu/gitops-build-lib@${gitOpsBuildLibRepo}"]) _
194184
//import com.cloudogu.ces.cesbuildlib.*
195185
//import com.cloudogu.ces.gitopsbuildlib.*
196-
186+
197187
cesBuildLib = library(identifier: "ces-build-lib@${cesBuildLibVersion}",
198188
retriever: modernSCM([$class: 'GitSCMSource', remote: cesBuildLibRepo, credentialsId: scmManagerCredentials])
199189
).com.cloudogu.ces.cesbuildlib

docs/configuration.schema.json

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -501,33 +501,17 @@
501501
"type" : "string",
502502
"description" : "Optional when registry-url is set"
503503
},
504-
"pullPassword" : {
504+
"proxyPassword" : {
505505
"type" : "string",
506-
"description" : "Optional when registry-pull-url is set"
506+
"description" : "Use with registry-proxy-url, added to Jenkins as credentials."
507507
},
508-
"pullUrl" : {
508+
"proxyUrl" : {
509509
"type" : "string",
510-
"description" : "The url of your external pull-registry. Make sure to always use this with registry-push-url"
510+
"description" : "The url of your proxy-registry. Used in pipelines to authorize pull base images. Use in conjunction with petclinic base image."
511511
},
512-
"pullUsername" : {
512+
"proxyUsername" : {
513513
"type" : "string",
514-
"description" : "Optional when registry-pull-url is set"
515-
},
516-
"pushPassword" : {
517-
"type" : "string",
518-
"description" : "Optional when registry-push-url is set"
519-
},
520-
"pushPath" : {
521-
"type" : "string",
522-
"description" : "Optional when registry-push-url is set"
523-
},
524-
"pushUrl" : {
525-
"type" : "string",
526-
"description" : "The url of your external pull-registry. Make sure to always use this with registry-pull-url"
527-
},
528-
"pushUsername" : {
529-
"type" : "string",
530-
"description" : "Optional when registry-push-url is set"
514+
"description" : "Use with registry-proxy-url, added to Jenkins as credentials."
531515
},
532516
"url" : {
533517
"type" : "string",

docs/developers.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -427,27 +427,25 @@ That is, for most helm charts, you'll need to set an individual value.
427427

428428
## Testing two registries
429429

430-
### Very simple test
430+
### Basic test
431431
* Start playground once,
432432
* then again with these parameters:
433-
`--registry-pull-url=localhost:30000 --registry-push-url=localhost:30000`
433+
`--registry-url=localhost:30000 --registry-proxy-url=localhost:30000 --registry-proxy-username=Proxy --registry-proxy-password=Proxy12345`
434434
* The petclinic pipelines should still run
435435

436436
### Proper test
437437

438438
* Start cluster:
439439
```shell
440-
# Stop other cluster, if necessary
441-
# k3d cluster stop gitops-playground
442-
scripts/init-cluster.sh --cluster-name=two-regs
440+
scripts/init-cluster.sh
443441
```
444442
* Setup harbor as stated [above](#external-registry-for-development), but with Port `30000`.
445443
Wait for harbor to startup: ` kubectl get pod -n harbor`
446444
Don't care about crashing harbor `jobservice`
447445
* Create registries and base image:
448446
449447
```bash
450-
operations=("Pull" "Push")
448+
operations=("Proxy" "Registry")
451449
452450
for operation in "${operations[@]}"; do
453451
@@ -460,30 +458,31 @@ for operation in "${operations[@]}"; do
460458
echo creating user $operation with PW ${operation}12345
461459
curl -s --fail 'http://localhost:30000/api/v2.0/users' -X POST -u admin:Harbor12345 -H 'Content-Type: application/json' --data-raw "{\"username\":\"$operation\",\"email\":\"[email protected]\",\"realname\":\"$operation example\",\"password\":\"${operation}12345\",\"comment\":null}"
462460
463-
echo "Adding member $operation to project $lower_operation; ID=${projectId}"
461+
echo "Adding member $operation to project $lower_operation; ID=${projectId}"
464462
465463
curl --fail "http://localhost:30000/api/v2.0/projects/${projectId}/members" -X POST -u admin:Harbor12345 -H 'Content-Type: application/json' --data-raw "{\"role_id\":4,\"member_user\":{\"username\":\"$operation\"}}"
466464
done
467465
468-
skopeo copy docker://eclipse-temurin:11-jre-alpine --dest-creds Pull:Pull12345 --dest-tls-verify=false docker://localhost:30000/pull/eclipse-temurin:11-jre-alpine
466+
skopeo copy docker://eclipse-temurin:11-jre-alpine --dest-creds Proxy:Proxy12345 --dest-tls-verify=false docker://localhost:30000/proxy/eclipse-temurin:11-jre-alpine
469467
```
470468
471469
* Deploy playground:
472470
473471
```bash
474-
docker run --rm -t -u $(id -u) \
475-
-v ~/.config/k3d/kubeconfig-two-regs.yaml:/home/.kube/config \
476-
-v $(pwd)/gitops-playground.yaml:/config/gitops-playground.yaml \
477-
--net=host \
478-
gitops-playground:dev -x --yes --argocd --ingress-nginx --base-url=http://localhost \
479-
--registry-push-url=localhost:30000 \
480-
--registry-push-path=push \
481-
--registry-push-username=Push \
482-
--registry-push-password=Push12345 \
483-
--registry-pull-url=localhost:30000 \
484-
--registry-pull-username=Pull \
485-
--registry-pull-password=Pull12345 \
486-
--petclinic-image=localhost:30000/pull/eclipse-temurin:11-jre-alpine
472+
docker run --rm -t -u $(id -u) \
473+
-v ~/.config/k3d/kubeconfig-gitops-playground.yaml:/home/.kube/config \
474+
--net=host \
475+
gitops-playground:dev \
476+
--yes --argocd --ingress-nginx --base-url=http://localhost \
477+
--registry-url=localhost:30000 \
478+
--registry-path=registry \
479+
--registry-username=Registry \
480+
--registry-password=Registry12345 \
481+
--registry-proxy-url=localhost:30000 \
482+
--registry-proxy-username=Proxy \
483+
--registry-proxy-password=Proxy12345 \
484+
--petclinic-image=localhost:30000/proxy/eclipse-temurin:11-jre-alpine
485+
487486
# Or with config file --config-file=/config/gitops-playground.yaml
488487
```
489488
@@ -496,8 +495,8 @@ for namespace in "${namespaces[@]}"; do
496495
kubectl create secret docker-registry regcred \
497496
-n $namespace \
498497
--docker-server=localhost:30000 \
499-
--docker-username=Push \
500-
--docker-password=Push12345
498+
--docker-username=Registry\
499+
--docker-password=Registry12345
501500
kubectl patch serviceaccount default -n $namespace -p '{"imagePullSecrets": [{"name": "regcred"}]}'
502501
done
503502
```
@@ -506,15 +505,15 @@ The same using a config file looks like so:
506505
507506
```yaml
508507
registry:
509-
pullUrl: localhost:30000
510-
pullUsername: Pull
511-
pullPassword: Pull12345
512-
pushUrl: localhost:30000
513-
pushUsername: Push
514-
pushPassword: Push12345
515-
pushPath: push
508+
proxyUrl: localhost:30000
509+
proxyUsername: Proxy
510+
proxyPassword: Proxy12345
511+
registryUrl: localhost:30000
512+
registryUsername: Registry
513+
registryPassword: Registry12345
514+
registryPath: Registry
516515
images:
517-
petclinic: localhost:30000/pull/eclipse-temurin:11-jre-alpine
516+
petclinic: localhost:30000/proxy/eclipse-temurin:11-jre-alpine
518517
```
519518
520519
## Emulate an airgapped environment

exercises/petclinic-helm/Jenkinsfile.ftl

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ String getApplication() { "exercise-spring-petclinic-helm" }
44
String getScmManagerCredentials() { 'scmm-user' }
55
String getConfigRepositoryPRBaseUrl() { env.SCMM_URL }
66
String getConfigRepositoryPRRepo() { '${namePrefix}argocd/example-apps' }
7-
<#if registry.twoRegistries>
8-
String getDockerRegistryPullBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PULL_URL }
9-
String getDockerRegistryPullCredentials() { 'registry-pull-user' }
10-
String getDockerRegistryPushBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PUSH_URL }
11-
String getDockerRegistryPushPath() { env.${namePrefixForEnvVars}REGISTRY_PUSH_PATH }
12-
String getDockerRegistryPushCredentials() { 'registry-push-user' }
13-
<#else>
7+
148
String getDockerRegistryBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_URL }
159
String getDockerRegistryPath() { env.${namePrefixForEnvVars}REGISTRY_PATH }
1610
String getDockerRegistryCredentials() { 'registry-user' }
11+
12+
<#if registry.twoRegistries>
13+
String getDockerRegistryProxyCredentials() { 'registry-proxy-user' }
14+
String getDockerRegistryProxyBaseUrl() { env.${namePrefixForEnvVars}REGISTRY_PROXY_URL }
1715
</#if>
1816
<#noparse>
1917
String getCesBuildLibRepo() { "${env.SCMM_URL}/repo/3rd-party-dependencies/ces-build-lib/" }
@@ -60,35 +58,25 @@ node {
6058
stage('Docker') {
6159
String imageTag = createImageTag()
6260
</#noparse>
63-
<#if registry.twoRegistries>
64-
<#noparse>
65-
String pathPrefix = !dockerRegistryPushPath?.trim() ? "" : "${dockerRegistryPushPath}/"
66-
imageName = "${dockerRegistryPushBaseUrl}/${pathPrefix}${application}:${imageTag}"
67-
docker.withRegistry("http://${dockerRegistryPullBaseUrl}", dockerRegistryPullCredentials) {
68-
image = docker.build(imageName, '.')
69-
}
70-
</#noparse>
71-
<#else>
7261
<#noparse>
7362
String pathPrefix = !dockerRegistryPath?.trim() ? "" : "${dockerRegistryPath}/"
7463
imageName = "${dockerRegistryBaseUrl}/${pathPrefix}${application}:${imageTag}"
75-
image = docker.build(imageName, '.')
7664
</#noparse>
77-
</#if>
78-
79-
80-
if (isBuildSuccessful()) {
8165
<#if registry.twoRegistries>
8266
<#noparse>
83-
docker.withRegistry("http://${dockerRegistryPushBaseUrl}", dockerRegistryPushCredentials) {
67+
docker.withRegistry("http://${dockerRegistryProxyBaseUrl}", dockerRegistryProxyCredentials) {
68+
image = docker.build(imageName, '.')
69+
}
8470
</#noparse>
8571
<#else>
8672
<#noparse>
87-
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
73+
image = docker.build(imageName, '.')
8874
</#noparse>
8975
</#if>
9076
<#noparse>
91-
image.push()
77+
if (isBuildSuccessful()) {
78+
docker.withRegistry("http://${dockerRegistryBaseUrl}", dockerRegistryCredentials) {
79+
image.push()
9280
}
9381
} else {
9482
echo 'Skipping docker push, because build not successful'

0 commit comments

Comments
 (0)