Skip to content

Commit

Permalink
Merge pull request #1 from ManfredKarrer/http-api
Browse files Browse the repository at this point in the history
Integration and refactorings
  • Loading branch information
blabno authored Sep 13, 2018
2 parents f26b021 + e13e904 commit 3f5004b
Show file tree
Hide file tree
Showing 221 changed files with 4,858 additions and 3,690 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ docker/prod/Dockerfile

target
support

build
out
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Maven
target/

# Gradle
.gradle
build

# Idea
.idea/
*.iml
target/

# macOS
.DS_Store

# Vim
*.sw[op]

out/
16 changes: 4 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,16 @@ services:
env:
- CUBE_LOGGER_ENABLE=true

# These env variables start 2 parallel builds.
#
# The neat part about this setup is that the unit test suite is usually going to be done before
# the integration test suite, giving you a faster visual feedback on the basic test coverage.
#env:
# - MVN_COMMAND="mvn clean install -Dmaven.javadoc.skip=true -B -V"
# - MVN_COMMAND="docker-compose build;mvn verify -P integration"

jobs:
include:
- stage: test
script: "mvn clean install -Dmaven.javadoc.skip=true -B -V"
script: ./gradlew test
- stage: integration
script:
docker-compose build;
mvn dependency:resolve -P integration compile exec:java -Dexec.mainClass="network.bisq.api.app.ApiMain" -Dexec.args="--help";
docker volume create m2;
docker container create -v m2:/m2 --name m2helperContainer busybox;
docker cp ~/.m2/repository m2helperContainer:/m2/;
docker rm m2helperContainer;
mvn verify -P integration
./gradlew build -x test;
sh create-docker-volumes.sh;
./gradlew testIntegration;
37 changes: 6 additions & 31 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ see it in action (pretty outdated).
## Prerequisites

* Java 8
* Maven 3.5+


## Bisq configuration
Expand All @@ -31,25 +30,13 @@ Changing the appname can fix this issue.

## Compiling the API

This step needs to be done before you can start the API with UI or headless:

mvn clean install


## Getting started: with UI

The following command will start a GUI Bisq instance on
Bitcoin mainnet (meaning you can lose real BTC):

mvn compile exec:java -Dexec.mainClass="network.bisq.api.app.BisqApiWithUIMain"


## Getting started: headless

The following command will start a headless Bisq instance on
Bitcoin mainnet (meaning you can lose real BTC):

mvn compile exec:java -Dexec.mainClass="network.bisq.api.app.ApiMain"
./gradlew run


## Developing
Expand All @@ -58,9 +45,7 @@ When testing it is advisable to run Bisq in REGTEST mode.
See below on how to pass Bisq arguments to enable REGTEST mode.
All regular Bisq arguments can be used.

mvn compile exec:java \
-Dexec.mainClass="network.bisq.api.app.BisqApiWithUIMain" \
-Dexec.args="--baseCurrencyNetwork=BTC_REGTEST --bitcoinRegtestHost localhost --nodePort 2003 --seedNodes=localhost:2225 --useLocalhost true --appName Bisq-Regtest-Bob"
./gradlew run --args ' --baseCurrencyNetwork=BTC_REGTEST --bitcoinRegtestHost localhost --nodePort 2003 --seedNodes=localhost:2225 --useLocalhost true --appName Bisq-Regtest-Bob'


## Exploring the HTTP API
Expand All @@ -84,7 +69,7 @@ Set the environment variable `BISQ_API_PORT` to your desired port.
Set the environment variable `BISQ_API_HOST` to your desired host.
You might also pass program args: `apiPort` and `apiHost`.


#TODO this is invalid instruction. We want to restore it once those params get to BisqEnvironment in core
mvn compile exec:java \
-Dexec.mainClass="network.bisq.api.app.BisqApiWithUIMain" \
-Dexec.args="--apiPort=8000 --apiHost=localhost"
Expand All @@ -108,12 +93,9 @@ If you want to build your own production image instead of pulling it from docker

## Docker for developers

Since maven dependencies are being fetched after container is started you can seed 'm2' volume used for caching local maven repo:
Since maven and gradle dependencies are being fetched after container is started you can seed 'm2' and 'gradle' volumes used for caching local maven repo:

docker volume create m2
docker container create -v m2:/m2 --name m2helperContainer busybox
docker cp ~/.m2/repository m2helperContainer:/m2/
docker rm m2helperContainer
sh create-docker-volumes.sh

Build bisq-api image:

Expand All @@ -140,14 +122,7 @@ You have to build bisq-api image before running integration tests.
Run integration tests:

docker-compose build #just make sure our images are up to date
mvn verify -P integration


## Build

In order to build shaded jar:

mvn package -P shade
./gradlew test


## Api naming guidelines:
Expand Down
114 changes: 114 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
plugins {
id 'java'
id 'maven'
id 'application'
}

group = 'network.bisq'
version = '-SNAPSHOT'

sourceCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

mainClassName = 'bisq.httpapi.app.HttpApiMain'

repositories {
mavenLocal()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://raw.githubusercontent.com/JesusMcCloud/tor-binary/master/release/' }
maven { url 'https://repo.maven.apache.org/maven2' }
maven { url 'https://dl.bintray.com/jerady/maven' }
}

dependencies {
compile 'network.bisq:bisq-common:-SNAPSHOT'
compile 'network.bisq:bisq-assets:-SNAPSHOT'
compile 'network.bisq:bisq-core:-SNAPSHOT'
compile 'network.bisq:bisq-p2p:-SNAPSHOT'

compile "io.dropwizard:dropwizard-core:1.2.2"
compile "io.dropwizard:dropwizard-forms:1.2.2"
compile "io.dropwizard:dropwizard-jackson:1.2.2"
compile "io.dropwizard:dropwizard-jersey:1.2.2"
compile "io.dropwizard:dropwizard-util:1.2.2"

runtime 'org.bouncycastle:bcprov-jdk15on:1.56'
compileOnly 'org.projectlombok:lombok:1.16.16'
annotationProcessor 'org.projectlombok:lombok:1.16.16'
testCompile 'junit:junit:4.12'
testCompile('org.mockito:mockito-core:2.8.9') {
exclude(module: 'objenesis')
}
testCompile 'org.powermock:powermock-module-junit4:1.7.1'
testCompile 'org.powermock:powermock-api-mockito2:1.7.1'
testCompile 'org.jmockit:jmockit:1.30'
testCompile 'org.springframework:spring-test:4.3.6.RELEASE'
testCompile 'com.natpryce:make-it-easy:4.0.1'
testCompileOnly 'org.projectlombok:lombok:1.16.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.16.16'

// Converted from Bisq-API projects maven file (http://sagioto.github.io/maven2gradle/)
// TODO add exclusions
compile "com.google.guava:guava:20.0"
compile "com.fasterxml.jackson.core:jackson-databind:2.9.1"
compile "com.fasterxml.jackson.core:jackson-core:2.9.1"
compile "com.fasterxml.jackson.core:jackson-annotations:2.9.1"
compile "javax.xml.bind:jaxb-api:2.3.0"
compile "org.projectlombok:lombok:1.16.18"
compile "org.slf4j:slf4j-api:1.7.22"
compile "ch.qos.logback:logback-core:1.1.10"
compile "ch.qos.logback:logback-classic:1.1.10"
testCompile "junit:junit:4.12"
testCompile "org.mockito:mockito-core:2.7.5"
testCompile "org.jmockit:jmockit:1.30"
testCompile "com.github.javafaker:javafaker:0.14"
testCompile "org.arquillian.universe:arquillian-junit:1.2.0.1"
testCompile "org.arquillian.universe:arquillian-cube-docker:1.2.0.1"
testCompile "org.arquillian.cube:arquillian-cube-docker:1.15.3"
testCompile "io.rest-assured:rest-assured:3.0.2"

compile "com.smoketurner:dropwizard-swagger:1.2.2-2"
}

sourceSets {
testIntegration {
java.srcDir 'src/testIntegration/java'
resources.srcDir 'src/testIntegration/resources'
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}

task testIntegration(type: Test) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = 'Runs the integration tests.'

maxHeapSize = '1024m'

testClassesDir = sourceSets.testIntegration.output.classesDir
classpath = sourceSets.testIntegration.runtimeClasspath

binResultsDir = file("$buildDir/integration-test-results/binary/testIntegration")

reports {
html.destination = "$buildDir/reports/integration-test"
junitXml.destination = "$buildDir/integration-test-results"
}

systemProperties = [
CUBE_LOGGER_ENABLE: System.getenv('CUBE_LOGGER_ENABLE')
]

testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'

mustRunAfter tasks.test
}

build.dependsOn installDist
installDist.destinationDir = file('build/app')
distZip.enabled = false
7 changes: 7 additions & 0 deletions create-docker-volumes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
docker container create -v m2:/m2 -v gradle:/gradle --name m2helperContainer busybox
docker cp ~/.m2/repository m2helperContainer:/m2/
for dir in `ls ~/.gradle` ; do
docker cp ~/.gradle/$dir m2helperContainer:/gradle/
done
docker rm m2helperContainer
1 change: 1 addition & 0 deletions docker-compose-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
image: bisq-api
volumes:
- m2:/root/.m2
- gradle:/root/.gradle-volume
environment:
- LOG_LEVEL=debug
- USE_LOCALHOST_FOR_P2P=true
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ services:
volumes:
m2:
name: m2
gradle:
name: gradle
1 change: 0 additions & 1 deletion docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM openjdk:8-jdk

RUN apt-get update && apt-get install -y --no-install-recommends \
maven \
openjfx && rm -rf /var/lib/apt/lists/*

WORKDIR /bisq-api
Expand Down
9 changes: 4 additions & 5 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM openjdk:8-jdk

RUN apt-get update && apt-get install -y --no-install-recommends \
maven \
openjfx && rm -rf /var/lib/apt/lists/*

WORKDIR /bisq-api
Expand All @@ -12,14 +11,14 @@ ENV LANG=en_US

CMD ./docker/startApi.sh

COPY pom.xml .
COPY docker ./docker
COPY gradlew build.gradle ./
COPY gradle/wrapper ./gradle/wrapper
#This is to fetch maven plugins needed to run exec:java from docker/startApi.sh
RUN mvn dependency:resolve compile -P integration exec:java -Dexec.mainClass="bisq.desktop.app.BisqAppMain" -Dexec.args="--help"
RUN ./gradlew dependencies

COPY . /bisq-api

VOLUME /root/.local/share/Bisq
RUN mvn compile
RUN ./gradlew build -x test
ENV SKIP_BUILD=true
ENV BISQ_API_HOST=0.0.0.0
18 changes: 15 additions & 3 deletions docker/startApi.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

if [ -d /root/.gradle-volume ] ; then
echo Copying /root/.gradle-volume to /root/.gradle/
mkdir -p /root/.gradle/
cp -R /root/.gradle-volume/* /root/.gradle/
fi

if [ "$SKIP_BUILD" != "true" ]; then
mvn compile
./gradlew --no-daemon compileJava -x test
fi

IP=`ip -4 -o addr show eth0 | sed 's/.*inet \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/'`
Expand Down Expand Up @@ -33,6 +39,12 @@ fi
if [ ! -z "$USE_DEV_PRIVILEGE_KEYS" ]; then
ARGS="$ARGS --useDevPrivilegeKeys=$USE_DEV_PRIVILEGE_KEYS"
fi
if [ ! -z "$BISQ_API_PORT" ]; then
ARGS="$ARGS --httpApiPort=$BISQ_API_PORT"
fi
if [ ! -z "$BISQ_API_HOST" ]; then
ARGS="$ARGS --httpApiHost=$BISQ_API_HOST"
fi

echo mvn exec:java -Dexec.mainClass="network.bisq.api.app.ApiMain" -Dexec.args="$ARGS"
mvn exec:java -Dexec.mainClass="network.bisq.api.app.ApiMain" -Dexec.args="$ARGS"
echo ./gradlew run --no-daemon --args "foo $ARGS"
./gradlew run --no-daemon --args "foo $ARGS"
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
systemProp.org.gradle.internal.http.connectionTimeout=60000
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 3f5004b

Please sign in to comment.