Skip to content

Commit

Permalink
feat: API for nested settings reading (#290)
Browse files Browse the repository at this point in the history
* feat: API for nested settings reading

* docs: correct Kotlin example

Co-authored-by: Michal Augustýn <[email protected]>
  • Loading branch information
augi and augi authored Apr 8, 2021
1 parent 5cafffe commit 03e12df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ dockerCompose {
```kotlin
dockerCompose {
// settings as usual
createNested("myNested").apply {
nested("myNested").apply {
useComposeFiles = listOf("docker-compose-for-integration-tests.yml")
isRequiredBy(project.tasks.named("myTask").get())
}
}
```
```

</details>


Expand All @@ -177,12 +177,23 @@ dockerCompose {
* Configuration of the nested settings defaults to the main `dockerCompose` settings (declared before the nested settings), except following properties: `projectName`, `startedServices`, `useComposeFiles`, `scale`, `captureContainersOutputToFile`, `captureContainersOutputToFiles`, `composeLogToFile`, `containerLogToDir`, `pushServices`

When exposing service info from `myNestedComposeUp` task into your task you should use following syntax:
```
```groovy
test.doFirst {
dockerCompose.myNested.exposeAsEnvironment(test)
dockerCompose.myNested.exposeAsEnvironment(test)
}
```

<details>
<summary>Kotlin</summary>

```kotlin
test.doFirst {
dockerCompose.nested("myNested").exposeAsEnvironment(project.tasks.named("test").get())
}
```

</details>

It's also possible to use this simplified syntax:
```gradle
dockerCompose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ class ComposeExtension extends ComposeSettings {
private HashMap<String, ComposeSettings> settings = [:]

private ComposeSettings getOrCreateNested(String name) {
settings.computeIfAbsent(name, { createNested(name) })
settings.computeIfAbsent(name, { cloneAsNested(name) })
}

ComposeSettings createNested(String name) {
getOrCreateNested(name)
}

ComposeSettings nested(String name) {
getOrCreateNested(name)
}

def propertyMissing(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ComposeSettings {
"${fullPathMd5}_${project.name}"
}

ComposeSettings createNested(String name) {
protected ComposeSettings cloneAsNested(String name) {
def r = new ComposeSettings(project, name, this.nestedName)
r.buildBeforeUp = this.buildBeforeUp
r.buildBeforePull = this.buildBeforePull
Expand Down

0 comments on commit 03e12df

Please sign in to comment.