/spring-hr

Spring Boot Web MVC of the Oracle HR Schema

Primary LanguageJava

HR

This is a sample spring application that uses the Oracle HR Schema.

Swagger

The OpenAPI is at /hr/openapi and the Swagger UI is at /hr/swagger/.

How to Run

Prerequisites

For running and developing:

For deploying:

Environment

Place your environment variables in the .env file. An example, .env.example is supplied and can be copied:

# copy the example
cp .env.example .env
# add your envs to .example.env`

To build:

bash docker-build.sh

To run locally on docker:

# this assumes you have a dp running locally
bash docker-run.sh

To tag and push a release to the OCI Container Registry:

# source your environment variables
source .env
# syntax:
# bash tag-and-push.sh major.minor.patch $REGION $TENANCY_NAMESPACE

# example: 
bash tag-and-push.sh 0.1.1 $REGION $TENANCY_NAMESPACE

Database

Simply build the database from the docker-compose.yml.

docker-compose up -d oracle-database-xe-18400-slim

A PDB will be created with the name ORCLPDB1. This will run the startup scripts located in src/main/resources/db/startup.

To connect via SQLcl:

# SYS
sql sys/password@localhost:1521/ORCLPDB1 as sysdba
# HR Schema
sql hr/super-secret-password@localhost:1521/ORCLPDB1

Spring

This is a maven project and includes the maven wrapper. Simply use the spring-boot maven command:

./mvnw spring-boot:run

Each time your run the Liquibase migrations will run if required. This includes seed data.

Or through Docker

./docker-build.sh
./docker-run.sh

Or through docker-compose

docker-compose up spring-hr

Deployment

New Deployment

Login to private container registry:

docker login <region-key>.ocir.io
Username: <container-registry-namespace>/oracleidentitycloudservice/<username>
Password: <auth-token>

If this is a new repository, create it with this command:

oci artifacts container repository create --display-name oci-dev/<app-name> --compartment-id <compartment-id>

Provide the login credentials to kubernetes. More information.

kubectl create secret docker-registry <secret-name> --docker-server=<region-key>.ocir.io --docker-username='<tenancy-namespace>/<oci-username>' --docker-password='<oci-auth-token>' --docker-email='<email-address>'

Create a secret for the database url and password:

kubectl create secret generic hr-db-url-pass \
	--from-literal=url=<url> \
	--from-literal=password=<password>

This repository assumes you are using Oracle Autonomous Database (ATP) in OCI. Download your Oracle Wallet for your database and place its contents in src/main/resources/db/wallet. The Docker build will pickup this and put it in the container.

Build & Push

Now, build, tag, push to the registry. See OCI's documentation for more help.

# build the image
bash docker-build.sh
# tag image & push
bash tag-and-push.sh <major.minor.patch>
# Example:
# bash tag-and-push.sh 0.1.1 $REGION $TENANCY_NAMESPACE

Once your new version is pushed to the registry, deploy:

kubectl apply -f deployment/app.yaml
kubectl apply -f deployment/ingress-route.yaml