Skip to content

Commit

Permalink
Implement JPA through Elide
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed May 7, 2024
1 parent 735b891 commit f8ccfe7
Show file tree
Hide file tree
Showing 25 changed files with 1,205 additions and 677 deletions.
15 changes: 13 additions & 2 deletions .github/actions/ci-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: 'setup'
description: 'CI setup, such as installing JDK'
name: 'CI Setup'
description: 'Environment setup for CI phase such as installing JDK and Elide data models'

inputs:
data-models-repo-org:
description: 'Elide data models repo owner, e.g. paion-data'
required: true
data-models-repo-name:
description: 'Elide data models repo name, e.g. my-jpa-data-model'
required: true

runs:
using: "composite"
steps:
- name: Set up JDK
uses: QubitPi/jersey-webservice-deployment-actions/.github/actions/jdk-setup@master
- name: Load Maven settings.xml
shell: bash
run: cp settings.xml.example ~/.m2/settings.xml
65 changes: 31 additions & 34 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ name: Template CI/CD
push:
branches:
- master
- jpa-elide

env:
JDK_VERSION: 17
JDK_DISTRIBUTION: 'adopt'
USER: QubitPi
EMAIL: jack20220723@gmail.com
MODEL_PACKAGE_NAME: 'io.github.qubitpi.ws.jersey.template.models'

jobs:
yml-md-style-and-link-checks:
Expand All @@ -38,6 +40,9 @@ jobs:
- uses: actions/checkout@v3
- name: Test environment setup
uses: ./.github/actions/ci-setup
with:
data-models-repo-org: QubitPi
data-models-repo-name: jersey-webservice-template-jpa-data-models
- name: Set up Docker for Integration Tests
uses: docker-practice/actions-setup-docker@master
- name: Run unit & integration tests
Expand All @@ -57,6 +62,9 @@ jobs:
node-version: 18
- name: Test environment setup
uses: ./.github/actions/ci-setup
with:
data-models-repo-org: QubitPi
data-models-repo-name: jersey-webservice-template-jpa-data-models
- name: Install dependencies
working-directory: docs
run: yarn
Expand All @@ -78,49 +86,38 @@ jobs:
user_name: ${{ env.USER }}
user_email: ${{ env.EMAIL }}

docker-image:
name: Build Test & Release Development Docker Image
needs: tests
slack-notification-pr:
name: Send Slack Notification
if: ${{ (github.event_name == 'pull_request') && always() }}
needs: documentation
uses: QubitPi/hashicorp-aws/.github/workflows/slack-notification.yml@master
with:
job-status: ${{ needs.documentation.outputs.outcome }}
secrets:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}

triggering:
name: Triggering data model CI/CD
needs: documentation
if: github.ref == 'refs/heads/jpa-elide'
outputs:
outcome: ${{ job.status }}
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Test environment setup
uses: ./.github/actions/ci-setup
- name: Build App WAR file so that Docker can pickup during image build
run: mvn clean package
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Test image build
uses: docker/build-push-action@v3
with:
context: .
push: false
- name: Login to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
- name: Trigger data model CI/CD
uses: peter-evans/repository-dispatch@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/jersey-webservice-template:latest
token: ${{ secrets.JWT_DOWNSTREAM_CICD_TRIGGER_TOKEN }}
repository: QubitPi/jersey-webservice-template-jpa-data-models
event-type: jersey-webservice-template-jpa-elide-changes

slack-notification:
slack-notification-jpa-elide-branch-commit:
name: Send Slack Notification
if: ${{ always() }}
needs: [documentation, docker-image]
if: ${{ (github.ref == 'refs/heads/jpa-elide') && always() }}
needs: triggering
uses: QubitPi/hashicorp-aws/.github/workflows/slack-notification.yml@master
with:
job-status: ${{ (needs.documentation.outputs.outcome == 'success' && needs.docker-image.outputs.outcome == 'success') && 'success' || 'failure' }}
job-status: ${{ needs.triggering.outputs.outcome }}
secrets:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright Jiaqi Liu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: "3.9"
services:
web:
build: .
ports:
- "8080:8080"
environment:
- MODEL_PACKAGE_NAME=${MODEL_PACKAGE_NAME}
- DB_USER=root
- DB_PASSWORD=root
- DB_DRIVER=com.mysql.jdbc.Driver
- DB_DIALECT=org.hibernate.dialect.MySQLDialect
- DB_URL=jdbc:mysql://db/elide?serverTimezone=UTC
- OAUTH_ENABLED=${OAUTH_ENABLED:-false}
- JWKS_URL=${JWKS_URL}
- HIBERNATE_HBM2DDL_AUTO=create
depends_on:
db:
condition: service_healthy
db:
image: "mysql:5.7"
ports:
- "3306:3306"
volumes:
- "${MYSQL_INIT_SCRIPT_PATH:-./mysql-init.sql}:/docker-entrypoint-initdb.d/mysql-init.sql"
environment:
MYSQL_ROOT_PASSWORD: root
command: --character-set-server=utf8 --collation-server=utf8_general_ci
healthcheck:
test: mysqladmin ping -h localhost -u root -proot
timeout: 3s
retries: 3
16 changes: 16 additions & 0 deletions docs/docs/elide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ The following configurations can be placed in the properties file called **jpada
- **DB_URL**: The persistence DB URL, such as "jdbc:mysql://localhost/elide?serverTimezone=UTC".
- **DB_DRIVER**: The SQL DB driver class name, such as "com.mysql.jdbc.Driver".
- **DB_DIALECT**: The SQL DB dialect name, such as "org.hibernate.dialect.MySQLDialect".
- **HIBERNATE_HBM2DDL_AUTO**: What to do with existing JPA database when webservice starts; can be one of the 4 values:

1. _validate_: validate that the schema matches, make no changes to the schema of the database. _This is the default
value of **HIBERNATE_HBM2DDL_AUTO**_
2. _update_: update the schema to reflect the entities being persisted
3. _create_: creates the schema necessary for your entities, destroying any previous data.
4. _create-drop_: create the schema as in create above, but also drop the schema at the end of the session. This is
great in development or for testing.

:::note

This property is exactly the same as [Hibernate `hibernate.hbm2ddl.auto` property].

:::

CI/CD
-----
Expand Down Expand Up @@ -115,6 +129,8 @@ Note that how `my-webservice-repo-changes` is used to bridge the event dispatche

[GitHub Action - How to set up]: https://docs.github.com/en/actions/security-guides/encrypted-secrets

[Hibernate `hibernate.hbm2ddl.auto` property]: https://stackoverflow.com/questions/18077327/hibernate-hbm2ddl-auto-possible-values-and-what-they-do

[Java system properties]: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
[jersey-webservice-template-jpa-data-models]: https://github.com/QubitPi/jersey-webservice-template-jpa-data-models
[jersey-webservice-template-jpa-data-models-acceptance-tests]: https://github.com/QubitPi/jersey-webservice-template-jpa-data-models-acceptance-tests
Expand Down
16 changes: 16 additions & 0 deletions mysql-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright Jiaqi Liu
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

CREATE DATABASE IF NOT EXISTS elide;
USE elide;
Loading

0 comments on commit f8ccfe7

Please sign in to comment.