Skip to content

Commit cebb99b

Browse files
author
Krystian Panek
committed
Hosts lazy / setup better lifecycle
1 parent f9ba297 commit cebb99b

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

README.MD

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ As of plugin is published at official Gradle Plugin Portal, see instructions fro
4242

4343
Most of the configuration steps are automated. However, there are three manual steps to make this setup fully operating:
4444

45-
1. [Install Docker](https://docs.docker.com/install/)
45+
* [Install Docker](https://docs.docker.com/install/)
4646
* [Mac](https://docs.docker.com/docker-for-mac/)
4747
* [Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
4848
* Windows
4949
* [Desktop](https://docs.docker.com/docker-for-windows/install/) (highly recommended, using Hyper-V)
5050
* [Toolbox](https://docs.docker.com/toolbox/toolbox_install_windows/) (legacy, using VirtualBox)
5151

52-
2. Setup hosts on local machine (admin rights are required to access `/etc/hosts` or `C:\Windows\System32\drivers\etc\hosts` file)
53-
* Unix: execute `sudo gradlew environmentHosts --no-daemon`
54-
* Windows: start PowerShell with "Run as administrator", then execute `./gradlew.bat environmentHosts --no-daemon`
55-
52+
5653
### Notice for Docker on Windows
5754

5855
Ensure having shared folders enabled via GUI:
@@ -73,7 +70,7 @@ As a consequence, if project is located outside of *C:/Users* directory, there i
7370

7471
To configure containers to be deployed using Docker Swarm, simply create standard Docker Compose file but with templating (file at path *src/environment/docker-compose.yml.peb*)
7572

76-
```yml
73+
```pebble
7774
version: "3"
7875
services:
7976
httpd:
@@ -114,14 +111,14 @@ Moreover, plugin comes with rich DSL which allows to:
114111
* run callbacks on each container lifecycle event (resolve, up, reload, dev),
115112
* configure where container resources are stored,
116113
* configure health checks to be able to detect moment in build lifecycle when are container services are stable and be ready to perform next build tasks using these services,
117-
* configure hosts which should be apended to OS-specific hosts file.
114+
* configure hosts which should be appended to OS-specific hosts file.
118115

119116
```kotlin
120117
environment { // config for AEM environment running on Docker
121118
rootDir.set(prop.string("environment.rootDir")) // project.file(".environment")
122119
hosts { // domains to be appended to hosts file automatically
123120
"http://example.com" { tag("publish") }
124-
"http://locahost:4502 { tag("author") }
121+
"http://locahost:4502" { tag("author") }
125122
}
126123
docker { // Docker specific configuration
127124
containers {
@@ -210,26 +207,28 @@ Reloads virtualized environment by reloading all Docker containers (e.g. removin
210207

211208
## Task `environmentHosts`
212209

213-
Prints hosts entries to be appended to OS-specific file.
210+
Amends hosts entries in OS-specific file.
214211

215212
Example configuration:
216213

217214
```kotlin
218215
environment {
219216
hosts { // domains to be appended to hosts file automatically
220-
"http://example.com" { tag("live site") }
221-
"http://locahost:4502" { tag("cms authoring") }
222-
"http://locahost:8080" { tag("dbms") }
217+
"example.com" { tag("live site") }
218+
"demo.example.com" { tag("demo site") }
219+
"cms" { tag("cms authoring") }
223220
}
224221
}
225222
```
226223

227-
Result of running task `environmentHosts` will be an list of IP-domain pairs which should be appended to OS-specific file (e.g /etc/hosts on Unix). When using Docker Toolbox on Windows, IP may be different, as of it is using extra VM to run Docker and IP of that VM should be used instead of loopback IP (localhost / 127.0.0.1). Plugin is trying to make this difference transparent for build users.
224+
The task will run on Windows & Mac OS interactive process asking for administrative/sudo permissions to be able to edit the hosts file.
225+
On other OSes / Unix-based systems, the task will print a path to the generated script to be executed with sudo rights but in a non-interactive way (to be done separately right after this task execution.
228226

229-
Consider creating scripts which will run this task and amend output to OS-specific hosts file automatically with requesting admin/sudo permissions. See examples for:
227+
Options:
230228

231-
* [Windows](https://github.com/Cognifide/gradle-aem-multi/blob/master/env/hosts.bat),
232-
* [Unix](https://github.com/Cognifide/gradle-aem-multi/blob/master/env/hosts).
229+
- `hosts.updater.enabled=false` - allows to disable temporarily host amendmend (e.g on CI/CD),
230+
- `hosts.updater.interactive=false` - potentially useful when interactive mode does not work for unknown/OS-specific reason,
231+
- `hosts.updater.force=true` - by default, updater is lazy - it will not ask for administrative/sudo mode if the hosts file does not need to be updated.
233232

234233
## License
235234

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
2727
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
2828

29-
implementation("com.cognifide.gradle:common-plugin:1.0.2")
29+
implementation("com.cognifide.gradle:common-plugin:1.0.3")
3030
implementation("org.buildobjects:jproc:2.3.0")
3131
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
3232
implementation("org.apache.commons:commons-lang3:3.9")

src/main/kotlin/com/cognifide/gradle/environment/EnvironmentPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class EnvironmentPlugin : CommonDefaultPlugin() {
4444
mustRunAfter(up)
4545
}
4646
val await = register<EnvironmentAwait>(EnvironmentAwait.NAME) {
47-
mustRunAfter(up)
47+
mustRunAfter(hosts, up)
4848
}
4949
register<EnvironmentReload>(EnvironmentReload.NAME) {
5050
mustRunAfter(up)
@@ -65,7 +65,7 @@ class EnvironmentPlugin : CommonDefaultPlugin() {
6565
dependsOn(restart)
6666
}
6767
named<Setup>(Setup.NAME) {
68-
dependsOn(up)
68+
dependsOn(hosts, up, await)
6969
}
7070
named<Resetup>(Resetup.NAME) {
7171
dependsOn(resetup)

0 commit comments

Comments
 (0)