Skip to content

Commit af2be38

Browse files
authored
ADB-Free Container Helm Support (#210)
* Added ADB-Free support into Helm * Hugo Update for Documentation * Image Action Checks including Scans * Pin cohere module to 5.1.5
1 parent 1e715e5 commit af2be38

23 files changed

+357
-56
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
build:
3737
runs-on: ubuntu-latest
3838
env:
39-
HUGO_VERSION: 0.145.0
39+
HUGO_VERSION: 0.148.0
4040
steps:
4141
- name: Install Hugo CLI
4242
run: |

.github/workflows/image_smoke.yml

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ name: Validate Container Images
44
on:
55
pull_request:
66
types:
7-
- opened
87
- synchronize
98
- reopened
109
- ready_for_review
10+
paths:
11+
- "src/**"
12+
- ".github/workflows/image_smoke.yml"
1113

1214
# Allows running this workflow manually
1315
workflow_dispatch:
1416

1517
jobs:
16-
docker-build:
17-
if: github.event.pull_request.draft == false
18+
image-build-test:
1819
runs-on: ubuntu-latest
1920
# Block merging if the job fails
2021
permissions:
@@ -37,30 +38,64 @@ jobs:
3738
- name: Checkout Code
3839
uses: actions/checkout@v4
3940

40-
- name: Set up Docker Buildx
41-
uses: docker/setup-buildx-action@v3
42-
with:
43-
driver: docker-container
44-
45-
- name: Cache Image Layers
41+
- name: Restore Cache
4642
uses: actions/cache@v4
4743
with:
4844
path: /tmp/.buildx-cache
49-
key: ${{ runner.os }}-buildx-${{ matrix.build.name }}-${{ github.sha }}
45+
key: ${{ runner.os }}-buildx-${{ matrix.build.name }}-${{ github.ref_name }}
5046
restore-keys: |
5147
${{ runner.os }}-buildx-${{ matrix.build.name }}-
48+
${{ runner.os }}-buildx-
49+
50+
- name: Create Buildx builder
51+
run: docker buildx create --use --name mybuilder || docker buildx use mybuilder
5252

5353
- name: Build Container Image with Cache
5454
run: |
55-
docker buildx create --use
56-
docker buildx build \
57-
--cache-from=type=local,src=/tmp/.buildx-cache \
58-
--cache-to=type=local,dest=/tmp/.buildx-cache-new \
59-
--file ${{ matrix.build.context }}/${{ matrix.build.dockerfile }} \
60-
--output=type=cacheonly \
61-
${{ matrix.build.context }}
55+
if [ "${{ matrix.build.name }}" = "aio" ]; then
56+
docker buildx build \
57+
--cache-from=type=local,src=/tmp/.buildx-cache \
58+
--cache-to=type=local,dest=/tmp/.buildx-cache-new \
59+
--file ${{ matrix.build.context }}/${{ matrix.build.dockerfile }} \
60+
--tag ${{ matrix.build.name }}:${{ github.sha }} \
61+
--load \
62+
${{ matrix.build.context }}
63+
else
64+
docker buildx build \
65+
--cache-from=type=local,src=/tmp/.buildx-cache \
66+
--cache-to=type=local,dest=/tmp/.buildx-cache-new \
67+
--file ${{ matrix.build.context }}/${{ matrix.build.dockerfile }} \
68+
--output=type=cacheonly \
69+
${{ matrix.build.context }}
70+
fi
6271
6372
- name: Move Cache for Reuse
6473
run: |
6574
rm -rf /tmp/.buildx-cache
6675
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
76+
77+
- name: Save Cache
78+
uses: actions/cache@v4
79+
with:
80+
path: /tmp/.buildx-cache
81+
key: ${{ runner.os }}-buildx-${{ matrix.build.name }}-${{ github.ref_name }}
82+
83+
- name: Scan with Trivy
84+
if: matrix.build.name == 'aio'
85+
uses: aquasecurity/trivy-action@0.32.0
86+
with:
87+
scan-type: image
88+
image-ref: "aio:${{ github.sha }}"
89+
severity: HIGH,CRITICAL
90+
format: json
91+
output: trivy-report.json
92+
cache: true
93+
ignore-unfixed: true
94+
exit-code: 1
95+
96+
- name: Upload Trivy Report on Failure
97+
if: failure() && matrix.build.name == 'aio'
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: trivy-report-${{ matrix.build.name }}
101+
path: trivy-report.json

.github/workflows/opentofu.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ name: Validate Infrastructure as Code
44
on:
55
pull_request:
66
types:
7-
- opened
87
- synchronize
98
- reopened
109
- ready_for_review
11-
# Limit runs to only when opentofu changes
1210
paths:
11+
- "tests/**"
1312
- "opentofu/**"
1413
- ".github/workflows/opentofu.yml"
1514

1615
# Allows running this workflow manually
1716
workflow_dispatch:
1817

1918
jobs:
20-
check:
21-
if: github.event.pull_request.draft == false
19+
verify-iac:
2220
runs-on: ubuntu-latest
2321
container:
2422
image: hashicorp/terraform:latest

.github/workflows/pytest.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ name: Test Suite
44
on:
55
pull_request:
66
types:
7-
- opened
87
- synchronize
98
- reopened
109
- ready_for_review
10+
paths:
11+
- "tests/**"
12+
- "src/**"
13+
- ".github/workflows/pytest.yml"
1114

1215
# Allows running this workflow manually
1316
workflow_dispatch:
1417

1518
jobs:
1619
check:
17-
if: github.event.pull_request.draft == false
1820
runs-on: ubuntu-latest
1921
services:
2022
docker:

.github/workflows/releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77
IAC: ${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}-stack.zip
88

99
jobs:
10-
build:
10+
build-release:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Oracle AI Optimizer and Toolkit
22

33
<!-- spell-checker:ignore streamlit, venv, setuptools -->
4+
![Test Status](https://github.com/oracle-samples/ai-optimizer/actions/workflows/pytest.yml/badge.svg)
5+
![IaC Status](https://github.com/oracle-samples/ai-optimizer/actions/workflows/opentofu.yml/badge.svg)
6+
![Build Status](https://github.com/oracle-samples/ai-optimizer/actions/workflows/image_smoke.yml/badge.svg)
47

58
## Description
69

docs/content/advanced/helm.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Configure Oracle Cloud Infrastructure used by the {{< short_app_ref >}} API Serv
155155
| server.oci_config.user | string | `""` | User OCID. Required when specifying keySecretName. |
156156
| server.oci_config.fingerprint | string | `""` | Fingerprint. Required when specifying keySecretName. |
157157
| server.oci_config.region | string | `""` | Region. Required when oke is true. |
158-
| server.oci_config.fileSecretName | string | `""` | Secret containing an OCI config file and the key_file(s). Use the scripts/oci_config.py script to help create the secret based on an existing ~.oci/config file |
158+
| server.oci_config.fileSecretName | string | `""` | Secret containing an OCI config file and the key_file(s). Use the [scripts/oci_config.py](https://github.com/oracle-samples/ai-optimizer/blob/main/helm/scripts/oci_config.py) script to help create the secret based on an existing ~.oci/config file |
159159
| server.oci_config.keySecretName | string | `""` | Secret containing a single API key corresponding to above tenancy configuration This used by OraOperator when not running in OKE |
160160

161161
###### Examples
@@ -299,7 +299,7 @@ Give the **Helm Chart** a spin using a locally installed [Kind](https://kind.sig
299299

300300
1. (Optional) Configure for Oracle Cloud Infrastructure
301301

302-
If you already have an OCI API configuration file, use the `oci_config` helper script to turn it into a secret for OCI connectivity:
302+
If you already have an OCI API configuration file, use the [scripts/oci_config.py](https://github.com/oracle-samples/ai-optimizer/blob/main/helm/scripts/oci_config.py) helper script to turn it into a secret for OCI connectivity:
303303

304304
```sh
305305
kubectl create namespace ai-optimizer
@@ -337,6 +337,11 @@ Give the **Helm Chart** a spin using a locally installed [Kind](https://kind.sig
337337
enabled: true
338338
```
339339

340+
1. Add the Helm Repository
341+
```sh
342+
helm repo add ai-optimizer https://oracle-samples.github.io/ai-optimizer/helm
343+
```
344+
340345
1. Deploy the Helm Chart
341346

342347
```sh

helm/charts/server/templates/configmap.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ metadata:
1313
data:
1414
init.sh: |
1515
sqlplus <<- EOF
16+
WHENEVER SQLERROR EXIT 1
17+
WHENEVER OSERROR EXIT 1
1618
connect / as sysdba
1719
ALTER SYSTEM SET VECTOR_MEMORY_SIZE=512M SCOPE=SPFILE;
1820
ALTER SESSION SET CONTAINER=FREEPDB1;
@@ -36,6 +38,70 @@ data:
3638
STARTUP FORCE;
3739
ALTER SYSTEM REGISTER;
3840
EOF
41+
{{- else if eq .Values.database.type "ADB-FREE" }}
42+
apiVersion: v1
43+
kind: ConfigMap
44+
metadata:
45+
name: db-custom-scripts
46+
labels:
47+
{{- include "app.labels" . | nindent 4 }}
48+
data:
49+
init.sh: |
50+
sql /nolog <<- EOF
51+
WHENEVER SQLERROR EXIT 1
52+
WHENEVER OSERROR EXIT 1
53+
connect ADMIN/${DB_PASSWORD}@//${DB_DSN}
54+
DECLARE
55+
l_conn_user VARCHAR2(255);
56+
l_user VARCHAR2(255);
57+
l_tblspace VARCHAR2(255);
58+
BEGIN
59+
BEGIN
60+
SELECT user INTO l_conn_user FROM DUAL;
61+
SELECT username INTO l_user FROM DBA_USERS WHERE USERNAME='${DB_USERNAME}';
62+
EXCEPTION WHEN no_data_found THEN
63+
EXECUTE IMMEDIATE 'CREATE USER "${DB_USERNAME}" IDENTIFIED BY "${DB_PASSWORD}"';
64+
END;
65+
SELECT default_tablespace INTO l_tblspace FROM dba_users WHERE username = '${DB_USERNAME}';
66+
EXECUTE IMMEDIATE 'ALTER USER "${DB_USERNAME}" QUOTA UNLIMITED ON ' || l_tblspace;
67+
EXECUTE IMMEDIATE 'GRANT DB_DEVELOPER_ROLE TO "${DB_USERNAME}"';
68+
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD TO "${DB_USERNAME}"';
69+
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD_AI TO "${DB_USERNAME}"';
70+
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD_PIPELINE TO "${DB_USERNAME}"';
71+
EXECUTE IMMEDIATE 'ALTER USER "${DB_USERNAME}" DEFAULT ROLE ALL';
72+
END;
73+
/
74+
BEGIN
75+
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
76+
host => '${API_SERVER_HOST}',
77+
ace => xs\$ace_type(privilege_list => xs\$name_list('http'),
78+
principal_name => '${DB_USERNAME}',
79+
principal_type => xs_acl.ptype_db)
80+
);
81+
END;
82+
/
83+
BEGIN
84+
DBMS_CLOUD.CREATE_CREDENTIAL(
85+
credential_name => 'AI_OPTIMIZER_CRED',
86+
username => 'SELECTAI',
87+
password => '${API_SERVER_KEY}'
88+
);
89+
EXCEPTION WHEN OTHERS THEN
90+
IF SQLCODE = -20022 THEN NULL;
91+
ELSE RAISE;
92+
END IF;
93+
END;
94+
/
95+
-- !! NOT YET GA !!
96+
-- BEGIN
97+
-- DBMS_CLOUD_AI.CREATE_PROFILE(
98+
-- profile_name => 'AI_OPTIMIZER' ,
99+
-- attributes => '{"provider_endpoint": "${API_SERVER_HOST}:8000",
100+
-- "model": "openai"}'
101+
-- );
102+
--END;
103+
--/
104+
EOF
39105
{{- else if .Values.oci_config }}
40106
apiVersion: v1
41107
kind: ConfigMap

helm/charts/server/templates/database.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,63 @@ spec:
5454
- name: db-custom-scripts
5555
configMap:
5656
name: db-custom-scripts
57+
{{- else if eq .Values.database.type "ADB-FREE" }}
58+
apiVersion: apps/v1
59+
kind: Deployment
60+
metadata:
61+
name: {{ include "release.name" . }}-adb
62+
labels:
63+
{{- include "app.labels" . | nindent 4 }}
64+
"app.kubernetes.io/component": "database"
65+
spec:
66+
replicas: 1
67+
selector:
68+
matchLabels:
69+
{{- include "app.selectorLabels" . | nindent 6 }}
70+
"app.kubernetes.io/component": "database"
71+
template:
72+
metadata:
73+
labels:
74+
{{- include "app.labels" . | nindent 8 }}
75+
"app.kubernetes.io/component": "database"
76+
spec:
77+
securityContext:
78+
fsGroup: 54321
79+
runAsGroup: 54321
80+
runAsUser: 54321
81+
containers:
82+
- name: adb-free
83+
image: {{ .Values.database.image.repository }}:{{ .Values.database.image.tag }}
84+
imagePullPolicy: IfNotPresent
85+
ports:
86+
- containerPort: 1521
87+
readinessProbe:
88+
tcpSocket:
89+
port: 1521
90+
initialDelaySeconds: 60
91+
periodSeconds: 10
92+
env:
93+
- name: DATABASE_NAME
94+
value: FREEPDB1
95+
- name: ENABLE_ARCHIVE_LOG
96+
value: "False"
97+
- name: ADMIN_PASSWORD
98+
valueFrom:
99+
secretKeyRef:
100+
name: {{ $secretName }}
101+
key: password
102+
- name: WALLET_PASSWORD
103+
valueFrom:
104+
secretKeyRef:
105+
name: {{ $secretName }}
106+
key: password
107+
volumeMounts:
108+
- name: db-custom-scripts
109+
mountPath: "/opt/oracle/scripts/startup"
110+
volumes:
111+
- name: db-custom-scripts
112+
configMap:
113+
name: db-custom-scripts
57114
{{- else if eq .Values.database.type "ADB-S" }}
58115
apiVersion: database.oracle.com/v1alpha1
59116
kind: AutonomousDatabase

0 commit comments

Comments
 (0)