diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 000000000..686ea6199 --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1,17 @@ +.git +.gitignore +.dockerignore +docker-compose.yml +docker-compose-base.yml +Dockerfile +docker/dev/Dockerfile +docker/prod/Dockerfile + +.idea +*.iml + +target +support + +build +out diff --git a/api/README.md b/api/README.md index bc4408947..415ce6159 100644 --- a/api/README.md +++ b/api/README.md @@ -70,6 +70,21 @@ Note that username is ignored and can be whatever, i.e. in following example use ../gradlew run --args="--httpApiHost=127.0.0.1 --httpApiPort=8080" +## Docker integration + +First you need to build the docker image for the API: + + cd api + docker-compose build + +Start container with the API: + + docker-compose up alice + +It will automatically start `bisq-api` (alice), `bitcoind` and `seednode` in regtest mode. + + curl localhost:8080/api/v1/version + **CAUTION! Please do not expose the API over a public interface** ## Experimental features diff --git a/api/docker-compose-base.yml b/api/docker-compose-base.yml new file mode 100644 index 000000000..1e88a915d --- /dev/null +++ b/api/docker-compose-base.yml @@ -0,0 +1,34 @@ +version: '2.1' + +services: + api: + build: + context: .. + dockerfile: api/docker/dev/Dockerfile + image: bisq/api + environment: + - LOG_LEVEL=debug + - USE_LOCALHOST_FOR_P2P=true + - USE_DEV_PRIVILEGE_KEYS=true + - SEED_NODES=seed:8000 + - BTC_NODES=bitcoin:18444 + - BASE_CURRENCY_NETWORK=BTC_REGTEST + - BITCOIN_REGTEST_HOST=NONE + - HTTP_API_HOST=0.0.0.0 + - ENABLE_HTTP_API_EXPERIMENTAL_FEATURES=true + seed: + image: bisq/seednode + environment: + - MY_ADDRESS=seed:8000 + - SEED_NODES=seed:8000 + - BTC_NODES=bitcoin:18444 + - USE_LOCALHOST_FOR_P2P=true + - BASE_CURRENCY_NETWORK=BTC_REGTEST + - BITCOIN_REGTEST_HOST=NONE + bitcoin: + image: bisq/bitcoind:latest + command: -logips -rpcallowip=::/0 -regtest -printtoconsole + environment: + - DISABLEWALLET=0 + - RPCUSER=user + - RPCPASSWORD=password diff --git a/api/docker-compose.yml b/api/docker-compose.yml new file mode 100644 index 000000000..2305ff48f --- /dev/null +++ b/api/docker-compose.yml @@ -0,0 +1,51 @@ +version: '2.1' + +services: + alice: + extends: + file: docker-compose-base.yml + service: api + ports: + - 8080:8080 + environment: + - NODE_PORT=8003 + links: + - seed + - bitcoin + bob: + extends: + file: docker-compose-base.yml + service: api + ports: + - 8081:8080 + environment: + - NODE_PORT=8004 + links: + - seed + - bitcoin + arbitrator: + extends: + file: docker-compose-base.yml + service: api + ports: + - 8082:8080 + environment: + - NODE_PORT=8005 + links: + - seed + - bitcoin + seed: + extends: + file: docker-compose-base.yml + service: seed + ports: + - 8000:8000 + links: + - bitcoin + bitcoin: + extends: + file: docker-compose-base.yml + service: bitcoin + ports: +# If it is default regtest port (18444) then bisq ignores btcNodes param and uses localhost + - 18445:18444 diff --git a/api/docker/dev/Dockerfile b/api/docker/dev/Dockerfile new file mode 100644 index 000000000..5fffc0bfe --- /dev/null +++ b/api/docker/dev/Dockerfile @@ -0,0 +1,29 @@ +FROM openjdk:10-jdk + +RUN apt-get update && apt-get install -y --no-install-recommends \ + openjfx && rm -rf /var/lib/apt/lists/* + +WORKDIR /bisq/api + +#ENV HTTP_API_HOST= +#ENV HTTP_API_PORT= +ENV LANG=en_US + +CMD ./docker/startApi.sh + +#Fetch gradle and dependencies +COPY gradle /bisq/gradle/ +COPY gradlew build.gradle gradle.properties settings.gradle /bisq/ +RUN ../gradlew --no-daemon -v + +COPY assets /bisq/assets/ +COPY common /bisq/common/ +COPY core /bisq/core/ +COPY p2p /bisq/p2p/ +COPY pricenode /bisq/pricenode/ +RUN ../gradlew --no-daemon build -x test + +COPY api /bisq/api + +#Compile sources to speed up startup +RUN ../gradlew --no-daemon --offline compileJava -x test diff --git a/api/docker/startApi.sh b/api/docker/startApi.sh new file mode 100755 index 000000000..1fad1954b --- /dev/null +++ b/api/docker/startApi.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +ARGS="" +if [ ! -z "$APP_NAME" ]; then + ARGS="$ARGS --appName=$APP_NAME" +fi +if [ ! -z "$NODE_PORT" ]; then + ARGS="$ARGS --nodePort=$NODE_PORT" +fi +if [ ! -z "$USE_LOCALHOST_FOR_P2P" ]; then + ARGS="$ARGS --useLocalhostForP2P=$USE_LOCALHOST_FOR_P2P" +fi +if [ ! -z "$SEED_NODES" ]; then + ARGS="$ARGS --seedNodes=$SEED_NODES" +fi +if [ ! -z "$BTC_NODES" ]; then + ARGS="$ARGS --btcNodes=$BTC_NODES" +fi +if [ ! -z "$BITCOIN_REGTEST_HOST" ]; then + ARGS="$ARGS --bitcoinRegtestHost=$BITCOIN_REGTEST_HOST" +fi +if [ ! -z "$BASE_CURRENCY_NETWORK" ]; then + ARGS="$ARGS --baseCurrencyNetwork=$BASE_CURRENCY_NETWORK" +fi +if [ ! -z "$LOG_LEVEL" ]; then + ARGS="$ARGS --logLevel=$LOG_LEVEL" +fi +if [ ! -z "$USE_DEV_PRIVILEGE_KEYS" ]; then + ARGS="$ARGS --useDevPrivilegeKeys=$USE_DEV_PRIVILEGE_KEYS" +fi +if [ "$ENABLE_HTTP_API_EXPERIMENTAL_FEATURES" == "true" ]; then + ARGS="$ARGS --enableHttpApiExperimentalFeatures" +fi +if [ ! -z "$HTTP_API_PORT" ]; then + ARGS="$ARGS --httpApiPort=$HTTP_API_PORT" +fi +if [ ! -z "$HTTP_API_HOST" ]; then + ARGS="$ARGS --httpApiHost=$HTTP_API_HOST" +fi + +echo ../gradlew run --no-daemon --args "foo $ARGS" +../gradlew run --no-daemon --args "foo $ARGS"