Skip to content

Commit 8b8b5a6

Browse files
author
Adnane Miliari
committed
🗄️initialize database schemas and configure multi-architecture support for Docker builds
1 parent fe875b6 commit 8b8b5a6

File tree

31 files changed

+336
-42
lines changed

31 files changed

+336
-42
lines changed

‎apiKey-manager/pom.xml‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<version>1.0-SNAPSHOT</version>
88
</parent>
99

10-
<artifactId>apiKey-manager</artifactId>
10+
<artifactId>apikey-manager</artifactId>
1111

1212
<properties>
1313
<maven.compiler.source>17</maven.compiler.source>
@@ -64,4 +64,52 @@
6464
</plugin>
6565
</plugins>
6666
</build>
67+
68+
<profiles>
69+
<profile>
70+
<id>jib-build-push-image-to-local</id>
71+
<activation>
72+
<activeByDefault>false</activeByDefault>
73+
</activation>
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>com.google.cloud.tools</groupId>
78+
<artifactId>jib-maven-plugin</artifactId>
79+
<version>${jib.maven.plugin.version}</version>
80+
<configuration>
81+
<from>
82+
<image>openjdk:17</image>
83+
<platforms>
84+
<platform>
85+
<architecture>arm64</architecture>
86+
<os>linux</os>
87+
</platform>
88+
</platforms>
89+
</from>
90+
<to>
91+
<image>miliariadnane/apikeymanager</image>
92+
<tags>
93+
<tag>latest</tag>
94+
</tags>
95+
</to>
96+
<container>
97+
<jvmFlags>
98+
<jvmFlag>-Dspring.profiles.active=docker</jvmFlag>
99+
</jvmFlags>
100+
</container>
101+
</configuration>
102+
<executions>
103+
<execution>
104+
<phase>package</phase>
105+
<goals>
106+
<goal>dockerBuild</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</profile>
114+
</profiles>
67115
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Sequences
2+
CREATE SEQUENCE IF NOT EXISTS api_key_sequence START WITH 1 INCREMENT BY 1;
3+
CREATE SEQUENCE IF NOT EXISTS application_sequence START WITH 1 INCREMENT BY 1;
4+
5+
CREATE TABLE IF NOT EXISTS api_keys
6+
(
7+
id BIGINT DEFAULT nextval('api_key_sequence') PRIMARY KEY,
8+
key VARCHAR (255) UNIQUE NOT NULL,
9+
client VARCHAR(255) UNIQUE NOT NULL,
10+
description TEXT,
11+
created_date TIMESTAMP,
12+
expiration_date TIMESTAMP,
13+
enabled BOOLEAN NOT NULL DEFAULT FALSE,
14+
never_expires BOOLEAN NOT NULL DEFAULT FALSE,
15+
approved BOOLEAN NOT NULL DEFAULT FALSE,
16+
revoked BOOLEAN NOT NULL DEFAULT FALSE
17+
);
18+
19+
CREATE TABLE IF NOT EXISTS applications
20+
(
21+
id INT DEFAULT nextval('application_sequence') PRIMARY KEY,
22+
application_name VARCHAR(255) NOT NULL,
23+
enabled BOOLEAN NOT NULL DEFAULT FALSE,
24+
approved BOOLEAN NOT NULL DEFAULT FALSE,
25+
revoked BOOLEAN NOT NULL DEFAULT FALSE,
26+
api_key_id BIGINT NOT NULL,
27+
CONSTRAINT fk_api_key
28+
FOREIGN KEY (api_key_id)
29+
REFERENCES api_keys (id)
30+
ON DELETE CASCADE
31+
);

‎common/src/main/resources/shared-application-docker.yml‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
management:
2+
observations:
3+
key-values:
4+
application: ${spring.application.name}
5+
tracing:
6+
sampling:
7+
probability: 1.0
8+
enabled: true
29
zipkin:
310
tracing:
4-
endpoint: http://zipkin:9411/api/v2/spans
11+
endpoint: http://localhost:9411/api/v2/spans
12+
endpoints:
13+
web:
14+
exposure:
15+
include: "*"
16+
endpoint:
17+
health:
18+
show-details: always
519

620
spring:
721
datasource:
822
url: jdbc:postgresql://postgres:5432/${spring.application.name}
923
username: miliariadnane
1024
password: password
25+
jpa:
26+
hibernate:
27+
ddl-auto: none
1128
rabbitmq:
1229
addresses: rabbitmq:5672
1330
sql:
1431
init:
1532
mode: always
33+
schema-locations: classpath*:db/schema.sql
1634
data-locations: classpath*:db/data.sql
1735
platform: postgresql
1836
security:

‎common/src/main/resources/shared-application-kube.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ management:
55

66
spring:
77
datasource:
8-
url: jdbc:postgresql://demo-microservices.csetxdk14qax.us-east-1.rds.amazonaws.com:5432/${spring.application.name}
8+
url: jdbc:postgresql://postgres:5432/${spring.application.name}
99
username: ${DB_USERNAME}
1010
password: ${DB_PASSWORD}
1111
rabbitmq:
1212
addresses: rabbitmq:5672
1313
jpa:
1414
hibernate:
15-
ddl-auto: update
15+
ddl-auto: create
1616
sql:
1717
init:
1818
mode: never

‎customer/pom.xml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,24 @@
125125
<configuration>
126126
<from>
127127
<image>openjdk:17</image>
128+
<platforms>
129+
<platform>
130+
<architecture>arm64</architecture>
131+
<os>linux</os>
132+
</platform>
133+
</platforms>
128134
</from>
129135
<to>
130136
<image>${image}</image>
131137
<tags>
132138
<tag>latest</tag>
133139
</tags>
134140
</to>
141+
<container>
142+
<jvmFlags>
143+
<jvmFlag>-Dspring.profiles.active=docker</jvmFlag>
144+
</jvmFlags>
145+
</container>
135146
</configuration>
136147
<executions>
137148
<execution>
@@ -159,6 +170,16 @@
159170
<configuration>
160171
<from>
161172
<image>openjdk:17</image>
173+
<platforms>
174+
<platform>
175+
<architecture>amd64</architecture>
176+
<os>linux</os>
177+
</platform>
178+
<platform>
179+
<architecture>arm64</architecture>
180+
<os>linux</os>
181+
</platform>
182+
</platforms>
162183
</from>
163184
<to>
164185
<image>${image}</image>
@@ -167,6 +188,11 @@
167188
<tag>latest</tag>
168189
</tags>
169190
</to>
191+
<container>
192+
<jvmFlags>
193+
<jvmFlag>-Dspring.profiles.active=docker</jvmFlag>
194+
</jvmFlags>
195+
</container>
170196
</configuration>
171197
<executions>
172198
<execution>

‎customer/src/main/java/dev/nano/customer/CustomerApplication.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
66
import org.springframework.cloud.openfeign.EnableFeignClients;
7-
import org.springframework.context.annotation.PropertySource;
8-
import org.springframework.context.annotation.PropertySources;
97
import org.springframework.context.annotation.ComponentScan;
108

119
@SpringBootApplication(
@@ -18,10 +16,6 @@
1816
basePackages = "dev.nano.clients"
1917
)
2018
@EnableDiscoveryClient
21-
@PropertySources({
22-
@PropertySource("classpath:amqp-${spring.profiles.active}.properties"),
23-
@PropertySource("classpath:clients-${spring.profiles.active}.properties")
24-
})
2519
@ComponentScan(basePackages = "dev.nano")
2620
public class CustomerApplication {
2721
public static void main(String[] args) {

‎customer/src/main/resources/application.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ spring:
77
application:
88
name: customer
99
config:
10-
import: classpath:shared-application-${spring.profiles.active}.yml
10+
import:
11+
- "classpath:shared-application-${spring.profiles.active}.yml"
12+
- "classpath:clients-${spring.profiles.active}.properties"
13+
- "classpath:amqp-${spring.profiles.active}.properties"
14+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Sequences
2+
CREATE SEQUENCE IF NOT EXISTS customer_sequence START WITH 1 INCREMENT BY 1;
3+
4+
CREATE TABLE IF NOT EXISTS customer
5+
(
6+
id BIGINT DEFAULT nextval('customer_sequence') PRIMARY KEY,
7+
name TEXT NOT NULL,
8+
email TEXT NOT NULL UNIQUE,
9+
phone TEXT,
10+
address TEXT
11+
);

‎docker/compose/docker-compose.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ services:
88
PGDATA: /data/postgres
99
volumes:
1010
- postgres:/data/postgres
11+
- ../config/postgres/init.sql/init.sql:/docker-entrypoint-initdb.d/init.sql
1112
ports:
12-
- "5432:5432"
13+
- "5434:5432"
1314
networks:
1415
- postgres
1516
healthcheck:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE DATABASE notification;
2+
CREATE DATABASE customer;
3+
CREATE DATABASE product;
4+
CREATE DATABASE "order";
5+
CREATE DATABASE payment;
6+
CREATE DATABASE apikey_manager;
7+
CREATE DATABASE keycloak;

0 commit comments

Comments
 (0)