Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: API for nested settings reading #290

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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