Skip to content

Commit

Permalink
allow specifying projectNamePrefix
Browse files Browse the repository at this point in the history
closes avast#231
  • Loading branch information
Brice Burgess committed May 5, 2020
1 parent 6182bad commit 139aa78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -109,7 +109,8 @@ dockerCompose {
removeVolumes = true // default is true
removeOrphans = false // removes containers for services not defined in the Compose file; default is false
projectName = 'my-project' // allow to set custom docker-compose project name (defaults to a stable name derived from absolute path of the project and nested settings name), set to null to Docker Compose default (directory name)
projectName = 'my-project' // allow to set custom docker-compose project name (defaults to projectNamePrefix-project.name-nested_project.name), set to null to Docker Compose default (directory name)
projectNamePrefix = 'build-88' // used to create a safe projectName. if empty it will be derived from absolute path of the project
executable = '/path/to/docker-compose' // allow to set the path of the docker-compose executable (useful if not present in PATH)
dockerExecutable = '/path/to/docker' // allow to set the path of the docker executable (useful if not present in PATH)
dockerComposeWorkingDirectory = '/path/where/docker-compose/is/invoked/from'
Expand Down
Expand Up @@ -64,6 +64,7 @@ class ComposeSettings {
List<String> upAdditionalArgs = []
List<String> downAdditionalArgs = []
String projectName
String projectNamePrefix

boolean stopContainers = true
boolean removeContainers = true
Expand Down Expand Up @@ -98,7 +99,7 @@ class ComposeSettings {
this.composeExecutor = new ComposeExecutor(this)
this.serviceInfoCache = new ServiceInfoCache(this)

this.projectName = this.projectName ?: generateProjectName(project, name)
this.projectName = this.projectName ?: generateProjectName(project, name, this.projectNamePrefix)

this.containerLogToDir = project.buildDir.toPath().resolve('containers-logs').toFile()

Expand All @@ -110,9 +111,10 @@ class ComposeSettings {
}
}

private static String generateProjectName(Project project, String name) {
def fullPathMd5 = MessageDigest.getInstance("MD5").digest(project.projectDir.absolutePath.toString().getBytes(StandardCharsets.UTF_8)).encodeHex().toString()
"${fullPathMd5}_${project.name}_${name}"
private static String generateProjectName(Project project, String name, String prefix) {
def safe_prefix = prefix ?: MessageDigest.getInstance("MD5")
.digest(project.projectDir.absolutePath.toString().getBytes(StandardCharsets.UTF_8)).encodeHex().toString()
"${safe_prefix}_${project.name}_${name}"
}

ComposeSettings createNested(String name) {
Expand Down

0 comments on commit 139aa78

Please sign in to comment.