Merge pull request #39 from beaniejoy/feature/38

Jenkins FlywayRunner plugin 이용한 DB Migrate stage 내용 수정
This commit is contained in:
Hanbin Lee
2023-03-12 19:47:18 +09:00
committed by GitHub
10 changed files with 71 additions and 83 deletions

View File

@@ -9,17 +9,18 @@ pipeline {
sh 'printenv'
FLYWAY_CONFIG = '/home/ec2-user/flyway/flyway.conf'
MIGRATION_SCRIPT = './script/db_migration.sh'
}
}
}
stage('DB Migrate') {
steps {
sh """
chmod 755 ${MIGRATION_SCRIPT}
/bin/bash ${MIGRATION_SCRIPT} ${FLYWAY_CONFIG}
"""
flywayrunner installationName: 'flywaytool-jenkins',
flywayCommand: 'info migrate validate',
commandLineArgs: "-configFiles=${FLYWAY_CONFIG}",
credentialsId: 'ecb29499-7272-4e8b-b3ab-a7a3ab7eafab',
url: '',
locations: "filesystem:${WORKSPACE}/db/migration"
}
}

View File

@@ -5,11 +5,19 @@
<br>
## Specification
- java 17
- kotlin 1.6.21
- Spring Boot 2.7.0
- MySQL 8.0.21
## :pushpin: Specification
- Lang
- java 17
- kotlin 1.6.21
- Framework
- Spring Boot 2.7.0
- DB
- MySQL 8.0.21
- Flyway(migration)
- CI/CD
- Jenkins
- Cloud Server
- AWS Lightsail(Amazon Linux2)
<br>
@@ -25,7 +33,7 @@
<br>
## :pushpin: Run Application
## :pushpin: Setting
### 💽 로컬 DB 구성 (docker)
- local에 DB(MySQL)용 docker container run
@@ -34,31 +42,8 @@
$ docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=beaniejoy -d -p 3306:3306 mysql:8.0.21
```
### 💽 DB Migration (flyway)
[flyway doc](https://documentation.red-gate.com/fd/flyway-documentation-138346877.html)
- **Info**
Prints the details and status information about all the migrations
```bash
$ ./gradlew :db:flywayInfo
```
- **Validate**
Validates the applied migrations against the available ones
DB에 적용된 migration과 local에 적용된 migration 정보 일치 여부 체크
```bash
$ ./gradlew :db:flywayValidate
```
- **Migrate**
Migrates the schema to the latest version
migration 설정 내용들 반영
```bash
$ ./gradlew :db:flywayMigrate
```
- **Clean**
Drops all objects (tables, views, procedures, triggers, …) in the configured schemas
(prodution 단계에서는 절대 사용 X)
```bash
$ ./gradlew :db:flywayClean -i
```
### 💽 DB Migration (with flyway)
- [DB migration directory README](https://github.com/beaniejoy/dongne-cafe-api/blob/main/db/README.md)
### 💽 docker compose 실행(수정 작업 진행중)
- docker compose를 이용한 nginx, DB(MySQL), application 한꺼번에 실행하는 경우

View File

@@ -15,8 +15,4 @@ object Plugins {
const val PLUGIN_SPRING = "plugin.spring"
const val PLUGIN_JPA = "plugin.jpa"
}
object FlywayDB {
const val FLYWAY = "org.flywaydb.flyway"
}
}

View File

@@ -15,8 +15,4 @@ object Version {
const val KOTLIN_LOGGING = "3.0.4"
const val JWT = "0.11.5"
}
object FlywayDB {
const val FLYWAY_CORE = "9.8.1"
}
}

42
db/README.md Normal file
View File

@@ -0,0 +1,42 @@
# DB Migration
- flyway version: `9.15.4`
- [flyway doc](https://documentation.red-gate.com/fd/flyway-documentation-138346877.html)
## :pushpin: Installation
```shell
$ brew install flyway
```
- macOS 전용
<br>
## :pushpin: Flyway Command
- **Clean**
Drops all objects (tables, views, procedures, triggers, …) in the configured schemas
(prodution 단계에서는 절대 사용 X)
```bash
$ flyway clean -configFiles=db/flyway.conf
```
- **Info**
Prints the details and status information about all the migrations
```bash
$ flyway info -configFiles=db/flyway.conf
```
- **Migrate**
Migrates the schema to the latest version
migration 설정 내용들 반영
```bash
$ flyway migrate -configFiles=db/flyway.conf
```
- **Validate**
Validates the applied migrations against the available ones
DB에 적용된 migration과 local에 적용된 migration 정보 일치 여부 체크
```bash
$ flyway validate -configFiles=db/flyway.conf
```

View File

@@ -1,25 +0,0 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.flywaydb:flyway-mysql:${Version.FlywayDB.FLYWAY_CORE}")
}
}
plugins {
id(Plugins.FlywayDB.FLYWAY).version(Version.FlywayDB.FLYWAY_CORE)
}
dependencies {
implementation("org.flywaydb:flyway-core:${Version.FlywayDB.FLYWAY_CORE}") // flyway
}
flyway {
baselineDescription = "Start Flyway Migration!"
baselineOnMigrate = true
baselineVersion = "000"
configFiles = arrayOf(System.getProperty("config") ?: "flyway.conf")
cleanDisabled = false // activate flywayClean
ignoreMigrationPatterns = arrayOf("*:pending") // ignore validating pending(대기) state
}

View File

@@ -2,4 +2,9 @@ flyway.url=jdbc:mysql://localhost:3306/dongne?autoreconnect=true&characterEncodi
flyway.user=root
flyway.password=beaniejoy
flyway.driver=com.mysql.cj.jdbc.Driver
flyway.locations=filesystem:db/migration,db/seed
flyway.locations=filesystem:db/migration,db/seed
flyway.baselineOnMigrate=true
flyway.baselineVersion=000
# flyway.ignoreMigrationPatterns=*:pending
flyway.cleanDisabled=false

View File

@@ -5,7 +5,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: none # use [service-api] flyway migration
ddl-auto: none # use flyway migration
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect

View File

@@ -1,11 +0,0 @@
#!/bin/bash
echo "================ 1. Flyway Info ================"
./gradlew :db:flywayInfo -Dconfig=$1
echo "================ 2. Flyway Validate ============"
./gradlew :db:flywayValidate -Dconfig=$1
echo "================ 3. Flyway Migrate ============="
./gradlew :db:flywayMigrate -Dconfig=$1

View File

@@ -2,4 +2,3 @@ rootProject.name = "dongne-cafe-api"
include("dongne-common")
include("dongne-service-api")
include("dongne-account-api")
include("db")