4
4
5
5
package com.saveourtool.save.buildutils
6
6
7
+ import org.gradle.api.GradleException
7
8
import org.gradle.api.Project
8
9
import org.gradle.api.tasks.Exec
9
10
import org.gradle.api.tasks.TaskProvider
@@ -23,6 +24,63 @@ const val NEO4J_STARTUP_DELAY_MILLIS = 30_000L
23
24
const val MINIO_STARTUP_DELAY_MILLIS = 5_000L
24
25
const val KAFKA_STARTUP_DELAY_MILLIS = 5_000L
25
26
27
+ fun Project.registerLiquibaseTask (profile : String ) {
28
+ val registerLiquibaseTaskBackend = reqisterLiquibaseTask(
29
+ projectName = " save-backend" ,
30
+ relativeChangeLogFile = " db/db.changelog-master.xml" ,
31
+ profile = profile
32
+ )
33
+ val registerLiquibaseTaskSandbox = reqisterLiquibaseTask(
34
+ projectName = " save-sandbox" ,
35
+ relativeChangeLogFile = " save-sandbox/db/db.changelog-sandbox.xml" ,
36
+ profile = profile
37
+ )
38
+ val registerLiquibaseTaskDemo = reqisterLiquibaseTask(
39
+ projectName = " save-demo" ,
40
+ relativeChangeLogFile = " save-demo/db/db.changelog-demo.xml" ,
41
+ profile = profile
42
+ )
43
+ tasks.register(" liquibaseUpdate" ) {
44
+ dependsOn(
45
+ registerLiquibaseTaskBackend,
46
+ registerLiquibaseTaskSandbox,
47
+ registerLiquibaseTaskDemo
48
+ )
49
+ }
50
+ }
51
+
52
+ private fun Project.reqisterLiquibaseTask (projectName : String , relativeChangeLogFile : String , profile : String ): TaskProvider <Exec > {
53
+ val taskName = " liquibaseUpdate" + projectName.split(" -" ).map { it.capitalized() }.joinToString(" " )
54
+ val credentials = getDatabaseCredentials(projectName, profile)
55
+
56
+ return tasks.register<Exec >(taskName) {
57
+ val contexts = when (profile) {
58
+ " prod" -> " prod"
59
+ " dev" -> " dev"
60
+ else -> throw GradleException (" Profile $profile not configured to map on a particular liquibase context" )
61
+ }
62
+
63
+ val changeLogFile = rootDir.resolve(relativeChangeLogFile)
64
+ val changeLogFileSource = " ${changeLogFile.parent} "
65
+ val changeLogFileTarget = relativeChangeLogFile.substringBeforeLast(" /" )
66
+ commandLine(
67
+ " docker" , " run" ,
68
+ " -v" , " $changeLogFileSource :/liquibase/changelog/$changeLogFileTarget " ,
69
+ " --rm" ,
70
+ " --env" , " INSTALL_MYSQL=true" ,
71
+ " --network" , " build_default" ,
72
+ " liquibase/liquibase:4.15" ,
73
+ " --url=${credentials.getDatabaseUrlForLiquibaseInDocker()} " ,
74
+ " --changeLogFile=$relativeChangeLogFile " ,
75
+ " --username=${credentials.username} " ,
76
+ " --password=${credentials.password} " ,
77
+ " --log-level=info" ,
78
+ " --contexts=$contexts " ,
79
+ " update"
80
+ )
81
+ }
82
+ }
83
+
26
84
/* *
27
85
* @param profile deployment profile, used, for example, to start SQL database in dev profile only
28
86
*/
@@ -101,18 +159,6 @@ fun Project.createStackDeployTask(profile: String) {
101
159
| MINIO_ROOT_USER: admin
102
160
| MINIO_ROOT_PASSWORD: adminadmin
103
161
|
104
- | minio-create-bucket:
105
- | image: minio/mc:latest
106
- | depends_on:
107
- | - minio
108
- | entrypoint:
109
- | - /bin/sh
110
- | - -c
111
- | - |
112
- | /usr/bin/mc alias set minio http://minio:9000 admin adminadmin
113
- | /usr/bin/mc mb --ignore-existing minio/cnb
114
- | /usr/bin/mc policy set public minio/cnb
115
- |
116
162
|${declareDexService().prependIndent(" " )}
117
163
""" .trimMargin()
118
164
} else if (profile == " dev" && it.trim().startsWith(" logging:" )) {
@@ -226,7 +272,7 @@ fun Project.createStackDeployTask(profile: String) {
226
272
dependsOn(kafkaTaskName)
227
273
}
228
274
229
- val minioTaskName = registerService(" minio-create-bucket " , MINIO_STARTUP_DELAY_MILLIS , " startMinioService " )
275
+ val minioTaskName = registerService(" minio" , MINIO_STARTUP_DELAY_MILLIS )
230
276
tasks.register(" startMinio" ) {
231
277
dependsOn(minioTaskName)
232
278
}
0 commit comments