Skip to content

Commit 32dca40

Browse files
committed
add automation
1 parent 9fd50f5 commit 32dca40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4739
-0
lines changed

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,43 @@ Temporary Items
3535
#temp directory ignore
3636
deploy/
3737
service/python/Dockerfile
38+
39+
.certs
40+
.artifacts
41+
deploy/k8s/backend/application.yaml
42+
deploy/k8s/overlays/prod/kustomization.yaml
43+
deploy/k8s/backend/wallet/
44+
45+
generated/
46+
47+
.env.json
48+
*.bkp
49+
*.zip
50+
kubeconfig
51+
52+
# Terraform
53+
**/.terraform/*
54+
*.tfstate
55+
*.tfstate.*
56+
crash.log
57+
crash.*.log
58+
*.tfvars
59+
*.tfvars.json
60+
override.tf
61+
override.tf.json
62+
*_override.tf
63+
*_override.tf.json
64+
.terraformrc
65+
terraform.rc
66+
67+
# Node
68+
node_modules/
69+
70+
# Java
71+
.gradle
72+
build/
73+
!gradle/wrapper/gradle-wrapper.jar
74+
!**/src/main/**/build/
75+
!**/src/test/**/build/
76+
.idea
77+
bin/

K8S.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# OCI Gen AI POC
2+
3+
![Architecture](./images/architecture.png)
4+
5+
Get troubleshoot help on the [FAQ](FAQ.md)
6+
7+
## Set Up environment
8+
9+
Install dependencies for scripts.
10+
11+
```bash
12+
cd scripts/ && npm install && cd ..
13+
```
14+
15+
### Set the environment variables
16+
17+
Generate `genai.json` file with all environment variables.
18+
19+
```bash
20+
npx zx scripts/setenv.mjs
21+
```
22+
23+
> Answer the Compartment name where you want to deploy the infrastructure. Root compartment is the default.
24+
25+
### Deploy Infrastructure
26+
27+
Generate `terraform.tfvars` file for Terraform.
28+
29+
```bash
30+
npx zx scripts/tfvars.mjs
31+
```
32+
33+
```bash
34+
cd deploy/terraform
35+
```
36+
37+
Init Terraform providers:
38+
39+
```bash
40+
terraform init
41+
```
42+
43+
Apply deployment:
44+
45+
```bash
46+
terraform apply --auto-approve
47+
```
48+
49+
```bash
50+
cd ../..
51+
```
52+
53+
## Release and create Kustomization files
54+
55+
Build and push images:
56+
57+
```bash
58+
npx zx scripts/release.mjs
59+
```
60+
61+
Create Kustomization files
62+
63+
```bash
64+
npx zx scripts/kustom.mjs
65+
```
66+
67+
### Kubernetes Deployment
68+
69+
```bash
70+
export KUBECONFIG="deploy/terraform/generated/kubeconfig"
71+
```
72+
73+
```bash
74+
kubectl cluster-info
75+
```
76+
77+
```bash
78+
kubectl apply -k deploy/k8s/overlays/prod
79+
```
80+
81+
Run `get deploy` a few times:
82+
83+
```bash
84+
kubectl get deploy
85+
```
86+
87+
Wait for all deployments to be `Ready` and `Available`.
88+
89+
```
90+
NAME READY UP-TO-DATE AVAILABLE AGE
91+
backend 1/1 1 1 3m28s
92+
web 1/1 1 1 3m21s
93+
```
94+
95+
Access your application:
96+
97+
```bash
98+
echo $(kubectl get service \
99+
-n ingress-nginx \
100+
-o jsonpath='{.items[?(@.spec.type=="LoadBalancer")].status.loadBalancer.ingress[0].ip}')
101+
```
102+
103+
> This command will list the services on the `ingress-nginx` namespace and filter for the Load Balancer. If the response is an empty string, wait a bit and execute the command again. The Load Balancer takes a bit of time to create the Public IP address.
104+
105+
Take the Public IP to your browser.
106+
107+
## Clean up
108+
109+
Delete Kubernetes components
110+
111+
```bash
112+
kubectl delete -k deploy/k8s/overlays/prod
113+
```
114+
115+
Destroy infrastructure with Terraform.
116+
117+
```bash
118+
cd deploy/terraform
119+
```
120+
121+
```bash
122+
terraform destroy -auto-approve
123+
```
124+
125+
```bash
126+
cd ../..
127+
```
128+
129+
Clean up the artifacts on Object Storage
130+
131+
```bash
132+
npx zx scripts/clean.mjs
133+
```
134+
135+
## Local deployment
136+
137+
Run locally with these steps [Local](LOCAL.md)
138+
139+
## Known Issues
140+
141+
Deploying artifacts as Object Storage.
142+
143+
> There is an issue in Terraform `oracle/oci` provider on version `v5.25.0`. It is not updated to the specific version of `terraform-plugin-sdk` that fix the underlying gRCP limit of 4Mb.
144+
>
145+
> The project would want to upload artifacts to Object Storage, like the backend jar file, which is bigger than 4Mb.
146+
>
147+
> ```terraform
148+
> data "local_file" "backend_jar_tgz" {
149+
> filename = "${path.module}/../../.artifacts/backend_jar.tar.gz"
150+
> }
151+
> ```
152+
>
153+
> As a workaround, a `script/deliver.mjs` script and a `script/clean.mjs` script will deliver and clean the artifacts into Object Storage and make Pre-Authenticated Requests available for Terraform resources.

LOCAL.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Run Local
2+
3+
## Web
4+
5+
Run locally in a terminal with:
6+
7+
```bash
8+
cd web
9+
```
10+
11+
```bash
12+
npm run dev
13+
```
14+
15+
## Backend
16+
17+
Run locally on another terminal with:
18+
19+
```bash
20+
cd backend
21+
```
22+
23+
Edit `/backend/src/main/resources/application.yaml` to have the correct values.
24+
25+
```bash
26+
./gradlew bootRun
27+
```
28+
29+
## Build for distribution
30+
31+
## Build artifacts
32+
33+
### Build Java Application:
34+
35+
```bash
36+
cd backend
37+
```
38+
39+
```bash
40+
./gradlew bootJar
41+
```
42+
43+
> `build/libs/backend-0.0.1.jar` jar file generated
44+
45+
```bash
46+
cd ..
47+
```
48+
49+
### Build Web Application:
50+
51+
```bash
52+
cd web
53+
```
54+
55+
```bash
56+
npm run build
57+
```
58+
59+
> `dist` folder generated
60+
61+
```bash
62+
cd ..
63+
```

architecture.drawio

Lines changed: 889 additions & 0 deletions
Large diffs are not rendered by default.

backend/.dockerignore

Whitespace-only changes.

backend/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM --platform=linux/amd64 container-registry.oracle.com/java/jdk-no-fee-term:21-oraclelinux8 as build
2+
3+
RUN mkdir /opt/src
4+
COPY . /opt/src
5+
WORKDIR /opt/src
6+
RUN ./gradlew clean bootJar
7+
8+
FROM --platform=linux/amd64 container-registry.oracle.com/java/jdk-no-fee-term:21-oraclelinux8
9+
10+
VOLUME /tmp
11+
COPY --from=build /opt/src/build/libs/*.jar /tmp/
12+
RUN mkdir /app
13+
RUN mv /tmp/backend*.jar /app/backend.jar
14+
15+
ENTRYPOINT ["java","-jar","/app/backend.jar"]

backend/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '3.2.2'
4+
id 'io.spring.dependency-management' version '1.1.4'
5+
}
6+
7+
group = 'dev.victormartin.oci.genai.backend'
8+
version = '0.0.3'
9+
10+
java {
11+
sourceCompatibility = '17'
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
20+
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
21+
implementation 'org.springframework.boot:spring-boot-starter-websocket'
22+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
23+
implementation 'com.oracle.oci.sdk:oci-java-sdk-shaded-full:3.33.0'
24+
implementation 'com.oracle.oci.sdk:oci-java-sdk-core:3.35.0'
25+
implementation 'com.oracle.oci.sdk:oci-java-sdk-common:3.35.0'
26+
implementation 'com.oracle.oci.sdk:oci-java-sdk-addons-oke-workload-identity:3.35.0'
27+
implementation 'com.oracle.oci.sdk:oci-java-sdk-generativeai:3.35.0'
28+
implementation 'com.oracle.database.jdbc:ojdbc11-production:21.8.0.0'
29+
implementation 'com.oracle.database.jdbc:ucp:21.8.0.0'
30+
implementation 'com.oracle.database.security:oraclepki:21.8.0.0'
31+
implementation 'com.oracle.database.security:osdt_cert:21.8.0.0'
32+
implementation 'com.oracle.database.security:osdt_core:21.8.0.0'
33+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
34+
}
35+
36+
tasks.named('test') {
37+
useJUnitPlatform()
38+
}
42.4 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)