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

Feature/gradle support #12

Merged
merged 8 commits into from Jul 5, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -72,6 +72,11 @@ settings.json
*.vlt
*.vertx

# Gradle
.gradle
build
!gradle/wrapper/gradle-wrapper.jar

target
atlassian-ide-plugin.xml
bin/
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
@@ -1,7 +1,11 @@
sudo: required
language: java
install: true
script: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Pskip-integration-tests,release
before_script:
- chmod +x ./gradlew
script:
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Pskip-integration-tests,release
- ./gradlew
jdk:
- oraclejdk8
cache:
Expand Down
75 changes: 60 additions & 15 deletions README.md
@@ -1,31 +1,67 @@
[![][travis img]][travis]
[![][license img]][license]

# Running the Knot.x example project
# Knot.x example project
The example project shows how you can use Knot.x and develop it in a real project. Uses the
[Knot.x Stack](https://github.com/Knotx/knotx-stack) distribution and provides custom configuration
files, sample content and modules.

## Prerequisites
- JDK 8+
- Maven or Gradle

## Getting started
The example project consists of:

Knot.x Example Project contains both custom modules, a sample content and mocked HTTP data sources
(REST endpoints). Open the browser for:
- `http://localhost:8092/content/simple.html`
- `http://localhost:8092/content/login/step1.html`
- `acme-stack` - contains all configuration files and the sample content
- `acme-action-adapter-http` - handles forms submit requests (POSTs), executes business logic and redirects to the next step / confirmation page / stay on the same page
- `acme-gateway` - provides the Gateway API interface that can be used by front-end integration
- `acme-handlebars-ext` - adds custom Handlebars directives
- `acme-sample-service` - runs the HTTP server on the `3000` port, which mocks real JSON service responses

to see the example is running.
The `acme-stack` module contains all required artifacts to build the example distribution. The result
of the build process is a ZIP file that you can deploy to the server, extract and run with
`bin\knotx run-knotx`. The `run-knotx` command starts all Knot.x modules, configures logs, and sets
Java options. Note that all dependencies like `acme-action-adapter-http`, `acme-gateway`,
`acme-handlebars-ext` and `acme-sample-service` are build and copied to the distribution.

### Run locally
### How to build
Clone the repository and build the example project:

#### Maven build

Let's run the command below:
```
$> mvn package
```
The distribution ZIP file location is `acme-stack/target/knotx-example-project-stack-X.X.X.zip`.

#### Gradle build
Let's run the command below:
```
$> gradlew
```
The distribution ZIP file location is `acme-stack/build/distributions/knotx-example-project-stack-X.X.X.zip`

### How to run
- Download and unpack latest [knotx-example-project-stack](https://bintray.com/knotx/downloads/examples)
- Alternatively, clone the repository and build the example project `mvn clean install`,
unpack the zip file from `knotx-example-project/acme-stack/target` to any folder
- Go to the `acme-stack` folder in the unpacked zip file and run the Knot.x
or
- clone the repository and build the example project

#### Run locally:
Go to the `acme-stack` folder in the unpacked zip file and run the Knot.x script

##### Unix and MacOS
```
$> cd acme-stack
$> bin/knotx run-knotx
```

### Run docker
##### Windows
```
$> bin\knotx.bat run-knotx
```

#### Run docker
Build image from dockerfile being in the `knotx-example-project` folder
```
$> docker build -t acme/knotx-example .
Expand All @@ -40,14 +76,23 @@ Follow logs
$> docker logs -f knotx-example
```

Open the browser for `http://localhost:8092/content/simple.html` URL to see the example is running.

### Run Knot.x cluster
#### Run Knot.x cluster
Clone this repository and go to `acme-cluster` folder and run the Knot.x cluster
```
$> docker-compose up
```

### How to verify

Knot.x works in two modes:
- templating engine with custom business logic that integrates with any data source using
[Knot.x Data Bridge](https://github.com/Knotx/knotx-data-bridge) and
[Handlebars](https://github.com/Cognifide/knotx/wiki/HandlebarsKnot) (back-end integration)
- [http://localhost:8092/content/simple.html](http://localhost:8092/content/simple.html)
- [http://localhost:8092/content/login/step1.html](http://localhost:8092/content/login/step1.html)
- [Gateway mode](https://github.com/Cognifide/knotx/wiki/GatewayMode) providing REST API (front-end integration)
- [http://localhost:8092/customFlow/](http://localhost:8092/customFlow/)

[travis]:https://travis-ci.org/Knotx/knotx-example-project
[travis img]:https://travis-ci.org/Knotx/knotx-example-project.svg?branch=master

Expand Down
27 changes: 27 additions & 0 deletions acme-action-adapter-http/build.gradle
@@ -0,0 +1,27 @@
plugins {
id 'java'
}

description = 'Acme Project - Action Adapter HTTP'

defaultTasks 'build'

dependencies {
implementation 'io.knotx:knotx-core'
implementation 'io.knotx:knotx-adapter-common'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web-client'
implementation 'io.vertx:vertx-rx-java2'
implementation 'io.vertx:vertx-service-proxy'

testCompile 'junit:junit'
testCompile 'org.powermock:powermock-api-mockito'
testCompile 'org.powermock:powermock-module-junit4'
testCompile 'org.hamcrest:hamcrest-all'
testCompile 'org.mockito:mockito-all'
testCompile 'io.vertx:vertx-unit'
testCompile 'io.vertx:vertx-config'

testCompile 'io.knotx:knotx-core::tests'
testCompile "io.knotx:knotx-mocks:$knotxVersion"
}
14 changes: 14 additions & 0 deletions acme-gateway/build.gradle
@@ -0,0 +1,14 @@
plugins {
id 'java'
}

description = 'Acme Project - Sample Gateway'

defaultTasks 'build'

dependencies {
implementation 'io.knotx:knotx-core'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-rx-java2'
implementation 'io.vertx:vertx-service-proxy'
}
11 changes: 11 additions & 0 deletions acme-handlebars-ext/build.gradle
@@ -0,0 +1,11 @@
plugins {
id 'java'
}

description = 'Acme Project - Knot.x handlebars extensions'

defaultTasks 'build'

dependencies {
implementation 'io.knotx:knotx-knot-handlebars'
}
13 changes: 13 additions & 0 deletions acme-sample-service/build.gradle
@@ -0,0 +1,13 @@
plugins {
id 'java'
}

description = 'Acme Project - Sample service'

defaultTasks 'build'

dependencies {
implementation 'io.knotx:knotx-core'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
}
11 changes: 11 additions & 0 deletions acme-stack/build.gradle
@@ -0,0 +1,11 @@
plugins {
id 'base'
}

apply from: "${rootProject.projectDir}/acme-stack/knotx-assemble-distribution.gradle"

task assembleKnotx() {
group = 'knotx'

dependsOn = ['assembleDistributionWithDeps']
}
69 changes: 69 additions & 0 deletions acme-stack/knotx-assemble-distribution.gradle
@@ -0,0 +1,69 @@
def downloadDir = file("${buildDir}/download")
def distributionDir = file("${buildDir}/out")
def stackName = "acme-stack"
def acmeDistribution = "knotx-example-project-stack-${version}.zip"

configurations {
zipped
deps
}

dependencies {
zipped group: 'io.knotx', name: 'knotx-stack-manager', version: knotxVersion, ext: 'zip'
deps project(':acme-gateway')
deps project(':acme-handlebars-ext')
deps project(':acme-action-adapter-http')
deps project(':acme-sample-service')
}

task cleanDistribution(type: Delete) {
delete downloadDir, distributionDir
}

task downloadDistribution(type: Copy) {
from configurations.zipped
into downloadDir
}

task unzipDistribution(type: Copy) {
def zipPath = project.configurations.zipped.find { it.name.startsWith('knotx-stack-manager') }
from zipTree(zipPath)
into distributionDir
}

task renameDistribution {
doLast {
file("${distributionDir}/knotx").renameTo(file("${distributionDir}/${stackName}"))
}
}

task overrideConfigurations(type: Copy) {
from file("src/main/descriptor/knotx-stack.json")
into file("${distributionDir}/${stackName}")
}

task overrideDesciptor(type: Copy) {
from file('src/main/packaging')
into file("${distributionDir}/${stackName}")
}

task downloadDeps(type: Copy) {
from configurations.deps
into "${distributionDir}/${stackName}/lib"
}

task assembleDistributionWithDeps(type: Zip) {
from distributionDir
archiveName acmeDistribution
}

downloadDistribution.dependsOn(cleanDistribution)
unzipDistribution.dependsOn(downloadDistribution)
renameDistribution.dependsOn(unzipDistribution)
overrideConfigurations.dependsOn(renameDistribution)
overrideDesciptor.dependsOn(overrideConfigurations)
downloadDeps.dependsOn(overrideDesciptor)
assembleDistributionWithDeps.dependsOn(downloadDeps)

build.dependsOn(assembleDistributionWithDeps)
clean.dependsOn(cleanDistribution)
22 changes: 22 additions & 0 deletions build.gradle
@@ -0,0 +1,22 @@
defaultTasks 'build'

allprojects {
version = '1.3.1-SNAPSHOT'

repositories {
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}

ext {
knotxVersion = project.version
}

subprojects {
plugins.withId 'java', {
dependencies {
implementation "io.knotx:knotx-dependencies:$knotxVersion"
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
#Fri Jun 29 12:12:38 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip