Skip to content

Commit a025587

Browse files
author
Igor Pavlenko
committed
#1 Implement ability to configure spring-based docker containers
1 parent 6f489bb commit a025587

File tree

17 files changed

+199
-17
lines changed

17 files changed

+199
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ggcode_modules/
33

44
# Expamples target directory
5-
examples/
5+
/app/
66

77
# Lock file
88
ggcode-info.lock

actions/generate.luau

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local postgres = require('compose/postgres')
44
local pgadmin = require('compose/pgadmin')
55
local keycloak = require('compose/keycloak')
66
local kcadm = require('compose/kcadm')
7+
local app = require('compose/app')
78

89
local datasource_keycloak = {
910
uri = 'jdbc:postgresql://env_postgres:5432/keycloak',
@@ -18,7 +19,7 @@ local datasource_app = {
1819
}
1920

2021
ggcode.generate "@/compose" {
21-
target = '@examples',
22+
target = '@app',
2223
variables = {
2324
config = {
2425
include = {
@@ -30,13 +31,14 @@ ggcode.generate "@/compose" {
3031
{ path = "compose/env/env_swagger_ui.compose.yaml" },
3132
{ path = "compose/env/env_keycloak.compose.yaml" },
3233
{ path = "compose/env/env_kcadm.compose.yaml" },
34+
{ path = "compose/app/app_assembly_web.compose.yaml" },
3335
}
3436
}
3537
}
3638
}
3739

3840
ggcode.generate "@/haproxy" {
39-
target = '@examples',
41+
target = '@app',
4042
variables = haproxy.build {
4143
haproxy.Route:from_arrow('http://kafka-ui.local.example.com', 'http://env_kafka_ui:8080');
4244
haproxy.Route:from_arrow('http://pgadmin.local.example.com', 'http://env_pgadmin:80');
@@ -46,53 +48,56 @@ ggcode.generate "@/haproxy" {
4648
haproxy.Route:from_uri_string('http://api.local.example.com')
4749
:with_name('api')
4850
:with_proxies({
51+
haproxy.Proxy:from_path_string('/api/assembly_web')
52+
:with_cors('*')
53+
:with_server(haproxy.Server:from_uri_string('http://app_assembly_web:8080'):with_optional(true));
4954
haproxy.Proxy:from_path_string('/api/service_catalog')
5055
:with_cors('*')
51-
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8080'):with_optional(true));
56+
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8081'):with_optional(true));
5257
haproxy.Proxy:from_path_string('/api/service_customers')
5358
:with_cors('*')
54-
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8081'):with_optional(true));
59+
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8082'):with_optional(true));
5560
haproxy.Proxy:from_path_string('/api/service_basket')
5661
:with_cors('*')
57-
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8082'):with_optional(true));
62+
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8083'):with_optional(true));
5863
haproxy.Proxy:from_path_string('/api/service_payments')
5964
:with_cors('*')
60-
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8083'):with_optional(true));
65+
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8084'):with_optional(true));
6166
haproxy.Proxy:from_path_string('/api/service_events')
6267
:with_cors('*')
63-
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8084'):with_optional(true));
68+
:with_server(haproxy.Server:from_uri_string('http://host.docker.internal:8085'):with_optional(true));
6469
});
6570
}
6671
}
6772

68-
ggcode.generate "@/kafka" { target = '@examples' }
69-
ggcode.generate "@/kafka_ui" { target = '@examples' }
73+
ggcode.generate "@/kafka" { target = '@app' }
74+
ggcode.generate "@/kafka_ui" { target = '@app' }
7075

7176
ggcode.generate "@/pgadmin" {
72-
target = '@examples',
77+
target = '@app',
7378
variables = pgadmin.build {
7479
pgadmin.Server:from_datasource(datasource_keycloak),
7580
pgadmin.Server:from_datasource(datasource_app),
7681
}
7782
}
7883

7984
ggcode.generate "@/postgres" {
80-
target = '@examples',
85+
target = '@app',
8186
variables = postgres.build {
8287
postgres.Database:from_datasource(datasource_keycloak),
8388
postgres.Database:from_datasource(datasource_app),
8489
}
8590
}
8691

8792
ggcode.generate "@/keycloak" {
88-
target = '@examples',
93+
target = '@app',
8994
variables = keycloak.build {
9095
keycloak.Manifest:new():with_datasource(datasource_keycloak),
9196
}
9297
}
9398

9499
ggcode.generate "@/kcadm" {
95-
target = '@examples',
100+
target = '@app',
96101
variables = kcadm.build {
97102
kcadm.Realm:from('application'),
98103

@@ -121,10 +126,11 @@ ggcode.generate "@/kcadm" {
121126
}
122127

123128
ggcode.generate "@/swagger_ui" {
124-
target = '@examples',
129+
target = '@app',
125130
variables = {
126131
config = {
127132
urls = {
133+
{ name = "Assembly Web", url = "http://api.local.example.com/api/assembly_web/v3/api-docs" },
128134
{ name = "Service Catalogue", url = "http://api.local.example.com/api/service_catalog/v3/api-docs" },
129135
{ name = "Service Customers", url = "http://api.local.example.com/api/service_customers/v3/api-docs" },
130136
{ name = "Service Basket", url = "http://api.local.example.com/api/service_basket/v3/api-docs" },
@@ -134,3 +140,19 @@ ggcode.generate "@/swagger_ui" {
134140
}
135141
}
136142
}
143+
144+
local service_assembly_web =
145+
146+
ggcode.generate "@/app" {
147+
target = '@app',
148+
variables = app.Service
149+
:from('app_assembly_web', 'example/assembly_web:1.0-SNAPSHOT')
150+
:with_depends_on('env_kafka')
151+
:with_depends_on('env_postgres')
152+
:with_depends_on('env_keycloak')
153+
:with_spring_datasource(datasource_app)
154+
:with_env_variable('SPRING_KAFKA_BOOTSTRAP_SERVERS', 'env_kafka:29092')
155+
:with_link('env_haproxy:auth.local.example.com')
156+
-- :with_env_variable('SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI', 'http://env_keycloak:8080/auth/realms/application')
157+
:unwrap()
158+
}

ggcode-info.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ actions:
77
- name: test/pgadmin
88
path: actions/test/pgadmin.luau
99
scrolls:
10+
- name: app
11+
path: scrolls/app
1012
- name: compose
1113
path: scrolls/compose
1214
- name: haproxy
@@ -29,5 +31,5 @@ repositories:
2931
- name: core
3032
uri: [email protected]:ntr1x/ggcode-repo-core.git
3133
targets:
32-
- name: '@examples'
33-
path: examples
34+
- name: '@app'
35+
path: app

lib/compose/app.luau

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local Service = require('compose/app/Service')
2+
3+
return {
4+
Service = Service,
5+
}

lib/compose/app/Name.luau

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local Meta = require('core/Meta')
2+
3+
local Name = {
4+
__type = 'Name',
5+
name = nil,
6+
}
7+
8+
function Name:new(o)
9+
o = o or {}
10+
setmetatable(o, self)
11+
self.__index = self
12+
return o
13+
end
14+
15+
function Name:from(name: string)
16+
return Name:new({
17+
name = name,
18+
})
19+
end
20+
21+
function Name:unwrap()
22+
return {
23+
name = self.name,
24+
}
25+
end
26+
27+
return Name

lib/compose/app/Service.luau

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
local Meta = require('core/Meta')
2+
3+
local Service = {
4+
__type = 'Service',
5+
name = nil,
6+
image = nil,
7+
environment = nil,
8+
depends_on = nil,
9+
links = nil,
10+
}
11+
12+
function Service:new(o)
13+
o = o or {}
14+
setmetatable(o, self)
15+
self.__index = self
16+
return o
17+
end
18+
19+
function Service:from(name: string, image: string, environment: table)
20+
return Service:new({
21+
name = name,
22+
image = image,
23+
depends_on = Meta:array {},
24+
links = Meta:array {},
25+
environment = environment or Meta:table {},
26+
})
27+
end
28+
29+
function Service:with_env_variable(name: string, value: string)
30+
self.environment[name] = value
31+
return self
32+
end
33+
34+
function Service:with_spring_datasource(datasource: table)
35+
self.environment.SPRING_DATASOURCE_URL = datasource.uri
36+
self.environment.SPRING_DATASOURCE_USERNAME = datasource.username
37+
self.environment.SPRING_DATASOURCE_PASSWORD = datasource.password
38+
return self
39+
end
40+
41+
function Service:with_env_variables(environment: table)
42+
environment = environment or Meta:table {}
43+
44+
for name, value in environment do
45+
self.environment[name] = value
46+
end
47+
48+
return self
49+
end
50+
51+
function Service:with_depends_on(name: string)
52+
self.depends_on[#self.depends_on + 1] = name
53+
return self
54+
end
55+
56+
function Service:with_link(link: string)
57+
self.links[#self.links + 1] = link
58+
return self
59+
end
60+
61+
function Service:unwrap_depends_on()
62+
if #self.depends_on > 0 then
63+
return self.depends_on
64+
end
65+
66+
return nil
67+
end
68+
69+
function Service:unwrap_links()
70+
if #self.links > 0 then
71+
return self.links
72+
end
73+
74+
return nil
75+
end
76+
77+
function Service:unwrap()
78+
return {
79+
service = {
80+
name = self.name,
81+
manifest = {
82+
image = self.image,
83+
environment = self.environment,
84+
depends_on = self:unwrap_depends_on(),
85+
links = self:unwrap_links()
86+
}
87+
}
88+
}
89+
end
90+
91+
return Service

scrolls/app/templates/!trace.luau

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- print(yaml:stringify({
2+
-- bundle = bundle,
3+
-- service = service,
4+
-- volumes = volumes,
5+
-- }))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local config = {
2+
services = {
3+
[service.name] = service.manifest
4+
},
5+
volumes = volumes,
6+
}
7+
8+
template:println(yaml:stringify(config))

scrolls/app/variables/bundle.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: app

scrolls/app/variables/service.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: app_service_api
2+
manifest:
3+
image: example/service_api:1.0-SNAPSHOT
4+
restart: unless-stopped
5+
deploy:
6+
resources:
7+
limits:
8+
memory: 600M
9+
profiles:
10+
- app
11+
environment:
12+
JAVA_OPTS: "-Xmx512m -Xms256m"
13+
networks:
14+
default: {}

scrolls/haproxy/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ manifest:
1313
- "host.docker.internal:host-gateway"
1414
profiles:
1515
- env
16+
- app
1617
ports:
1718
- "80:80"
1819
- "8404:8404"

scrolls/kafka/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ manifest:
1010
- env_kafka:/bitnami/kafka
1111
profiles:
1212
- env
13+
- app
1314
ports:
1415
- "9092:9092"
1516
- "29092:29092"

scrolls/kafka_ui/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ manifest:
1010
- env_kafka
1111
profiles:
1212
- env
13+
- admin
1314
environment:
1415
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: env_kafka:29092
1516
KAFKA_CLUSTERS_0_NAME: local

scrolls/keycloak/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ manifest:
1313
- env_postgres
1414
profiles:
1515
- env
16+
- app
1617
environment:
1718
KEYCLOAK_ADMIN: admin
1819
KEYCLOAK_ADMIN_PASSWORD: GfhjkmRfhjkm1

scrolls/pgadmin/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ manifest:
1212
- env_postgres
1313
profiles:
1414
- env
15+
- admin
1516
environment:
1617
PGADMIN_DEFAULT_EMAIL: [email protected]
1718
PGADMIN_DEFAULT_PASSWORD: admin

scrolls/postgres/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ manifest:
1111
- env_postgres:/var/lib/postgresql/data
1212
profiles:
1313
- env
14+
- app
1415
ports:
1516
- "5432:5432"
1617
environment:

scrolls/swagger_ui/variables/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ manifest:
1010
- ../../config/env/env_swagger_ui/swagger-config.json:/usr/share/nginx/html/swagger-config.json
1111
profiles:
1212
- env
13+
- app
1314
environment:
1415
CONFIG_URL: swagger-config.json
1516
URL: ""

0 commit comments

Comments
 (0)