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

Add example of using kustomization. #11

Closed
wants to merge 9 commits into from
Closed
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
42 changes: 29 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pipeline {
agent any
environment {
DEPLOYMENT = readYaml(file: './nais.yaml')
DEPLOYMENT = readYaml(file: './nais/base/nais.yaml')
APPLICATION_NAME = "${DEPLOYMENT.metadata.name}"
ZONE = "${DEPLOYMENT.metadata.annotations.zone}"
NAMESPACE = "${DEPLOYMENT.metadata.namespace}"
Expand Down Expand Up @@ -40,10 +40,6 @@ pipeline {
docker push ${DOCKER_IMAGE_VERSION} || true
"""
}

sh label: 'Prepare service contract', script: """
sed 's/latest/${VERSION}/' nais.yaml | tee nais-deployed.yaml
"""
}

post {
Expand All @@ -59,24 +55,32 @@ pipeline {

junit 'build/test-results/test/*.xml'
}

success {
archiveArtifacts artifacts: 'nais*.yaml', fingerprint: true
}
}
}

stage('Acceptance testing') {
stages {
stage('Deploy to pre-production') {
steps {

sh label: 'Prepare dev service contract', script: """
sed 's/latest/${VERSION}/' ./nais/dev/nais.yaml | tee ./nais/dev/nais.yaml
kustomize build nais/dev -o nais/nais-dev-deployed.yaml
"""

sh label: 'Deploy with kubectl', script: """
kubectl config use-context dev-${env.ZONE}
kubectl apply -n ${env.NAMESPACE} -f redis.yaml --wait
kubectl apply -n ${env.NAMESPACE} -f nais-deployed.yaml --wait
kubectl apply -n ${env.NAMESPACE} -f nais/nais-dev-deployed.yaml --wait
kubectl rollout status -w deployment/${APPLICATION_NAME}
"""
}

post {
success {
archiveArtifacts artifacts: 'nais/nais-dev-deployed.yaml', fingerprint: true
}
}

}

stage('Run tests') {
Expand Down Expand Up @@ -156,13 +160,25 @@ pipeline {
when { branch 'master' }

steps {

sh label: 'Prepare prod service contract', script: """
sed 's/latest/${VERSION}/' ./nais/prod/nais.yaml | tee ./nais/prod/nais.yaml
kustomize build nais/prod -o nais/nais-prod-deployed.yaml
"""

sh label: 'Deploy with kubectl', script: """
kubectl config use-context prod-${env.ZONE}
kubectl apply -n ${env.NAMESPACE} -f redis.yaml --wait
kubectl apply -n ${env.NAMESPACE} -f nais-deployed-.yaml --wait
kubectl apply -n ${env.NAMESPACE} -f nais/nais-deployed-prod.yaml --wait
kubectl rollout status -w deployment/${APPLICATION_NAME}
"""
}

post {
success {
archiveArtifacts artifacts: 'nais/nais-prod-deployed.yaml', fingerprint: true
}
}

}

stage('Release') {
Expand Down
6 changes: 6 additions & 0 deletions nais/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
commonLabels:
app: dp-regel-api
team: teamdagpenger
resources:
- nais.yaml
- redis.yaml
6 changes: 3 additions & 3 deletions nais.yaml → nais/base/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ spec:
enabled: true
env:
- name: REDIS_HOST
value: dp-regel-api-redis.default.svc.nais.local
value: redis
- name: KAFKA_BOOTSTRAP_SERVERS
value: d26apvl00159.test.local:8443,d26apvl00160.test.local:8443,d26apvl00161.test.local:8443
value: kafka
ingresses:
- "https://dp-regel-api.nais.preprod.local"
- "https://app"
File renamed without changes.
4 changes: 4 additions & 0 deletions nais/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bases:
- ./../base
patchesStrategicMerge:
- nais.yaml
13 changes: 13 additions & 0 deletions nais/dev/nais.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: "nais.io/v1alpha1"
kind: "Application"
metadata:
name: dp-regel-api
spec:
image: repo.adeo.no:5443/dp-regel-api:latest
env:
- name: REDIS_HOST
value: dp-regel-api-redis.default.svc.nais.local
- name: KAFKA_BOOTSTRAP_SERVERS
value: d26apvl00159.test.local:8443,d26apvl00160.test.local:8443,d26apvl00161.test.local:8443
ingresses:
- "https://dp-regel-api.nais.preprod.local"
4 changes: 4 additions & 0 deletions nais/prod/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bases:
- ./../base
patchesStrategicMerge:
- nais.yaml
13 changes: 13 additions & 0 deletions nais/prod/nais.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: "nais.io/v1alpha1"
kind: "Application"
metadata:
name: dp-regel-api
spec:
image: repo.adeo.no:5443/dp-regel-api:latest
env:
- name: REDIS_HOST
value: dp-regel-api-redis.default.svc.nais.local
- name: KAFKA_BOOTSTRAP_SERVERS
value: a01apvl00145.adeo.no:8443,a01apvl00146.adeo.no:8443,a01apvl00147.adeo.no:8443,a01apvl00148.adeo.no:8443,a01apvl00149.adeo.no:8443,a01apvl150.adeo.no:8443
ingresses:
- "https://dp-regel-api.nais.adeo.no"