|
12 | 12 | * [Notice for Docker on Windows](#notice-for-docker-on-windows) |
13 | 13 | * [Notice for Docker Toolbox](#notice-for-docker-toolbox) |
14 | 14 | * [Configuration](#configuration) |
| 15 | + * [Docker compose file](#docker-compose-file) |
| 16 | + * [DSL options](#dsl-options) |
15 | 17 | * [Health checks](#health-checks) |
16 | 18 | * [Task environmentUp](#task-environmentup) |
17 | 19 | * [Task environmentDown](#task-environmentdown) |
|
23 | 25 |
|
24 | 26 | ## About |
25 | 27 |
|
26 | | -Provides seamless Gradle integration with Docker & Swarm. |
| 28 | +Provides seamless Gradle integration with Docker & Swarm. Hides many OS-specific glitches from unexperienced Docker users. |
27 | 29 |
|
28 | | -Controls virtualized environment consisting of Apache Web Server (HTTPD). |
29 | | -Web Server is deployed as [Docker Container](https://www.docker.com/resources/what-container) orchestrated by [Swarm](https://docs.docker.com/engine/swarm/). This solution is cross-platform just like Docker. |
| 30 | +Controls virtualized environment consisting of any Docker-compatible software (e.g Apache Web Server (HTTPD), SQL/noSQL databases). |
| 31 | +Such software is deployed as [Docker Containers](https://www.docker.com/resources/what-container) orchestrated by [Swarm](https://docs.docker.com/engine/swarm/). This solution is cross-platform just like Docker. |
30 | 32 |
|
31 | 33 | Provides environment related tasks: `environmentUp`, `environmentDev`, `environmentHosts` etc. |
32 | 34 |
|
@@ -67,7 +69,52 @@ As a consequence, if project is located outside of *C:/Users* directory, there i |
67 | 69 |
|
68 | 70 | ## Configuration |
69 | 71 |
|
70 | | -Illustrative example: |
| 72 | +### Docker compose file |
| 73 | + |
| 74 | +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*) |
| 75 | + |
| 76 | +```yml |
| 77 | +version: "3" |
| 78 | +services: |
| 79 | + httpd: |
| 80 | + image: centos/httpd:latest |
| 81 | + command: ["tail", "-f", "--retry", "/usr/local/apache2/logs/error.log"] |
| 82 | + deploy: |
| 83 | + replicas: 1 |
| 84 | + ports: |
| 85 | + - "80:80" |
| 86 | + networks: |
| 87 | + - docker-net |
| 88 | + volumes: |
| 89 | + - "{{ docker.rootPath }}/env/src/environment/httpd/conf/httpd.conf:/etc/httpd/conf/httpd.conf" |
| 90 | + - "{{ docker.rootPath }}/app/aem/dispatcher/src/conf.d:/etc/httpd/conf.d" |
| 91 | + - "{{ docker.rootPath }}/app/aem/dispatcher/src/conf.dispatcher.d:/etc/httpd/conf.dispatcher.d" |
| 92 | + - "{{ docker.workPath }}/httpd/modules/mod_dispatcher.so:/etc/httpd/modules/mod_dispatcher.so" |
| 93 | + - "{{ docker.workPath }}/httpd/logs:/etc/httpd/logs" |
| 94 | + {% if docker.runtime.safeVolumes %} |
| 95 | + - "{{ docker.workPath }}/httpd/cache:/var/www/localhost/cache" |
| 96 | + - "{{ docker.workPath }}/httpd/htdocs:/var/www/localhost/htdocs" |
| 97 | + {% endif %} |
| 98 | + {% if docker.runtime.hostInternalIpMissing %} |
| 99 | + extra_hosts: |
| 100 | + - "host.docker.internal:{{ docker.runtime.hostInternalIp }}" |
| 101 | + {% endif %} |
| 102 | +networks: |
| 103 | + docker-net: |
| 104 | +``` |
| 105 | +
|
| 106 | +Docker has differences in case of how it works on different operating systems. While using templating and [variables](src/main/kotlin/com/cognifide/gradle/environment/docker/Docker.kt#L46) in that file, Gradle Environment Plugin tries to mitigate these differences, to make your build working smoothly on all OSes and hide glitches from unexperienced Docker users. For example, when using Docker Toolbox, paths should be absolute and having Unix separators despite that host OS is Windows. |
| 107 | +
|
| 108 | +Example above comes from [that file](https://github.com/Cognifide/gradle-aem-multi/blob/master/env/src/environment/docker-compose.yml.peb) which is setting up Apache HTTPD for [Adobe Experience Manager](https://www.adobe.com/pl/marketing/experience-manager.html). |
| 109 | +
|
| 110 | +### DSL options |
| 111 | +
|
| 112 | +Moreover, plugin comes with rich DSL which allows to: |
| 113 | +
|
| 114 | +* run callbacks on each container lifecycle event (resolve, up, reload, dev), |
| 115 | +* configure where container resources are stored, |
| 116 | +* 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. |
71 | 118 |
|
72 | 119 | ```kotlin |
73 | 120 | environment { // config for AEM environment running on Docker |
@@ -163,7 +210,26 @@ Reloads virtualized environment by reloading all Docker containers (e.g. removin |
163 | 210 |
|
164 | 211 | ## Task `environmentHosts` |
165 | 212 |
|
166 | | -Appends environment specific hosts entries to OS specific hosts file. |
| 213 | +Prints hosts entries to be appended to OS-specific file. |
| 214 | + |
| 215 | +Example configuration: |
| 216 | + |
| 217 | +```kotlin |
| 218 | +environment { |
| 219 | + 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") } |
| 223 | + } |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 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. |
| 228 | + |
| 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: |
| 230 | + |
| 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). |
167 | 233 |
|
168 | 234 | ## License |
169 | 235 |
|
|
0 commit comments