Skip to content

Commit

Permalink
Merge pull request #22 from bryopsida/add-liquibase
Browse files Browse the repository at this point in the history
Database migrations
  • Loading branch information
bryopsida authored Oct 21, 2023
2 parents f0c94f1 + e7cfa1b commit 2bc86b1
Show file tree
Hide file tree
Showing 23 changed files with 413 additions and 106 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,9 @@ jobs:
path: chart/
- name: Set up chart-testing
uses: helm/[email protected]
- name: Deploy a database
run: |
helm repo add groundhog2k https://groundhog2k.github.io/helm-charts/
helm --namespace test install postgres groundhog2k/postgres
- name: Install
run: ct install --charts chart/ --namespace test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build
bin
.gradle
.DS_Store
.DS_Store
.idea
.vscode
36 changes: 0 additions & 36 deletions HELP.md

This file was deleted.

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ create-namespace:
build-chart:
./gradlew k8sResource k8sHelm

deploy: build-chart
helm --namespace=$(HELM_NAMESPACE) upgrade --install spring-boot-starter-k8s ./build/jkube/helm/spring-boot-starter-k8s/kubernetes/
build-dependencies:
helm dependency build ./build/jkube/helm/spring-boot-starter-k8s/kubernetes/

deploy: build-chart build-dependencies
helm --namespace=$(HELM_NAMESPACE) upgrade --install spring-boot-starter-k8s ./build/jkube/helm/spring-boot-starter-k8s/kubernetes/ --set image_tag=local
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Spring Boot Starter K8S Template

## What is this?

This is a template repository for kicking off a cloud native spring boot java microservice.

## What makes this cloud native?

It's solely focused on deployment to kubernetes, the primary build artifacts of the repository are a OCI image and a helm chart. The helm chart is dynamically generated using jkube and it's associated gradle plugin.

## What opinions have applied to this?

- Gradle
- Spring Boot
- Spring Flux
- Spring R2DBC (Reactive Database)
- Netty
- JKube (Kubernetes Deployment and Development Tools)
- Liquibase

## How do I run locally?

Use `make run`.

## How do I run locally outside of a container?

If you wish to run directly in your IDE:

1. Run `docker-compose up -d` to start the postgres database server.
2. Run `./gradlew update bootRun`, `update` runs the migrations and `bootRun` launches the spring boot application
150 changes: 97 additions & 53 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ plugins {
id 'io.spring.dependency-management' version '1.1.3'
id 'org.eclipse.jkube.kubernetes' version '1.15-SNAPSHOT'
id 'com.palantir.git-version' version '3.0.0'
id 'org.liquibase.gradle' version '2.2.0'
id 'com.diffplug.spotless' version '6.22.0'
id 'jacoco'
id 'jacoco'
}

group = 'io.github.bryopsida'
Expand Down Expand Up @@ -45,8 +46,17 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.2.0'
implementation 'org.postgresql:r2dbc-postgresql:1.0.2.RELEASE'
implementation 'org.postgresql:postgresql:42.6.0'

liquibaseRuntime 'org.liquibase:liquibase-core:4.16.1'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.2'
liquibaseRuntime 'info.picocli:picocli:4.6.1'
liquibaseRuntime "org.postgresql:postgresql"

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
Expand All @@ -60,62 +70,96 @@ tasks.named('test') {
useJUnitPlatform()
}

liquibase {
activities {
main {
changelogFile 'classpath:/changelog/v1.json'
classpath "$rootDir/src/main/resources/db"
username "postgres"
password "postgres"
logLevel "info"
url 'jdbc:postgresql://localhost:5432/spring-boot-starter'
}
}
}

kubernetes {
offline = false
images {
image {
name = 'ghcr.io/bryopsida/spring-boot-starter-k8s'
build {
image {
name = 'ghcr.io/bryopsida/spring-boot-starter-k8s'
build {
assembly {
name = 'target'
}
}
}
}
access {
namespace = 'default'
}
generator {
includes = ['spring-boot']
config {
'spring-boot' {
color = 'always'
}
}
}
resources {
labels {
all {
testProject = 'spring-boot-stater-k8s'
}
}
}
helm {
stableRepository {
name = 'stable'
url = "https://ghcr.io/" + System.getenv("HELM_REPO_PATH")
type = 'OCI'
username = System.getenv("HELM_REPO_USERNAME")
password = System.getenv("HELM_REPO_PASSWORD")
}
}
name = 'target'
}
}
}
}
access {
namespace = 'default'
}
enricher {
excludes = ['jkube-expose']
config {
'jkube-healthcheck-spring-boot' {
path = '/actuator/health'
}
}
}
generator {
includes = ['spring-boot']
config {
'spring-boot' {
color = 'always'
}
}
}
resources {
labels {
all {
testProject = 'spring-boot-stater-k8s'
}
}
configMap {
name = 'liquibase-change-log-v1'
entries = [{
file = 'src/main/resources/db/changelog/v1.json'
}]
}
}
helm {
apiVersion = 'v2'
keywords = ['spring-boot', 'starter-template']
dependencies = [{
name = 'postgres'
repository = 'https://groundhog2k.github.io/helm-charts/'
version = '0.4.6'
condition = 'postgres.enabled'
}]
}
}
spotless {
java {
importOrder()
removeUnusedImports()
cleanthat()
prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
formatAnnotations()
licenseHeader '/* (C) $YEAR */'
}
format 'styling', {
target '*.md', '*.yaml', '*.yml'
prettier()
}
java {
importOrder()
removeUnusedImports()
cleanthat()
prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
formatAnnotations()
licenseHeader '/* (C) $YEAR */'
}
format 'misc', {
target '*.gradle', '*.md', '.gitignore', '.yml'
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}
format 'styling', {
target '*.md', '*.yaml', '*.yml'
prettier()
}
}
tasks.register('printProjectName') {
doLast {
println project.name
}
doLast {
println project.name
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"
services:
database:
image: "postgres:latest"
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=springboottemplate
8 changes: 4 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginManagement {
repositories {
maven { url "https://plugins.gradle.org/m2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
repositories {
maven { url "https://plugins.gradle.org/m2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
rootProject.name = 'spring-boot-starter-k8s'
4 changes: 4 additions & 0 deletions src/main/java/io/github/springboottemplate/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.r2dbc.config.EnableR2dbcAuditing;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;

@EnableR2dbcRepositories
@EnableR2dbcAuditing
@SpringBootApplication
public class App {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* (C) 2023 */
package io.github.springboottemplate.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class DbConfig {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* (C) 2023 */
package io.github.springboottemplate.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class SecurityConfig {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* (C) 2023 */
package io.github.springboottemplate.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {}
Loading

0 comments on commit 2bc86b1

Please sign in to comment.