Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 12507a1f authored by Daya Adianto's avatar Daya Adianto
Browse files

Add capability to run using HSQLDB on deployment environment

parent 035f0f21
No related branches found
No related tags found
1 merge request!10Add capability to run using HSQLDB on deployment environment
......@@ -47,7 +47,7 @@ stages:
build:
stage: build
image: docker.io/library/maven:3.8.6-eclipse-temurin-17-focal
image: docker.io/library/maven:3.9.5-eclipse-temurin-17-focal
before_script:
- java -version && javac --version && mvn --version
- pwd
......@@ -66,7 +66,7 @@ build:
test:
stage: test
image: docker.io/library/maven:3.8.6-eclipse-temurin-17-focal
image: docker.io/library/maven:3.9.5-eclipse-temurin-17-focal
services:
- name: docker.io/library/postgres:14-alpine
alias: database
......@@ -84,9 +84,9 @@ test:
- pwd
script:
# Run test suites
- mvn clean test
- mvn $MAVEN_CLI_OPTS clean test
# Run PMD and generate test reports
- mvn verify -DskipTests
- mvn $MAVEN_CLI_OPTS verify -DskipTests
# Get line coverage
- grep -o "Total[^%]*%" target/site/jacoco/index.html
coverage: '/Total.*?(\d{1,3})%/'
......@@ -107,23 +107,31 @@ test:
deploy:
stage: deploy
image: docker.io/bitnami/git:2.42.0
image: docker.io/dokku/ci-docker-image:0.9.3
variables:
FLYCTL_VERSION: 0.1.104
FLY_API_TOKEN: $PRODUCTION_FLY_API_TOKEN
APP_NAME: sitodo-pmpl
BRANCH: $CI_COMMIT_BRANCH
COMMAND: deploy
GIT_REMOTE_URL: ssh://dokku@dokku-ppl.cs.ui.ac.id/$APP_NAME
SSH_PRIVATE_KEY: $DOKKU_SSH_PRIVATE_KEY
GIT_DEPTH: "0"
rules: !reference [.upstream-deploy-production-rules, rules]
before_script:
- curl -L https://fly.io/install.sh | sh -s $FLYCTL_VERSION
- chmod +x .gitlab/dokku-ci-pre-deploy.sh
- mkdir -p ./bin
- cp .gitlab/dokku-ci-pre-deploy.sh ./bin/ci-pre-deploy
script:
- /root/.fly/bin/flyctl deploy --remote-only
- dokku-deploy
after_script:
- dokku-unlock
environment:
name: production
url: https://sitodo-pmpl.fly.dev
url: http://$APP_NAME.dokku-ppl.cs.ui.ac.id
dependencies: []
bdd-test:
stage: post-deploy
image: docker.io/library/maven:3.8.6-eclipse-temurin-17-focal
image: docker.io/library/maven:3.9.5-eclipse-temurin-17-focal
variables:
DEBUG: "false"
TRACE: "false"
......@@ -134,7 +142,7 @@ bdd-test:
before_script:
- apt-get update && apt-get install -y firefox
- sed -i "s#headless.mode = false#headless.mode = true#" src/test/resources/serenity.conf
- sed -i "s#http://localhost:8080#https://sitodo-pmpl.fly.dev#" src/test/resources/serenity.conf
- sed -i "s#http://localhost:8080#http://sitodo-pmpl.dokku-ppl.cs.ui.ac.id#" src/test/resources/serenity.conf
script:
- mvn -P bdd clean verify
dependencies: []
......@@ -160,7 +168,7 @@ visualize-coverage:
sonarqube-check:
stage: report
image: docker.io/library/maven:3.8.6-eclipse-temurin-17-focal
image: docker.io/library/maven:3.9.5-eclipse-temurin-17-focal
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
......
#!/bin/sh -l
# Based on: https://github.com/dokku/ci-docker-image/pull/28
# TODO: Allow custom SPRING_PROFILES_ACTIVE set from the CI
ssh "$SSH_REMOTE" -- config:set "$APP_NAME" "SPRING_PROFILES_ACTIVE=hsqldb"
echo "Configured the app to run using hsqldb profile"
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JsonSchemaMappingsProjectConfiguration">
<state>
<map>
<entry key="Liquibase">
<value>
<SchemaInfo>
<option name="name" value="Liquibase" />
<option name="relativePathToSchema" value="https://json.schemastore.org/liquibase-3.2.json" />
<option name="applicationDefined" value="true" />
<option name="patterns">
<list>
<Item>
<option name="path" value="src/main/resources/db/changelog/db.changelog-master.yaml" />
</Item>
</list>
</option>
</SchemaInfo>
</value>
</entry>
<entry key="docker-compose.yml">
<value>
<SchemaInfo>
<option name="name" value="docker-compose.yml" />
<option name="relativePathToSchema" value="https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json" />
<option name="applicationDefined" value="true" />
<option name="patterns">
<list>
<Item>
<option name="path" value="compose.yaml" />
</Item>
</list>
</option>
</SchemaInfo>
</value>
</entry>
</map>
</state>
</component>
</project>
\ No newline at end of file
# Use JDK & Maven image to build the application
FROM docker.io/library/maven:3.9.4-eclipse-temurin-17-alpine AS builder
FROM docker.io/library/maven:3.9.5-eclipse-temurin-17-alpine AS builder
# Set the working directory inside the container
WORKDIR /src
......@@ -29,5 +29,8 @@ COPY --chown=app:app --from=builder /src/target/sitodo-*.jar .
# Expose port 8080
EXPOSE 8080
# Set environment variables
ENV SPRING_PROFILES_ACTIVE=""
# Run the application JAR file
CMD ["/bin/sh", "-c", "java -jar sitodo-*.jar"]
......@@ -90,6 +90,19 @@ Following Spring Boot convention, properties are named in all uppercase and dot
For instance, `spring.datasource.url` becomes `SPRING_DATASOURCE_URL` when configured using an environment variable.
See the example in the [GitLab CI/CD configuration](./.gitlab-ci.yml), specifically in the job for running tests.
The project includes a Spring profile that lets you test and run the application using an in-memory database (HSQLDB).
To test and run the application using HSQLDB as the backing database, enable the profile using the following command:
```shell
# When running a Maven task
mvn -D"spring.profiles.active=hsqldb" [task]
# When running the app as standalone JAR
java -D"spring.profiles.active=hsqldb" sitodo.jar
# Or configure via environment variable
export SPRING_PROFILES_ACTIVE=hsqldb
java -jar sitodo.jar
```
### Running Example
See the running example based on the [upstream's `main` branch](https://gitlab.cs.ui.ac.id/pmpl/examples/sitodo-pmpl/-/tree/main) at [Fly.io](https://sitodo-pmpl.fly.dev).
......
......@@ -10,7 +10,7 @@
</parent>
<groupId>com.example</groupId>
<artifactId>sitodo</artifactId>
<version>0.1.2-SNAPSHOT</version>
<version>0.1.3-SNAPSHOT</version>
<name>sitodo-pmpl</name>
<description>A basic todo app for teaching basic Web programming, Git workflows, and CI/CD. Heavily inspired by the
running example in &quot;Test-Driven Development with Python&quot; book by Harry Percival.
......@@ -54,6 +54,11 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>bootstrap</artifactId>
......
# Application configuration
## Warning: Set debug to true only during development and debugging!
debug=true
trace=false
server.port=8080
sitodo.motivation.empty=Your list is empty :(
sitodo.motivation.noFinished=You have not finished any of your tasks!
sitodo.motivation.someFinished=You have finished some of your tasks!
sitodo.motivation.halfFinished=You have finished half of your tasks!
sitodo.motivation.allFinished=Congratulations!
sitodo.motivation.fewItems=You have too few tasks!
sitodo.motivation.manyItems=You have too many tasks!
sitodo.motivation.fewItemsThreshold=5
sitodo.motivation.manyItemsThreshold=10
# Database connection configuration
## Warning: The following configurations are for development environment!
## Use different values when deploying to production environment!
spring.datasource.url=jdbc:hsqldb:mem:sitodo
spring.datasource.username=sitodo
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:db/changelog/db.changelog-hsqldb.yaml
......@@ -21,3 +21,6 @@ sitodo.motivation.manyItemsThreshold=10
spring.datasource.url=jdbc:postgresql://localhost:5432/sitodo
spring.datasource.username=sitodo
spring.datasource.password=R83Moz74
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:db/changelog/db.changelog-postgresql.yaml
---
databaseChangeLog:
- includeAll:
path: ./hsqldb/
relativeToChangelogFile: true
---
databaseChangeLog:
- includeAll:
path: ./postgresql/
relativeToChangelogFile: true
---
databaseChangeLog:
- preConditions:
- dbms:
type: "hsqldb"
- changeSet:
id: "0001_initial_schema"
author: sitodo_maintainer
changes:
- createSequence:
sequenceName: todo_item_seq
incrementBy: 1
startValue: 1
- createSequence:
sequenceName: todo_list_seq
incrementBy: 1
startValue: 1
- createTable:
tableName: todo_item
columns:
- column:
name: id
# Approximate the appropriate data type using existing types
# from java.sql package: https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Types.html
type: INTEGER
autoIncrement: true
valueSequenceNext: todo_item_seq
constraints:
primaryKey: true
primaryKeyName: pk_todo_item
- column:
name: title
type: VARCHAR(255)
constraints:
nullable: false
- column:
name: finished
type: BOOLEAN
defaultValueBoolean: false
- createTable:
tableName: todo_list
columns:
- column:
name: id
type: INTEGER
autoIncrement: true
valueSequenceNext: todo_list_seq
constraints:
primaryKey: true
primaryKeyName: pk_todo_list
- createTable:
tableName: todo_list_items
columns:
- column:
name: todo_list_id
type: INTEGER
constraints:
foreignKeyName: fk_todo_list_items_todo_list
referencedTableName: todo_list
referencedColumnNames: id
- column:
name: items_id
type: INTEGER
constraints:
foreignKeyName: fk_todo_list_items_todo_item
referencedTableName: todo_item
referencedColumnNames: id
rollback:
- dropTable:
tableName: todo_list_items
- dropTable:
tableName: todo_list
- dropTable:
tableName: todo_item
- dropSequence:
sequenceName: todo_list_seq
- dropSequence:
sequenceName: todo_item_seq
---
databaseChangeLog:
- preConditions:
- dbms:
type: "postgresql"
- changeSet:
id: 1
id: "0001_initial_schema"
author: sitodo_maintainer
changes:
- createSequence:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment