Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.

Commit ad16d1c

Browse files
authored
fix(AAE-1223): Added init container for Postgres and RabbitMq (#293)
* fix(AAE-1207): Added init container for Postgres and RabbitMq * fix: publish preview artifacts * fix(Jenkins): Enabled ITs * fix: Enabled jenkins-x-docker-registry mirror * fix: Added missing SERVER_SERVLET_CONTEXTPATH * fix: move SERVER_SERVLET_CONTEXTPATH to extraEnv * fix: error converting YAML to JSON: yaml: line 55 * fix: Added notifications scope to rabbitmq-name tpl
1 parent 1f20c47 commit ad16d1c

File tree

7 files changed

+117
-161
lines changed

7 files changed

+117
-161
lines changed

Jenkinsfile

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pipeline {
1212
environment {
1313
ORG = "activiti"
1414
APP_NAME = "activiti-cloud-notifications-graphql"
15-
15+
VERSION = jx_release_version()
16+
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
1617
GITHUB_CHARTS_REPO = "https://github.com/${ORG}/activiti-cloud-helm-charts.git"
1718
GITHUB_HELM_REPO_URL = "https://${ORG}.github.io/activiti-cloud-helm-charts/"
1819
RELEASE_BRANCH = "master"
@@ -23,22 +24,25 @@ pipeline {
2324
branch "PR-*"
2425
}
2526
environment {
26-
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
27+
PROJECT_VERSION = maven_project_version()
28+
VERSION = "$PROJECT_VERSION".replaceAll("SNAPSHOT","$BRANCH_NAME-$BUILD_NUMBER-SNAPSHOT")
2729
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
2830
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
2931
}
3032
steps {
3133
container("maven") {
32-
sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
33-
sh "mvn install"
34-
// sh "export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml"
34+
sh "mvn versions:set -DnewVersion=$VERSION"
35+
sh "mvn install -DskipITs=false"
36+
sh "export VERSION=$VERSION && skaffold build -f skaffold.yaml"
3537

36-
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
38+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"
3739

3840
// Let's build chart to check for any errors
39-
//dir("./charts/$APP_NAME") {
40-
// sh "make build"
41-
//}
41+
dir("./charts/$APP_NAME") {
42+
sh "make preview"
43+
}
44+
45+
sh "mvn deploy -DskipTests"
4246
}
4347
}
4448
}
@@ -54,19 +58,19 @@ pipeline {
5458

5559
sh "jx step git credentials"
5660
// so we can retrieve the version in later steps
57-
sh "echo \$(jx-release-version) > VERSION"
58-
sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
61+
sh "echo $VERSION > VERSION"
62+
sh "mvn versions:set -DnewVersion=$VERSION"
5963

60-
sh "mvn clean install"
64+
sh "mvn clean install -DskipITs"
6165

6266
dir ("./charts/$APP_NAME") {
63-
sh "make tag"
67+
sh "make build tag"
6468
}
6569
sh "mvn deploy -DskipTests"
6670

67-
sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml"
71+
sh "export VERSION=$VERSION && skaffold build -f skaffold.yaml"
6872

69-
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
73+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$VERSION"
7074
}
7175
}
7276
}
@@ -77,7 +81,7 @@ pipeline {
7781
steps {
7882
container("maven") {
7983
dir ("./charts/$APP_NAME") {
80-
sh "jx step changelog --generate-yaml=false --version v\$(cat ../../VERSION)"
84+
sh "jx step changelog --generate-yaml=false --version v$VERSION"
8185

8286
// publish to github
8387
retry(5) {
@@ -109,3 +113,15 @@ pipeline {
109113
}
110114
}
111115
}
116+
117+
def jx_release_version() {
118+
container('maven') {
119+
return sh( script: "echo \$(jx-release-version)", returnStdout: true).trim()
120+
}
121+
}
122+
123+
def maven_project_version() {
124+
container('maven') {
125+
return sh( script: "echo \$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f pom.xml)", returnStdout: true).trim()
126+
}
127+
}

charts/activiti-cloud-notifications-graphql/Makefile

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ NAME := $(shell basename $(CURRENT))
44
ORG := $(or $(ORG),$(shell git remote -v | grep "(fetch)" | sed 's/.*\/\([^ ]*\)\/.*/\1/'))
55
OS := $(shell uname)
66
APP_NAME := $(or $(APP_NAME),$(NAME))
7-
#RELEASE_VERSION := $(or $(shell cat ../../VERSION),$(shell sed -n 's/^version: //p' Chart.yaml))
8-
RELEASE_VERSION := $(shell cat ../../VERSION)
7+
RELEASE_VERSION := $(or $(VERSION),$(shell cat ../../VERSION),$(shell sed -n 's/^version: //p' Chart.yaml))
98
RELEASE_ARTIFACT := $(or $(RELEASE_ARTIFACT),$(NAME))
109
RELASE_NAME := $(or $(RELEASE_NAME),$(NAME))
1110

@@ -34,14 +33,18 @@ clean:
3433
rm -rf charts
3534
rm -rf ${NAME}*.tgz
3635

37-
release: $(NAME)-$(RELEASE_VERSION).tgz
36+
release: package
3837
curl -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(RELEASE_VERSION).tgz" $(CHART_REPO)/api/charts
3938
rm -rf ${NAME}*.tgz%
4039

4140
$(NAME)-$(RELEASE_VERSION).tgz: build
4241
helm package .
4342

44-
github: $(NAME)-$(RELEASE_VERSION).tgz
43+
package: $(NAME)-$(RELEASE_VERSION).tgz
44+
45+
preview: version release
46+
47+
github: package
4548
$(eval GITHUB_CHARTS_DIR := $(shell basename $(GITHUB_CHARTS_REPO) .git))
4649
git clone -b "$(GITHUB_CHARTS_BRANCH)" "$(GITHUB_CHARTS_REPO)" $(GITHUB_CHARTS_DIR)
4750
cp "$(NAME)-$(RELEASE_VERSION).tgz" $(GITHUB_CHARTS_DIR)
@@ -54,18 +57,12 @@ github: $(NAME)-$(RELEASE_VERSION).tgz
5457
git push origin "$(GITHUB_CHARTS_BRANCH)"
5558
rm -rf $(GITHUB_CHARTS_DIR)
5659

57-
tag:
58-
ifeq ($(OS),Darwin)
59-
sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
60-
sed -i "" -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
61-
else ifeq ($(OS),Linux)
60+
version:
6261
sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
6362
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)/$(ORG)/$(APP_NAME)|" values.yaml
6463
sed -i -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
65-
else
66-
echo "platfrom $(OS) not supported to release from"
67-
exit -1
68-
endif
64+
65+
tag: version
6966
git add --all
7067
git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
7168
git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
@@ -76,13 +73,11 @@ updatebot/push-version:
7673
$(eval ACTIVITI_CLOUD_NOTIFICATIONS_SERVICE_VERSION=$(shell mvn help:evaluate -Dexpression=activiti-cloud-notifications-service-graphql.version -q -DforceStdout -f ../../pom.xml))
7774

7875
@echo Doing updatebot push-version.....
79-
cd ../../ && updatebot push-version --kind make ACTIVITI_CLOUD_NOTIFICATIONS_VERSION $(RELEASE_VERSION)
80-
cd ../../ && updatebot push-version --kind maven org.activiti.cloud.examples:activiti-cloud-notifications-graphql $(RELEASE_VERSION) org.activiti.cloud.notifications.graphql:activiti-cloud-notifications-graphql-dependencies $(ACTIVITI_CLOUD_NOTIFICATIONS_SERVICE_VERSION)
81-
82-
#cd ../../ && rm -rf .updatebot-repos/
83-
#sleep $$[ ( $$RANDOM % 10 ) + 1 ]s
84-
85-
#cd ../../ && updatebot push-version --kind make ACTIVITI_CLOUD_NOTIFICATIONS_VERSION $(RELEASE_VERSION)
86-
#cd ../../ && updatebot push-version --kind maven org.activiti.cloud.notifications.graphql:activiti-cloud-notifications-graphql-dependencies $(ACTIVITI_CLOUD_NOTIFICATIONS_SERVICE_VERSION)
87-
#cd ../../ && updatebot push-version --kind maven org.activiti.cloud.examples:activiti-cloud-notifications-graphql $(RELEASE_VERSION)
76+
for number in 1 2; do \
77+
cd ../../; \
78+
updatebot push-version --kind make ACTIVITI_CLOUD_NOTIFICATIONS_VERSION $(RELEASE_VERSION); \
79+
updatebot push-version --kind maven org.activiti.cloud.examples:activiti-cloud-notifications-graphql $(RELEASE_VERSION) org.activiti.cloud.notifications.graphql:activiti-cloud-notifications-graphql-dependencies $(ACTIVITI_CLOUD_NOTIFICATIONS_SERVICE_VERSION); \
80+
rm -rf .updatebot-repos/; \
81+
sleep $$[ ( $$RANDOM % 10 ) + 1 ]s; \
82+
done
8883

charts/activiti-cloud-notifications-graphql/templates/_helpers.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ Create a default service name.
2626
{{- $name := default (include "fullname" .) .Values.service.name -}}
2727
{{- printf "%s" $name | trunc 63 | trimSuffix "-" -}}
2828
{{- end -}}
29+
30+
31+
{{- define "notifications.rabbitmq-name" -}}
32+
{{- if .Values.global.rabbitmq.host.value }}
33+
{{ .Values.global.rabbitmq.host.value }}
34+
{{- else }}
35+
{{- printf "%s-%s" .Release.Name (.Values.rabbitmq.name | default "rabbitmq") -}}
36+
{{- end }}
37+
{{- end -}}
38+
Lines changed: 30 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,36 @@
11
{{- template "common.deployment" (list . "activiti.notifications.deployment") -}}
22
{{- define "activiti.notifications.deployment" -}}
33
spec:
4-
replicas: {{ .Values.replicaCount }}
54
template:
65
spec:
7-
{{- if include "common.registry-pull-secrets" . }}
8-
imagePullSecrets:
9-
{{- include "common.registry-pull-secrets" . | indent 6 }}
10-
{{- end }}
11-
containers:
12-
- name: {{ .Chart.Name }}
13-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
14-
imagePullPolicy: {{ .Values.image.pullPolicy }}
15-
env:
16-
- name: JAVA_OPTS
17-
value: "-Xmx{{ .Values.javaOpts.xmx }} -Xms{{ .Values.javaOpts.xms }} {{ .Values.javaOpts.other}}"
18-
- name: SPRING_APPLICATION_NAME
19-
value: {{ template "servicename" . }}
20-
- name: SPRING_RABBITMQ_HOST
21-
{{- if .Values.global.rabbitmq.host.value }}
22-
value: {{ .Values.global.rabbitmq.host.value | quote }}
23-
{{- else }}
24-
value: "{{ .Release.Name }}-rabbitmq"
25-
{{- end }}
26-
- name: SPRING_RABBITMQ_USERNAME
27-
value: {{ .Values.global.rabbitmq.username.value }}
28-
- name: SPRING_RABBITMQ_PASSWORD
29-
value: {{ .Values.global.rabbitmq.password.value }}
30-
{{- if include "common.keycloak-enabled" $ }}
31-
- name: ACT_KEYCLOAK_URL
32-
value: {{ include "common.keycloak-url" $ | quote }}
33-
{{- end }}
34-
{{- if include "common.keycloak-realm" . }}
35-
- name: ACT_KEYCLOAK_REALM
36-
value: {{ include "common.keycloak-realm" . | quote }}
37-
{{- end }}
38-
{{- if include "common.keycloak-resource" . }}
39-
- name: ACT_KEYCLOAK_RESOURCE
40-
value: {{ include "common.keycloak-resource" . | quote }}
41-
{{- end }}
42-
{{- if .Values.postgres.enabled }}
43-
- name: SPRING_DATASOURCE_URL
44-
{{- if .Values.postgres.uri }}
45-
value: {{ .Values.postgres.uri | quote }}
46-
{{- else }}
47-
value: "jdbc:postgresql://{{ .Release.Name }}-{{ .Values.postgres.name }}:{{ .Values.postgres.port }}/postgres"
48-
{{- end }}
49-
- name: SPRING_DATASOURCE_DRIVER_CLASS_NAME
50-
value: {{ default "org.postgresql.Driver" .Values.postgres.driver | quote }}
51-
- name: SPRING_DATASOURCE_USERNAME
52-
value: {{ default "postgres" .Values.postgres.username | quote }}
53-
- name: SPRING_DATASOURCE_PASSWORD
54-
{{- if .Values.postgres.password }}
55-
value: {{ .Values.db.password | quote}}
56-
{{- else }}
57-
valueFrom:
58-
secretKeyRef:
59-
name: {{ .Release.Name }}-{{ .Values.postgres.name }}
60-
key: postgresql-password
61-
{{- end }}
62-
- name: SPRING_JPA_DATABASE_PLATFORM
63-
value: {{ default "org.hibernate.dialect.PostgreSQLDialect" .Values.postgres.platform | quote }}
64-
- name: SPRING_JPA_GENERATE_DDL
65-
value: {{ default "true" .Values.postgres.generateDdl | quote }}
66-
- name: SPRING_JPA_HIBERNATE_DDL_AUTO
67-
value: {{ default "update" .Values.postgres.ddlAuto | quote}}
68-
{{- else }}
69-
{{- if .Values.db.uri }}
70-
- name: SPRING_DATASOURCE_URL
71-
value: {{ .Values.db.uri | quote }}
72-
{{- end }}
73-
{{- if .Values.db.driver }}
74-
- name: SPRING_DATASOURCE_DRIVER_CLASS_NAME
75-
value: {{ .Values.db.driver | quote }}
76-
{{- end }}
77-
{{- if .Values.db.username }}
78-
- name: SPRING_DATASOURCE_USERNAME
79-
value: {{ .Values.db.username | quote }}
80-
{{- end }}
81-
{{- if .Values.db.password }}
82-
- name: SPRING_DATASOURCE_PASSWORD
83-
value: {{ .Values.db.password | quote}}
84-
{{- end }}
85-
{{- if .Values.db.platform }}
86-
- name: SPRING_JPA_DATABASE_PLATFORM
87-
value: {{ .Values.db.platform | quote}}
88-
{{- end }}
89-
{{- if .Values.db.generateDdl }}
90-
- name: SPRING_JPA_GENERATE_DDL
91-
value: {{ .Values.db.generateDdl | quote }}
92-
{{- end }}
93-
{{- if .Values.db.ddlAuto }}
94-
- name: SPRING_JPA_HIBERNATE_DDL_AUTO
95-
value: {{ default "update" .Values.db.ddlAuto | quote }}
96-
{{- end }}
97-
{{- end }}
98-
{{- if include "common.ingress-path" . }}
99-
- name: SERVER_SERVLET_CONTEXTPATH
100-
value: {{ include "common.ingress-path" . | quote }}
101-
{{- end }}
102-
- name: ACT_CLOUD_CONFIG_SERVER_ENABLED
103-
value: "false"
104-
{{ include "common.extra-env" . | indent 8 }}
105-
ports:
106-
- containerPort: {{ .Values.service.internalPort }}
107-
livenessProbe:
108-
httpGet:
109-
path: {{ tpl .Values.probePath . }}
110-
port: {{ .Values.service.internalPort }}
111-
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
112-
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
113-
successThreshold: {{ .Values.livenessProbe.successThreshold }}
114-
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
115-
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
116-
readinessProbe:
117-
httpGet:
118-
path: {{ tpl .Values.probePath . }}
119-
port: {{ .Values.service.internalPort }}
120-
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
121-
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
122-
successThreshold: {{ .Values.readinessProbe.successThreshold }}
123-
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
124-
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
125-
resources:
126-
{{ toYaml .Values.resources | indent 12 }}
127-
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
6+
initContainers:
7+
{{- if .Values.postgres.enabled }}
8+
- name: wait-for-postgresql
9+
image: {{ .Values.init.container.image | quote }}
10+
imagePullPolicy: {{ .Values.init.container.imagePullPolicy }}
11+
command:
12+
- sh
13+
- -c
14+
- |
15+
until printf "." && nc -z -w 2 {{ .Release.Name }}-{{ .Values.postgres.name }} {{ .Values.postgres.port }}; do
16+
sleep 2;
17+
done;
18+
echo 'PostgreSQL OK ✓'
19+
{{- end }}
20+
{{- if .Values.rabbitmq.enabled }}
21+
- name: wait-for-rabbitmq
22+
image: {{ .Values.init.container.image | quote }}
23+
imagePullPolicy: {{ .Values.init.container.imagePullPolicy }}
24+
command:
25+
- sh
26+
- -c
27+
- |
28+
until printf "." && nc -z -w 2 {{ include "notifications.rabbitmq-name" . }} {{ .Values.rabbitmq.port | default 5672 }}; do
29+
sleep 2;
30+
done;
31+
echo 'RabbitMq OK ✓'
32+
{{- end }}
33+
{{- if .Values.extraInitContainers }}
34+
{{ tpl .Values.extraInitContainers . | indent 8 }}
35+
{{- end }}
12836
{{- end -}}

charts/activiti-cloud-notifications-graphql/values.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ postgres:
4040
generateDdl: "false" # default to disable generating Ddl schema
4141
ddlAuto: "none" # default to disable ddl update
4242

43+
rabbitmq:
44+
enabled: true
45+
name: "rabbitmq"
46+
port: 5672
47+
4348
javaOpts:
4449
xmx: 2048m
4550
xms: 512m
4651
other: -XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90
4752

4853
## Allows the specification of additional environment variables
4954
extraEnv: |
55+
{{- if include "common.ingress-path" . }}
56+
- name: SERVER_SERVLET_CONTEXTPATH
57+
value: {{ include "common.ingress-path" . | quote }}
58+
{{- end }}
5059
# - name: ACT_KEYCLOAK_URL
5160
# valueFrom:
5261
# configMapKeyRef:
@@ -60,6 +69,11 @@ image:
6069
tag: 7.0.0.SR1
6170
pullPolicy: IfNotPresent
6271

72+
init:
73+
container:
74+
image: alpine:3.8
75+
imagePullPolicy: IfNotPresent
76+
6377
service:
6478
name: notifications
6579
type: ClusterIP
@@ -122,3 +136,10 @@ ingress:
122136
nginx.ingress.kubernetes.io/session-cookie-hash: "md5"
123137
nginx.ingress.kubernetes.io/session-cookie-path: '{{ include "common.ingress-path" . }}'
124138

139+
## Add additional volumes and mounts
140+
extraVolumes: |
141+
extraVolumeMounts: |
142+
143+
## Additional init containers, e. g. to wait for a db or SSO
144+
extraInitContainers: |
145+

maven-dind.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ spec:
1919
image: docker:18.06.1-dind
2020
imagePullPolicy: IfNotPresent
2121
args:
22+
- --registry-mirror=http://jenkins-x-docker-registry:5000
2223
- --registry-mirror=https://mirror.gcr.io
23-
- --insecure-registry=10.7.251.133:5000
24+
- --insecure-registry=jenkins-x-docker-registry:5000
2425
workingDir: /home/jenkins
2526
securityContext:
2627
privileged: true

0 commit comments

Comments
 (0)