Skip to content

Commit 2774d89

Browse files
author
Araf Karsh Hamid
committed
Added Auto Generation of ConfigMap from App Properties for Kubernetes
1 parent 726ffdc commit 2774d89

24 files changed

+769
-36
lines changed

compile

+21-25
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,32 @@ then
4040
echo "---------------------------------------------------------------------------------------"
4141
echo "2.1 Compiling Service > $ORG/$SERVICE :: SUCCESS"
4242
echo "---------------------------------------------------------------------------------------"
43+
4344
echo "2.2 Copy the Fat and Thin jar files and the libs to the Docker Directory (src/docker)"
4445
cp target/*service*-spring-boot.jar src/docker/Input/$CONTAINER-spring-boot.jar
45-
#cp target/*service*?.?.?.jar src/docker/Input/$CONTAINER-thin.jar
46-
#cp target/libs/* src/docker/libs/
46+
4747
echo "2.3 Copy the application.properties File to the Docker Directory (src/docker)"
48-
cp src/main/resources/application.properties src/docker/Input
49-
cp src/main/resources/application-dev.properties src/docker/Input
50-
cp src/main/resources/application-staging.properties src/docker/Input
51-
cp src/main/resources/application-prod.properties src/docker/Input
52-
echo "2.4 Copy the application.properties Files to config directory."
53-
cp src/main/resources/application.properties config
54-
cp src/main/resources/application-dev.properties config
55-
cp src/main/resources/application-staging.properties config
56-
cp src/main/resources/application-prod.properties config
57-
echo "2.5 Copy the logback-spring xml Files to config directory."
58-
cp src/main/resources/logback-spring.xml config
59-
cp src/main/resources/logback-spring-scope.xml config
60-
cp src/main/resources/logback-spring-appenders-json.xml config
61-
cp src/main/resources/logback-spring-appenders-text.xml config
62-
cp src/main/resources/logback-spring-appenders-json-logstash.xml config
63-
echo "2.6 Copy the logback-spring xml Files to Docker directory src/docker/"
64-
cp src/main/resources/logback-spring.xml src/docker/Input
65-
cp src/main/resources/logback-spring-scope.xml src/docker/Input
66-
cp src/main/resources/logback-spring-appenders-text.xml src/docker/Input
67-
cp src/main/resources/logback-spring-appenders-json.xml src/docker/Input
68-
cp src/main/resources/logback-spring-appenders-json-logstash.xml src/docker/Input
48+
cp src/main/resources/application*properties src/docker/Input
49+
50+
echo "2.4 Copy the application.properties File to the Docker Directory (src/docker)"
51+
convert4ConfigMap src/main/resources/application.properties src/kubernetes/Package/default/application.properties
52+
convert4ConfigMap src/main/resources/application-dev.properties src/kubernetes/Package/dev/application-dev.properties
53+
convert4ConfigMap src/main/resources/application-staging.properties src/kubernetes/Package/staging/application-staging.properties
54+
convert4ConfigMap src/main/resources/application-prod.properties src/kubernetes/Package/prod/application-prod.properties
55+
56+
echo "2.5 Copy the application.properties Files to config directory."
57+
cp src/main/resources/application*properties config
58+
59+
echo "2.6 Copy the logback-spring xml Files to config directory."
60+
cp src/main/resources/logback-spring*xml config
61+
62+
echo "2.7 Copy the logback-spring xml Files to Docker directory src/docker/"
63+
cp src/main/resources/logback-spring*xml src/docker/Input
64+
6965
echo "---------------------------------------------------------------------------------------"
70-
echo "2.7. Building the Container for $ORG/$SERVICE Service ..... "
66+
echo "2.8. Building the Container for $ORG/$SERVICE Service ..... "
7167
echo "---------------------------------------------------------------------------------------"
72-
echo "2.7.1 Docker Build Process Disabled.... Run the build command separately"
68+
echo "2.8.1 Docker Build Process Disabled.... Run the build/buildx command separately"
7369
#build
7470
echo "---------------------------------------------------------------------------------------"
7571
echo "3. $SERVICE Microservice Build Process Completed Successfully! ........... "

config/application.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# =======================================================================
22
# MS-Vanilla Service Properties
33
# =======================================================================
4-
build.number=208
5-
build.date=Tue Jan 21 07:07:30 IST 2025
4+
build.number=209
5+
build.date=Tue Jan 21 08:42:40 IST 2025
66
# ------------------------------------------------------------------------
77
# Spring Profile
88
# ------------------------------------------------------------------------

convert4ConfigMap

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# -------------------------------------------------------------------------------------------
3+
# @author: Araf Karsh Hamid
4+
# -------------------------------------------------------------------------------------------
5+
# Making Application Properties file Compatible for Kubernetes
6+
# ===========================================================================================
7+
#echo "Converting Application Properties to Support Config Map inputs"
8+
9+
# Process the input file and remove lines starting with #
10+
echo " Removing all lines starts with # from $1 to $2"
11+
grep -vE '^#' "$1" > "$2"

src/docker/Input/application.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# =======================================================================
22
# MS-Vanilla Service Properties
33
# =======================================================================
4-
build.number=208
5-
build.date=Tue Jan 21 07:07:30 IST 2025
4+
build.number=209
5+
build.date=Tue Jan 21 08:42:40 IST 2025
66
# ------------------------------------------------------------------------
77
# Spring Profile
88
# ------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
build.number=209
2+
build.date=Tue Jan 21 08:42:40 IST 2025
3+
spring.profiles.default=dev
4+
service.org=arafkarsh
5+
service.name=MS-Vanilla
6+
service.api.name=ms-vanilla
7+
service.api.prefix=api
8+
service.api.version=v1
9+
service.api.error.prefix=13
10+
service.container=ms-vanilla-service
11+
service.api.repository=https://github.com/arafkarsh/ms-springboot-334-vanilla
12+
service.api.path=/${service.api.name}/${service.api.prefix}/${service.api.version}
13+
service.url=http://www.arafkarsh.com/
14+
service.license=Apache 2 License
15+
service.license.url=https://github.com/arafkarsh/ms-springboot-334-vanilla?tab=Apache-2.0-1-ov-file
16+
server.port=9334
17+
server.version=0.3.4
18+
server.restart=false
19+
server.leak.test=3
20+
server.resources.url=${service.url}${service.api.path}
21+
server.api.url.print=true
22+
server.crypto.public.key=publicKey.pem
23+
server.crypto.private.key=privateKey.pem
24+
server.token.issuer=${service.org}
25+
server.token.type=1
26+
server.token.test=true
27+
server.token.auth.expiry=600000
28+
server.token.refresh.expiry=3600000
29+
server.token.key=<([1234567890SecretKey!!To??Encrypt##Data@12345%6790])>
30+
server.secure.data.key=<([1234567890SecretKEY!!TO??Encrypt##DATA@12345%6790])>
31+
server.keycloak.url=http://localhost:8080/realms/Fusion-Air/protocol/openid-connect/token
32+
server.keycloak.certs=http://localhost:8080/realms/Fusion-Air/protocol/openid-connect/certs
33+
server.keycloak.clientId=fusion-air-user-service
34+
server.keycloak.secret=2AGe7XxP8evCmhdjD3cmgpE23y0g6PGU
35+
server.keycloak.grantType=password
36+
server.keycloak.publicKey=publicKey.KeyCloak.pem
37+
server.keycloak.issuer=http://localhost:8080/realms/Fusion-Air
38+
server.keycloak.enabled=false
39+
server.host=localhost
40+
server.host.dev=http://localhost:${server.port}
41+
server.host.dev.desc=Development Server
42+
server.host.uat=https://uat.${service.org}.com
43+
server.host.uat.desc=UAT Server
44+
server.host.prod=https://prod.${service.org}.com
45+
server.host.prod.desc=Production Server
46+
server.error.whitelabel.enabled=true
47+
server.vulnerability.demos.allowed=false
48+
spring.codec.max-in-memory-size=3MB
49+
app.property.product=fusion.air.product
50+
app.property.product.list=/create, /status, /all/secured, /search/product, /search/price, /search/active, /deactivate, /activate, /update, /update/price, /update/details, /delete
51+
app.property.list=element1, element2, element3
52+
app.property.map={key1:'val1', key2 : 'val2', key3 : 'val3'}
53+
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
54+
logging.level.org.springframework.boot.web.servlet=INFO
55+
logging.level.org.springframework.web.servlet.DispatcherServlet=INFO
56+
logging.level.org.springframework.security.web.FilterChainProxy=INFO
57+
logging.level.web=INFO
58+
logging.level.sql=INFO
59+
logging.level.tomcat=INFO
60+
logging.level.root=INFO
61+
logging.config=classpath:logback-spring.xml
62+
logging.format=plain
63+
logging.path=/tmp/logs/${service.api.name}
64+
logging.file.name=${service.api.name}.v${server.version}
65+
logging.pattern.rolling-file-name=${logging.path}/${logging.file.name}-%d{yyyy-MM-dd}-%i
66+
logging.file.max-size=10MB
67+
logging.file.max-history=100
68+
logging.file.total-size-cap=3GB
69+
springdoc.show-actuator=true
70+
management.endpoints.web.exposure.include=health,metrics,prometheus,info
71+
management.endpoint.health.enabled=true
72+
management.endpoint.metrics.enabled=true
73+
management.endpoint.prometheus.enabled=true
74+
management.metrics.export.prometheus.enabled=true
75+
management.metrics.enable.jvm=false
76+
management.metrics.enable.jvm.gc=false
77+
management.metrics.enable.datasource=false
78+
otel.propagators=tracecontext
79+
otel.resource.attributes.deployment.environment=dev
80+
otel.resource.attributes.service.name=ms-vanilla
81+
otel.resource.attributes.service.namespace=shopping
82+
otel.javaagent.debug=true
83+
otel.service.name=${service.container}
84+
otel.exporter.otlp.endpoint=http://localhost:4318
85+
otel.traces.exporter=none
86+
otel.metrics.exporter=none
87+
otel.logs.exporter=none
88+
otel.instrumentation.common.default-enabled=false
89+
otel.instrumentation.jdbc.enabled=false
90+
otel.instrumentation.logback-mdc.enabled=true
91+
otel.instrumentation.spring-web.enabled=true
92+
otel.instrumentation.spring-webmvc.enabled=true
93+
otel.instrumentation.micrometer.enabled=true
94+
otel.instrumentation.kafka.enabled=false
95+
otel.instrumentation.mongo.enabled=false
96+
jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}
97+
jasypt.encryptor.algorithm=PBEWithHmacSHA512AndAES_256
98+
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.RandomIvGenerator
99+
jasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator
100+
db.server=mem
101+
db.port=5432
102+
db.name=ms_cache
103+
db.schema=ms_schema
104+
db.vendor=H2
105+
spring.datasource.url=jdbc:h2:${db.server}:${db.name};DB_CLOSE_ON_EXIT=FALSE
106+
spring.datasource.driverClassName=org.h2.Driver
107+
spring.datasource.username=sa
108+
spring.datasource.password=ENC(lA6JCEpK7+wuHDpB1A41DOUfn6L74DQxaazXLTjyQHY5/X6CONfUEyDt6erWifrN)
109+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
110+
spring.datasource.hikari.connection-test-query=SELECT 1
111+
spring.jpa.show-sql=true
112+
spring.jpa.defer-datasource-initialization=true
113+
spring.jpa.hibernate.ddl-auto=create-drop
114+
spring.jpa.properties.hibernate.format_sql=true
115+
spring.jpa.properties.hibernate.validator.apply_to_ddl=false
116+
remote.host=127.0.0.1
117+
remote.port=8080
118+
remote.protocol=http
119+
springdoc.api-docs.path=${service.api.path}
120+
springdoc.swagger-ui.path=${service.api.path}/swagger-ui.html
121+
springdoc.swagger-ui.tryItOutEnabled=true
122+
springdoc.swagger-ui.filter=true
123+
springdoc.swagger-ui.use-root-path=true
124+
springdoc.swagger-ui.disable-swagger-default-url=true
125+
server.forward-headers-strategy=framework
126+
springdoc.cache.disabled=true
127+
springdoc.writer-with-default-pretty-printer=true
128+
springdoc.api-docs.enabled=true
129+
springdoc.swagger-ui.operationsSorter=method
130+
springdoc.swagger-ui.tagsSorter=alpha
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
configMapGenerator:
5+
- name: vanilla-configmap-default
6+
files:
7+
- application.properties
8+
9+
generatorOptions:
10+
disableNameSuffixHash: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server.port=9334
2+
logging.level.root=INFO
3+
db.server=mem
4+
db.port=5432
5+
db.name=ms_vanilla_334
6+
db.schema=ms_schema
7+
db.vendor=H2
8+
spring.datasource.url=jdbc:h2:${db.server}:${db.name};DB_CLOSE_ON_EXIT=FALSE
9+
spring.datasource.driverClassName=org.h2.Driver
10+
spring.datasource.username=sa
11+
spring.datasource.password=ENC(lA6JCEpK7+wuHDpB1A41DOUfn6L74DQxaazXLTjyQHY5/X6CONfUEyDt6erWifrN)
12+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
13+
spring.h2.console.enabled=true
14+
spring.h2.console.path=/h2-ui
15+
spring.h2.console.settings.trace=false
16+
spring.h2.console.settings.web-allow-others=false
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
configMapGenerator:
5+
- name: vanilla-configmap-dev
6+
files:
7+
- application-dev.properties
8+
9+
generatorOptions:
10+
disableNameSuffixHash: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server.port=9334
2+
logging.level.root=INFO
3+
db.server=localhost
4+
db.port=5433
5+
db.name=ms_vanilla_334
6+
db.schema=ms_schema
7+
db.vendor=PostgreSQL
8+
spring.datasource.url=jdbc:postgresql://${db.server}:${db.port}/${db.name}
9+
spring.datasource.driverClassName=org.postgresql.ds.PGSimpleDataSource
10+
spring.datasource.username=msadm
11+
spring.datasource.password=ENC(In0ZYcoLjwe2OzzaWZ07BMoFHL8yvo4KQ/3ABAbzSKJuUVEu5hYycNGWB66Xswju)
12+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
13+
spring.datasource.hikari.connection-test-query=SELECT 1
14+
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
configMapGenerator:
5+
- name: vanilla-configmap-prod
6+
files:
7+
- application-prod.properties
8+
9+
generatorOptions:
10+
disableNameSuffixHash: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server.port=9334
2+
logging.level.root=INFO
3+
db.server=localhost
4+
db.port=5433
5+
db.name=ms_vanilla_334
6+
db.schema=ms_schema
7+
db.vendor=PostgreSQL
8+
spring.datasource.url=jdbc:postgresql://${db.server}:${db.port}/${db.name}
9+
spring.datasource.driverClassName=org.postgresql.ds.PGSimpleDataSource
10+
spring.datasource.username=msadm
11+
spring.datasource.password=ENC(In0ZYcoLjwe2OzzaWZ07BMoFHL8yvo4KQ/3ABAbzSKJuUVEu5hYycNGWB66Xswju)
12+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
13+
spring.datasource.hikari.connection-test-query=SELECT 1
14+
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
configMapGenerator:
5+
- name: vanilla-configmap-staging
6+
files:
7+
- application-staging.properties
8+
9+
generatorOptions:
10+
disableNameSuffixHash: true

0 commit comments

Comments
 (0)