2022-12-26 10:09:08 -06:00
plugins {
id 'java' // required by versioning
2023-12-19 12:00:54 -06:00
id 'docker-compose'
2022-12-26 10:09:08 -06:00
}
2023-12-19 12:00:54 -06:00
import com.avast.gradle.dockercompose.tasks.ComposeUp
import com.avast.gradle.dockercompose.tasks.ComposeDownForced
2025-07-11 20:12:10 +05:30
import org.yaml.snakeyaml.Yaml
2022-12-26 10:09:08 -06:00
apply from: "../gradle/versioning/versioning.gradle"
ext {
2024-10-25 22:29:19 -05:00
compose_base = "profiles/docker-compose.yml"
2024-10-28 09:03:19 -05:00
project_name = "datahub"
2024-10-25 22:29:19 -05:00
2024-01-25 12:41:51 -06:00
backend_profile_modules = [
2022-12-26 10:09:08 -06:00
':docker:elasticsearch-setup' ,
':docker:mysql-setup' ,
':docker:kafka-setup' ,
2023-01-31 18:44:37 -06:00
':datahub-upgrade' ,
2024-01-25 12:41:51 -06:00
':metadata-service:war' ,
]
2024-12-20 20:00:09 -06:00
2025-04-16 12:23:29 +02:00
python_services_modules = [
]
2024-12-20 20:00:09 -06:00
// Common configuration for all tasks
common_config = [
captureContainersOutput: true ,
captureContainersOutputToFiles: project . file ( 'build/container-logs' )
2022-12-26 10:09:08 -06:00
]
2023-11-29 09:16:48 -06:00
2024-12-20 20:00:09 -06:00
// declarative task configuration
quickstart_configs = [
'quickstart' : [
profile: 'quickstart-consumers' ,
modules: python_services_modules + backend_profile_modules + [
':datahub-frontend' ,
':metadata-jobs:mce-consumer-job' ,
':metadata-jobs:mae-consumer-job' ,
2025-04-16 12:23:29 +02:00
':datahub-actions' ,
2024-12-20 20:00:09 -06:00
]
] ,
2025-07-11 20:12:10 +05:30
'quickstartCLI' : [
profile: 'quickstart' ,
modules: python_services_modules + backend_profile_modules + [
':datahub-frontend' ,
':datahub-actions' ,
]
] ,
2024-12-20 20:00:09 -06:00
'quickstartDebug' : [
profile: 'debug' ,
2025-04-16 12:23:29 +02:00
modules: python_services_modules + backend_profile_modules + [ ':datahub-frontend' , ':datahub-actions' ] ,
2025-05-05 10:54:31 -05:00
isDebug: true ,
additionalEnv: [
DATAHUB_LOCAL_ACTIONS_ENV: "${rootProject.project(':smoke-test').projectDir}/test_resources/actions/actions.env"
]
2024-12-20 20:00:09 -06:00
] ,
2025-04-25 08:12:41 +05:30
'quickstartDebugMin' : [
profile: 'debug-min' ,
modules: backend_profile_modules + [ ':datahub-frontend' ] ,
isDebug: true
] ,
2025-01-14 14:26:59 -08:00
'quickstartDebugConsumers' : [
profile: 'debug-consumers' ,
modules: python_services_modules + backend_profile_modules + [ ':datahub-frontend' ,
':metadata-jobs:mce-consumer-job' ,
2025-04-16 12:23:29 +02:00
':metadata-jobs:mae-consumer-job' ,
':datahub-actions' ] ,
2025-05-05 10:54:31 -05:00
isDebug: true ,
additionalEnv: [
DATAHUB_LOCAL_ACTIONS_ENV: "${rootProject.project(':smoke-test').projectDir}/test_resources/actions/actions.env"
]
2025-01-14 14:26:59 -08:00
] ,
2024-12-20 20:00:09 -06:00
'quickstartPg' : [
profile: 'quickstart-postgres' ,
modules: ( backend_profile_modules - [ ':docker:mysql-setup' ] ) + [
':docker:postgres-setup' ,
2025-04-16 12:23:29 +02:00
':datahub-frontend' ,
':datahub-actions' ,
2024-12-20 20:00:09 -06:00
]
] ,
'quickstartPgDebug' : [
profile: 'debug-postgres' ,
modules: python_services_modules + ( backend_profile_modules - [ ':docker:mysql-setup' ] ) + [
':docker:postgres-setup' ,
':datahub-frontend'
] ,
isDebug: true
] ,
'quickstartSlim' : [
profile: 'quickstart-backend' ,
2025-04-16 12:23:29 +02:00
modules: backend_profile_modules + [
2025-05-24 13:42:10 -05:00
':datahub-actions' ,
]
] ,
'quickstartSpark' : [
profile: 'quickstart-backend' ,
modules: backend_profile_modules + [
':datahub-actions' ,
2025-04-16 12:23:29 +02:00
] ,
2024-12-20 20:00:09 -06:00
additionalEnv: [
2025-07-19 21:50:03 +05:30
'DATAHUB_LOCAL_COMMON_ENV' : "${rootProject.project(':metadata-integration:java:spark-lineage-legacy').projectDir}/spark-smoke-test/smoke-gms.env" ,
'METADATA_SERVICE_AUTH_ENABLED' : 'false'
2024-12-20 20:00:09 -06:00
]
] ,
'quickstartStorage' : [
profile: 'quickstart-storage' ,
preserveVolumes: true
2025-04-24 23:00:03 +05:30
] ,
2025-05-28 15:11:27 -05:00
'quickstartBackendDebug' : [
profile: 'debug-backend-aws' ,
modules: python_services_modules + backend_profile_modules + [ ':datahub-frontend' , ':datahub-actions' ] ,
isDebug: true ,
additionalEnv: [
DATAHUB_LOCAL_ACTIONS_ENV: "${rootProject.project(':smoke-test').projectDir}/test_resources/actions/actions.env"
]
] ,
2025-04-24 23:00:03 +05:30
'allImages' : [ //This is a special task just to include all images as dependencies - and is useful when CI needs to publish all images
profile: 'quickstart-consumers' ,
modules: python_services_modules + backend_profile_modules + [
':datahub-frontend' ,
':metadata-jobs:mce-consumer-job' ,
':metadata-jobs:mae-consumer-job' ,
':datahub-actions' ,
2025-05-13 13:24:04 -05:00
':docker:datahub-ingestion' ,
':docker:postgres-setup'
2025-04-24 23:00:03 +05:30
]
2024-12-20 20:00:09 -06:00
]
2023-02-16 10:41:42 -06:00
]
2025-04-02 11:51:10 +05:30
2025-04-25 08:12:41 +05:30
// only for debug variants of quickstart to enable <variant>Reload tasks.
2025-04-02 11:51:10 +05:30
// The actual service name needs the profile to be appended, <container-name>-<profile>
2025-04-25 08:12:41 +05:30
// This list only contains modules that can be reloaded via the reloadTask. If other modules need to be reloaded, quickstart* needs to be used.
2025-04-02 11:51:10 +05:30
moduleToContainer = [
':metadata-service:war' : 'datahub-gms' ,
':datahub-frontend' : 'frontend' ,
':metadata-jobs:mce-consumer-job' : 'datahub-mce-consumer' ,
':metadata-jobs:mae-consumer-job' : 'datahub-mae-consumer' ,
]
2024-12-20 20:00:09 -06:00
}
// Register all quickstart tasks
quickstart_configs . each { taskName , config - >
2025-04-02 11:51:10 +05:30
tasks . register ( taskName ) {
group = 'quickstart'
}
2024-12-20 20:00:09 -06:00
}
// Dynamically create all quickstart tasks and configurations
dockerCompose {
// Configure default settings that apply to all configurations
useComposeFiles = [ compose_base ]
projectName = project_name
projectNamePrefix = ''
buildBeforeUp = false
buildBeforePull = false
stopContainers = false
removeVolumes = false
quickstart_configs . each { taskName , config - >
"${taskName}" {
isRequiredBy ( tasks . named ( taskName ) )
if ( config . profile ) {
composeAdditionalArgs = [ '--profile' , config . profile ]
}
// Common environment variables
2025-01-14 19:35:36 -06:00
environment . put 'DATAHUB_VERSION' , System . getenv ( "DATAHUB_VERSION" ) ? : "v${version}"
2024-12-20 20:00:09 -06:00
environment . put 'DATAHUB_TELEMETRY_ENABLED' , 'false'
environment . put "METADATA_TESTS_ENABLED" , "true"
environment . put "DATAHUB_REPO" , "${docker_registry}"
2025-07-11 20:12:10 +05:30
2024-12-20 20:00:09 -06:00
// Additional environment variables if specified
if ( config . additionalEnv ) {
config . additionalEnv . each { key , value - >
environment . put key , value
}
}
useComposeFiles = [ compose_base ]
projectName = project_name
projectNamePrefix = ''
buildBeforeUp = false
buildBeforePull = false
stopContainers = false
removeVolumes = false
2025-05-15 13:47:04 +05:30
retainContainersOnStartupFailure = config . isDebug ? true : false //forcing nulls to bool
2024-12-20 20:00:09 -06:00
// Apply common configuration
common_config . each { key , value - >
delegate . "${key}" = value
}
// Apply additional task-specific configuration if specified
if ( config . additionalConfig ) {
config . additionalConfig . each { key , value - >
delegate . "${key}" = value
}
}
}
}
}
2024-10-10 17:57:23 -05:00
2022-12-26 10:09:08 -06:00
2025-07-11 20:12:10 +05:30
task generateQuickstartComposeConfig {
description = "Generates the docker-compose config output for quickstart configuration for use with oss quickstart cli"
group = "docker"
doLast {
def composeUpTask = tasks . named ( "quickstartCLIComposeUp" )
// Some of these details task gleaned from the docker-compose plugin source code
// https://github.com/avast/gradle-docker-compose-plugin/blob/main/src/main/groovy/com/avast/gradle/dockercompose/ComposeExecutor.groovy
def composeExecutor = composeUpTask . get ( ) . getComposeExecutor ( ) . get ( )
composeExecutor . parameters . environment . put ( "DATAHUB_VERSION" , '__VERSION__' )
composeExecutor . parameters . environment . put ( "METADATA_SERVICE_AUTH_ENABLED" , 'false' )
def configOutput = composeExecutor . execute ( 'config' )
// The `config` returns a fully resolved compose file. We need to replace the DATAHUB_VERSION and HOME with values not available at build time
configOutput = configOutput . replace ( '__VERSION__' , '${DATAHUB_VERSION}' )
configOutput = configOutput . replace ( System . getenv ( 'HOME' ) , '${HOME}' )
// Parse configOutput as yaml and add UI_INGESTION_DEFAULT_CLI_VERSION as an env var under datahub-gms-quickstart.environment key
// This needs to be matched with the version of the CLI used to launch quickstart
def yaml = new Yaml ( )
def config = yaml . load ( configOutput )
config [ 'services' ] [ 'datahub-gms-quickstart' ] [ 'environment' ] [ 'UI_INGESTION_DEFAULT_CLI_VERSION' ] = '${UI_INGESTION_DEFAULT_CLI_VERSION}'
// Configure YAML dump options to match Docker Compose format
def dumpOptions = new org . yaml . snakeyaml . DumperOptions ( )
dumpOptions . setDefaultFlowStyle ( org . yaml . snakeyaml . DumperOptions . FlowStyle . BLOCK )
dumpOptions . setIndent ( 2 )
dumpOptions . setWidth ( 120 )
yaml = new Yaml ( dumpOptions )
configOutput = yaml . dump ( config )
configOutput = "# This file is generated as part of build process. If any build changes cause this file to be modified, please check in the generated file\n" + configOutput
def outputFile = project . file ( "${project.projectDir}/quickstart/docker-compose.quickstart-profile.yml" )
outputFile . getParentFile ( ) . mkdirs ( )
outputFile . text = configOutput
logger . lifecycle ( "quickstart Docker Compose config saved to: ${outputFile.absolutePath}" )
}
}
2025-04-02 11:51:10 +05:30
// Register all quickstart tasks
quickstart_configs . each { taskName , config - >
tasks . register ( "prepareAll${taskName}" ) {
group = 'quickstart-ci'
}
}
quickstart_configs . each { taskName , config - >
if ( config . modules ) {
tasks . getByName ( "prepareAll${taskName}" ) . dependsOn (
config . modules . collect { it + ':dockerPrepare' }
)
}
}
2025-04-15 09:48:11 +05:30
2025-04-02 11:51:10 +05:30
quickstart_configs . each { taskName , config - >
2025-04-15 09:48:11 +05:30
tasks . register ( "buildImages${taskName}" , Exec ) {
ext {
bakeSpec = [ : ]
}
2025-04-02 11:51:10 +05:30
group = 'quickstart-ci'
2025-05-07 20:13:52 +05:30
def taskSuffix = config . isDebug ? 'debug' : ''
dependsOn ( config . modules . collect { it + ":generateBakeSnippet${taskSuffix}" } )
2025-04-15 09:48:11 +05:30
dependsOn ( tasks . getByName ( "prepareAll${taskName}" ) )
2025-07-11 20:12:10 +05:30
dependsOn tasks . named ( "generateQuickstartComposeConfig" )
2025-04-02 11:51:10 +05:30
2025-04-15 09:48:11 +05:30
def jsonFile = new File ( rootProject . buildDir , "bake-spec-${taskName}.json" )
def bakeCmdArgs = [ "bake" , "-f" , "${jsonFile.absolutePath}" ]
def buildCmd = [ ]
if ( System . getenv ( "DOCKER_CACHE" ) = = "DEPOT" ) {
buildCmd < < "depot"
buildCmd + = bakeCmdArgs
buildCmd + = [ '--save' , '--metadata-file' , "${rootProject.buildDir}/build-metadata.json" ]
2025-04-24 23:00:03 +05:30
if ( project . properties . getOrDefault ( "dockerPush" , false ) ) {
buildCmd < < "--push"
2025-04-15 09:48:11 +05:30
}
} else {
buildCmd + = [ "docker" , "buildx" ]
buildCmd + = bakeCmdArgs
}
commandLine buildCmd
workingDir rootProject . projectDir
doFirst {
def bakeSnippets = [ : ]
def targets = [ ]
config . modules . each { module - >
def moduleProject = project . project ( module )
2025-05-07 20:13:52 +05:30
def generateBakeSnippetsTask = moduleProject . tasks . getByName ( "generateBakeSnippet${taskSuffix}" )
2025-04-15 09:48:11 +05:30
bakeSnippets . putAll ( generateBakeSnippetsTask . bakeSpec . target )
targets . addAll ( generateBakeSnippetsTask . bakeSpec . target . keySet ( ) )
}
ext . bakeSpec . group = [ "default" : [ "targets" : targets ] ]
ext . bakeSpec . target = bakeSnippets
jsonFile . parentFile . mkdirs ( )
jsonFile . text = groovy . json . JsonOutput . prettyPrint ( groovy . json . JsonOutput . toJson ( ext . bakeSpec ) )
}
2025-04-02 11:51:10 +05:30
}
}
2025-04-15 09:48:11 +05:30
// Configure dependencies for ComposeUp tasks
2025-04-02 11:51:10 +05:30
quickstart_configs . each { taskName , config - >
if ( config . modules ) {
2025-04-15 09:48:11 +05:30
tasks . getByName ( "${taskName}ComposeUp" ) . dependsOn (
tasks . getByName ( "buildImages${taskName}" )
2025-04-02 11:51:10 +05:30
)
}
}
2025-04-15 09:48:11 +05:30
2024-01-03 15:58:50 -06:00
tasks . register ( 'minDockerCompose2.20' , Exec ) {
executable 'bash'
args '-c' , 'echo -e "$(docker compose version --short)\n2.20"|sort --version-sort --check=quiet --reverse'
}
2024-01-03 22:31:48 -06:00
tasks . register ( 'quickstartNuke' ) {
2025-04-02 11:51:10 +05:30
group = 'quickstart'
2024-01-03 22:31:48 -06:00
doFirst {
2024-12-20 20:00:09 -06:00
quickstart_configs . each { taskName , config - >
dockerCompose . "${taskName}" . removeVolumes = ! config . preserveVolumes
}
2024-01-03 22:31:48 -06:00
}
finalizedBy ( tasks . withType ( ComposeDownForced ) )
2023-08-17 00:10:17 -05:00
}
2024-01-03 22:31:48 -06:00
tasks . register ( 'quickstartDown' ) {
2025-04-02 11:51:10 +05:30
group = 'quickstart'
2023-12-19 12:00:54 -06:00
finalizedBy ( tasks . withType ( ComposeDownForced ) )
2022-12-26 10:09:08 -06:00
}
2023-12-19 12:00:54 -06:00
tasks . withType ( ComposeUp ) . configureEach {
shouldRunAfter ( 'quickstartNuke' )
2024-01-03 15:58:50 -06:00
dependsOn tasks . named ( "minDockerCompose2.20" )
2023-02-16 10:41:42 -06:00
}
2025-04-02 11:51:10 +05:30
// Register all quickstart Reload tasks. For quickstartDebug, the reload task is DebugReload. (Taskname without quickstart prefix)
quickstart_configs . each { taskName , config - >
if ( config . isDebug ) {
def reloadTaskName = taskName . replaceFirst ( /^quickstart/ , "" )
tasks . register ( "${reloadTaskName}Reload" , Exec ) {
dependsOn tasks . named ( "prepareAll${taskName}" )
group = 'quickstart'
description = "Build and reload only changed containers for the ${taskName} task"
doFirst {
def executedTasks = project . gradle . taskGraph . allTasks . findAll { it . state . executed }
def containersToRestart = [ ]
moduleToContainer . each { modulePath , containerName - >
def moduleProject = project . project ( modulePath )
def dockerPrepareTask = moduleProject . tasks . findByName ( 'dockerPrepare' )
if ( dockerPrepareTask & & executedTasks . contains ( dockerPrepareTask ) & & ! dockerPrepareTask . state . upToDate ) {
containersToRestart < < "${containerName}-${config.profile}"
}
}
// Only restart containers that had their modules rebuilt
if ( containersToRestart ) {
2025-07-26 10:09:02 -05:00
def composeFiles = dockerCompose . "${taskName}" . useComposeFiles . get ( )
def composeFileArgs = composeFiles . collectMany { [ '-f' , it ] }
def cmd = [ "docker compose -p ${project_name} --profile ${config.profile}" ] + composeFileArgs + [ 'restart' ] + containersToRestart
2025-04-07 10:13:07 +05:30
println ( cmd . join ( " " ) )
2025-04-02 11:51:10 +05:30
commandLine 'bash' , '-c' , cmd . join ( " " )
} else {
// If no containers need restart, make this a no-op
commandLine 'bash' , '-c' , 'echo "No containers need restarting - all modules are up to date"'
}
}
}
2025-04-25 08:12:41 +05:30
tasks . register ( "${reloadTaskName}ReloadEnv" , Exec ) {
dependsOn tasks . named ( "prepareAll${taskName}" )
group = 'quickstart'
description = "Build changed containers but recreate all services for the ${taskName} task"
doFirst {
def containersToRestart = [ ]
moduleToContainer . each { modulePath , containerName - >
// Find which of of the reloadable modules are in used in this task
if ( config . modules . contains ( modulePath ) ) {
containersToRestart < < "${containerName}-${config.profile}"
}
}
2025-07-26 10:09:02 -05:00
def composeFiles = dockerCompose . "${taskName}" . useComposeFiles . get ( )
def composeFileArgs = composeFiles . collectMany { [ '-f' , it ] }
def cmd = [ "docker compose -p ${project_name} --profile ${config.profile}" ] + composeFileArgs + [ 'up' , '-d' , '--no-deps' ] + containersToRestart
2025-04-25 08:12:41 +05:30
println ( cmd . join ( " " ) )
commandLine 'bash' , '-c' , cmd . join ( " " )
}
}
2025-04-02 11:51:10 +05:30
}
}