Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Support for Knot.x setup in gradle aem multi #65

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
install: ./gradlew -i -S assemble
script: ./gradlew -i -S check
script: ./gradlew -i -S -Poffline=true check
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ Documentation for:

![Fork Props Dialog](docs/fork-props-dialog.png)

3. Setup local AEM instances with dependencies and AEM dispatcher (see [prerequisites](https://github.com/Cognifide/gradle-aem-plugin/tree/develop#environment-configuration)) then build application using command:
3. Setup the local DEV environment containing:
- AEM instances with dependencies
- AEM dispatcher (see [prerequisites](https://github.com/Cognifide/gradle-aem-plugin/tree/develop#environment-configuration))
- [Knot.x](https://github.com/Knotx/knotx) (see [prerequisites](https://github.com/Cognifide/gradle-aem-plugin/tree/develop#environment-configuration))

and build AEM application using command:

```bash
aem/hosts
Expand Down Expand Up @@ -128,6 +133,7 @@ Project is configured to have local environment which consists of:

* native AEM instances running on local file system,
* virtualized Apache HTTP Server with AEM Dispatcher module running on Docker ([official httpd image](https://hub.docker.com/_/httpd)).
* virtualized [Knot.x](https://github.com/Knotx/knotx) reactive integration framework running on Docker

Assumptions:

Expand All @@ -137,6 +143,7 @@ Assumptions:
* http://example.com -> which maps to `/content/example/live` content root on publish
* http://demo.example.com -> which maps to `/content/example/demo` content root on publish
* http://author.example.com -> which is proxy to the author instance
* http:://knotx.demo.example.com -> which maps to `/content/example/demo` content root on publish and [processes `<knotx:snippet>` tags](https://github.com/Knotx/knotx-fragments)

## Building

Expand Down Expand Up @@ -168,14 +175,29 @@ Task `setup` will:
* set up AEM environment (run HTTPD service on Docker) and install AEM dispatcher module
* build AEM application (compose assembly CRX package from many)
* migrate AEM application (for projects already deployed on production to upgrade JCR content in case of changed application behavior)
* clean AEM environment (restart HTTPD service then clean AEM dispatcher caches)
* clean AEM environment (restart HTTPD service then clean AEM dispatcher caches, restart Knot.x)
* check AEM environment (quickly check responsiveness of deployed application)
* run integration tests
* run functional tests

To sum up, all things needed by developer are fully automated in one place / Gradle build.
Still all separate concerns like running tests, only building application, only running tests, could be used separately by running particular Gradle tasks.

## Validation

### AEM mappings
You can check AEM Dispatcher url rewrites with:

[example.com/en-us.html](http://example.com/en-us.html)
[demo.example.com/en-us.html](http://demo.example.com/en-us.html)

### Knot.x Fragments processing
Fully static template page containing "dynamic" placeholder from Dispatcher:
[demo.example.com/products/details.html](http://demo.example.com/products/details.html)

Page containing data assembled by Knot.x:
[knotx.demo.example.com/products/details.html](http://knotx.demo.example.com/products/details.html)

## Tips & tricks

* To run some task only for subproject, use project path as a prefix, for instance: `gradlew :aem:site.demo:sync`.
Expand Down
7 changes: 5 additions & 2 deletions aem/gradle/environment.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ configure<AemExtension> {
"example.com",
"demo.example.com",
"author.example.com",
"dispatcher.example.com"
"dispatcher.example.com",
"knotx.demo.example.com"
)
distributions {
download("http://download.macromedia.com/dispatcher/download/dispatcher-apache2.4-linux-x86_64-4.3.2.tar.gz").then {
Expand All @@ -15,7 +16,8 @@ configure<AemExtension> {
}
directories {
regular(
"httpd/logs"
"httpd/logs",
"knotx/logs"
)
cache(
"httpd/cache/content/example/live",
Expand All @@ -27,6 +29,7 @@ configure<AemExtension> {
url("Demo site", "http://demo.example.com/en-us.html", text = "English")
url("Author login", "http://author.example.com/libs/granite/core/content/login.html" +
"?resource=%2F&\$\$login\$\$=%24%24login%24%24&j_reason=unknown&j_reason_code=unknown", text = "AEM Sign In")
url("Knot.x", "http://knotx.demo.example.com/products/details.html", text = "Content filled by Knot.x integration framework.")
}
}

Expand Down
10 changes: 10 additions & 0 deletions aem/gradle/environment/docker-compose.yml.peb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,15 @@ services:
extra_hosts:
- "host.docker.internal:10.0.2.2"
{% endif %}
knotx:
image: knotx/knotx:2.0.0-RC5
command: ["knotx", "run-knotx"]
volumes:
- "{{ environment.dockerConfigPath }}/knotx/conf:/usr/local/knotx/conf"
- "{{ environment.dockerRootPath }}/knotx/logs:/var/log/knotx"
ports:
- "8092:8092"
networks:
- docker-net
networks:
docker-net:
2 changes: 1 addition & 1 deletion aem/gradle/environment/httpd/conf/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ LoadModule dir_module modules/mod_dir.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule dispatcher_module modules/mod_dispatcher.so

<IfModule disp_apache2.c>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<VirtualHost *:80>
ServerName knotx.demo.example.com

RewriteEngine On

RewriteCond %{REQUEST_METHOD} =GET
RewriteRule ^(.*\.html)$ - [E=KNOTX_REQ:true]

RewriteCond %{ENV:KNOTX_REQ} ^true$
RewriteRule ^/(.*)$ http://knotx:8092/$1 [P,L]

RewriteRule ^/(.*)$ http://demo.example.com/$1 [P,L]

</VirtualHost>
12 changes: 12 additions & 0 deletions aem/gradle/environment/knotx/conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
########### Modules to start ###########
# Modules map specify a list of verticles to be started by Knot.x.
# Each line should have a form of <alias>=<verticle-class-name>
# where alias is just a name that you can use later in order to define configuration for the module
# verticle-class-name is a fully qualified class name of the verticle.
#
# This JSON object is filled in included files.
modules {}


include required(classpath("server.conf"))
include required(classpath("knots/templateEngineStack.conf"))
15 changes: 15 additions & 0 deletions aem/gradle/environment/knotx/conf/bootstrap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configRetrieverOptions": {
"scanPeriod": 5000,
"stores": [
{
"type": "file",
"format": "conf",
"config": {
"path": "${KNOTX_HOME}/conf/application.conf"
},
"optional": false
}
]
}
}
26 changes: 26 additions & 0 deletions aem/gradle/environment/knotx/conf/knots/templateEngineKnot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Vert.x event bus delivery options used when communicating with other verticles
address = knotx.knot.te.handlebars

engine {
factory = handlebars
config = {
# Algorithm used to build a hash key of the compiled handlebars snippets.
# The hash is computed for the snippet handlebars source code using a selected algorithm.
# The name should be a standard Java Security name (such as "SHA", "MD5", and so on).
# Default value is MD5
#
# cacheKeyAlgorithm = MD5

# Size of the compiled snippets cache. After reaching the max size, new elements will replace the oldest one.
cacheSize = 1000

# Symbol used as a start delimiter of handlebars expression. If not use, a default '{{' is used
#
# startDelimiter =

# Symbol used as a end delimiter of handlebars expression. If not use, a default '}}' is used
#
# endDelimiter =
}
}

11 changes: 11 additions & 0 deletions aem/gradle/environment/knotx/conf/knots/templateEngineStack.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
########### Data Bridge Stack ###########
modules {
templateEngine = "io.knotx.te.core.TemplateEngineKnot"
}

########### Modules configurations ###########
config.templateEngine {
options.config {
include required(classpath("knots/templateEngineKnot.conf"))
}
}
41 changes: 41 additions & 0 deletions aem/gradle/environment/knotx/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) 2019 Knot.x Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<configuration>
<property name="LOG_PATH" value="/var/log/knotx"/>

<include resource="io/knotx/logging/logback/defaults.xml"/>
<include resource="io/knotx/logging/logback/file-appender.xml"/>
<include resource="io/knotx/logging/logback/access.xml"/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<logger name="io.knotx" level="TRACE"/>
<logger name="io.vertx" level="TRACE"/>

<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
32 changes: 32 additions & 0 deletions aem/gradle/environment/knotx/conf/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Knot.x Stack OAS
description: This is the server API specification.

servers:
- url: https://{domain}:{port}
description: The local API server
variables:
domain:
default: localhost
description: api domain
port:
enum:
- '8092'
- '443'
default: '8092'

paths:
/products/*:
get:
operationId: products-get
responses:
default:
description: Remote repository template processing with http action and te
/assets/*:
get:
operationId: assets-get
responses:
default:
description: Return assets as is from the repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
########### This configuration is overloaded in integration tests! ###########
tasks {
hello-world {
action = hello-inline
onTransitions {
_success {
action = te-hbs
}
}
}
}

actions {
hello-inline {
factory = inline-payload
config {
alias = hello
payload {
_result {
message = "Content filled by Knot.x integration framework."
}
}
}
}
te-hbs {
factory = knot
config {
address = knotx.knot.te.handlebars
deliveryOptions {
sendTimeout = 3000
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Vert.x event bus delivery options used when communicating with other verticles
# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured
#
clientOptions {
maxPoolSize = 1000
idleTimeout = 120 # seconds
tryUseCompression = true

# If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure
# some aspects related to the SSL negotiation and validation.
#
# Whether all server certificated should be trusted or not (e.g. self-signed certificates)
# trustAll = true
#
# Hostname verification
# verifyHost = false
#
# It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination)
# forceSni = true
}

# HTTP Repository connection details
clientDestination {
# Connection scheme: http or https
scheme = http

# domain or the IP of the host: e.g. localhost, 10.0.11.2
domain = httpd

## Port on which the host listens, e.g. 8080, 3001, etc.
port = 80

# Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value.
hostHeader = demo.example.com
}

# List of allowed request headers that will be send to HTTP repository.
# Each item is a string that defines regex, e.g. to match any char use `.*`
#
allowedRequestHeaders = [
"Accept.*"
Authorization
Connection
Cookie
Date
"Edge.*"
"If.*"
Origin
Pragma
Proxy-Authorization
"Surrogate.*"
User-Agent
Via
"X-.*"
"Host.*"
]

# Statically defined HTTP request header sent in every request to the repository
customHttpHeader = {
name = X-User-Agent
value = Knot.x
}
Loading