Skip to content
3 changes: 3 additions & 0 deletions java/cicd-github-actions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
.idea
.DS_Store
12 changes: 12 additions & 0 deletions java/cicd-github-actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Source code for the blog: Database CI/CD with the Oracle DB Operator, GitHub Actions and Liquibase

Secrets required
DB_WALLET_PASSWORD - Password for DB wallet
FT_DEFAULT_ADMIN_PASSWORD - Default DB password
OCI_COMPARTMENT_OCID - Compartment OCID
OCI_CLI_USER - User OCID
OCI_CLI_TENANCY - User Tenancy OCID
OCI_CLI_FINGERPRINT - User Fingerprint
OCI_CLI_KEY_CONTENT - User Private Key Content
OCI_CLI_REGION - User Region
OKE_CLUSTER_OCID - OKE Cluster OCID
8 changes: 8 additions & 0 deletions java/cicd-github-actions/base/sidb-xe/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
name: arbitrary


resources:
- sidb.yaml
41 changes: 41 additions & 0 deletions java/cicd-github-actions/base/sidb-xe/sidb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright (c) 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

apiVersion: database.oracle.com/v1alpha1
kind: SingleInstanceDatabase
metadata:
name: db-
spec:

# Setup with LoadBalancer
loadBalancer: true

## Use only alphanumeric characters for sid
sid: XE

## DB edition
edition: express

## Secret containing SIDB password mapped to secretKey
adminPassword:
secretName: default-admin-password

## Database image details
image:
## Oracle Database Free is only supported from DB version 23.2 onwards
pullFrom: container-registry.oracle.com/database/express:latest
prebuiltDB: true

## size is the required minimum size of the persistent volume
## storageClass is specified for automatic volume provisioning
## accessMode can only accept one of ReadWriteOnce, ReadWriteMany
persistence:
size: 50Gi
## oci-bv applies to OCI block volumes. Use "standard" storageClass for dynamic provisioning in Minikube. Update as appropriate for other cloud service providers
storageClass: "oci-bv"
accessMode: "ReadWriteOnce"

## Count of Database Pods. Should be 1 for express edition.
replicas: 1
14 changes: 14 additions & 0 deletions java/cicd-github-actions/liquibase/admin/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">

<include file="schema_a.sql" />
<include file="schema_b.sql" />

</databaseChangeLog>
8 changes: 8 additions & 0 deletions java/cicd-github-actions/liquibase/admin/schema_a.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- liquibase formatted sql

-- changeset liquibase:1
CREATE USER "SCHEMA_A" NO AUTHENTICATION;
ALTER USER "SCHEMA_A" GRANT CONNECT THROUGH SYSTEM;
GRANT UNLIMITED TABLESPACE TO "SCHEMA_A";
GRANT CONNECT, RESOURCE TO "SCHEMA_A";
ALTER USER "SCHEMA_A" DEFAULT ROLE CONNECT, RESOURCE;
8 changes: 8 additions & 0 deletions java/cicd-github-actions/liquibase/admin/schema_b.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- liquibase formatted sql

-- changeset liquibase:2
CREATE USER "SCHEMA_B" NO AUTHENTICATION;
ALTER USER "SCHEMA_B" GRANT CONNECT THROUGH SYSTEM;
GRANT UNLIMITED TABLESPACE TO "SCHEMA_B";
GRANT CONNECT, RESOURCE TO "SCHEMA_B";
ALTER USER "SCHEMA_B" DEFAULT ROLE CONNECT, RESOURCE;
16 changes: 16 additions & 0 deletions java/cicd-github-actions/liquibase/schema_a/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">

<include file="departments.sql" />
<include file="departments_lookup.sql" />
<!-- employees has a foreign key constraint on departments -->
<include file="employees.sql" />


</databaseChangeLog>
10 changes: 10 additions & 0 deletions java/cicd-github-actions/liquibase/schema_a/departments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- liquibase formatted sql

-- changeset liquibase:1
CREATE TABLE SCHEMA_A.DEPARTMENTS (
DEPARTMENT_ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
DEPARTMENT_NAME VARCHAR2(80) NOT NULL
) LOGGING;


--rollback DROP TABLE SCHEMA_A.DEPARTMENTS;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- liquibase formatted sql

-- changeset liquibase:Initial
INSERT INTO SCHEMA_A.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES (1, 'Engineering');
INSERT INTO SCHEMA_A.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES (2, 'Sales');
INSERT INTO SCHEMA_A.DEPARTMENTS (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES (3, 'HR');
12 changes: 12 additions & 0 deletions java/cicd-github-actions/liquibase/schema_a/employees.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- liquibase formatted sql

-- changeset liquibase:2
CREATE TABLE SCHEMA_A.EMPLOYEES (
EMPLOYEE_ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
EMPLOYEE_FIRSTNAME VARCHAR2 (255) NOT NULL,
EMPLOYEE_LASTNAME VARCHAR2 (255) NOT NULL,
DEPARTMENT_ID NUMBER REFERENCES SCHEMA_A.DEPARTMENTS(DEPARTMENT_ID)
) LOGGING;


--rollback DROP TABLE SCHEMA_A.EMPLOYEES;
13 changes: 13 additions & 0 deletions java/cicd-github-actions/liquibase/schema_b/changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">

<include file="tasks.sql" />

</databaseChangeLog>
11 changes: 11 additions & 0 deletions java/cicd-github-actions/liquibase/schema_b/tasks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- liquibase formatted sql

-- changeset liquibase:1
CREATE TABLE SCHEMA_B.TASKS (
TASK_ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
TASK_NAME VARCHAR2(300) NOT NULL,
TASK_DESCRIPTION VARCHAR2(4000)
) LOGGING;


--rollback DROP TABLE SCHEMA_B.TASKS;
19 changes: 19 additions & 0 deletions java/cicd-github-actions/scripts/checkdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

IDENTIFICATION=$1

while : ; do

# get status
STATUS=$(kubectl get -n "feature-$IDENTIFICATION" singleinstancedatabase "db-$IDENTIFICATION" -o 'jsonpath={.status.status}')
# if database is available, end while loop; else sleep
if [[ "$STATUS" == "Healthy" ]]; then
break;
else
echo "Checking for DB Availability..."
sleep 5;
fi;

done;

echo "Database now available."
23 changes: 23 additions & 0 deletions java/cicd-github-actions/scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# set token
IDENTIFICATION=$(python get.py "$BRANCH_REF")
DBNAME=$(python clean_dbname.py "$IDENTIFICATION")

# kustomize remove if exists
if test -f "kustomization.yaml"; then
rm kustomization.yaml
fi

# create patch
cat <<EOF > patch.yaml
- op: add # action
path: "/spec/details/compartmentOCID"
value: ${COMPARTMENT_OCID}
- op: add # action
path: "/spec/details/dbName"
value: db${DBNAME}
- op: add # action
path: "/spec/details/displayName"
value: dbtest-${IDENTIFICATION}
EOF
46 changes: 46 additions & 0 deletions java/cicd-github-actions/scripts/run_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
import re
import sys
import os
import json



def list_schemas(location):
d = [ x.removeprefix(f'{location}/') for x in [x[0] for x in os.walk(location) if x[0] != location ] ]
d.remove("admin")
return json.dumps({"schemas": d})


def clean(with_name):
# used for database name
return re.sub('[^a-z0-9_$#]', '', with_name)


def get_feature_name(listing):
# expects list of [x, feature/A102, y]

for x in listing:
if x.startswith("feature"):
return x

def get_identification(from_feature_name):
# expects identification to be after feature

listing = from_feature_name.split("/")
for i in range(len(listing)):
if listing[i].lower().startswith("feature") and i+1 < len(listing):
return listing[i+1].lower()


# expects [filename] [command] [inputs]
command = sys.argv[1]

if command == "dbname":
print(clean(sys.argv[2]))
elif command == "id":
names = get_feature_name(sys.argv[2:])
ident = get_identification(names)
print(ident)
elif command == "schemas":
print(list_schemas(sys.argv[2]))
Loading