Skip to content

Commit

Permalink
NODE-2256: Use the modern docker image for integration tests (#3346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karasiq authored Mar 17, 2021
1 parent 2909f6d commit b2351b8
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 297 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target
*.*~

# dotfiles
.dockerignore
.editorconfig
.DS_Store

Expand All @@ -31,11 +30,11 @@ waves_logback.xml
*.csv
*.dat

# standalone docker
Dockerfile
# Docker
docker/temp

package
!src/package
native

!lang/jvm/lib/*.jar
!lang/jvm/lib/*.jar
18 changes: 18 additions & 0 deletions build-with-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

NETWORK="Mainnet"

if [[ -n $1 ]]; then
NETWORK=$1
fi

echo "Building with network: $NETWORK"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
USER=$(id -u)
GROUP=$(id -g)

docker run --mount type=bind,source="$DIR",target=/src -i mozilla/sbt:8u232_1.3.8 /bin/sh -c "
cd /src &&
COURSIER_CACHE=\"$DIR/target/docker/coursier\" sbt \"-Dsbt.boot.directory=$DIR/target/docker/sbt_cache\" \"set ThisBuild/network := $NETWORK\" packageAll &&
chown -R $USER:$GROUP .
"
22 changes: 10 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import sbt.Keys._
import sbt.{Project, _}
import sbt.{File, IO, Project, _}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}

val langPublishSettings = Seq(
Expand Down Expand Up @@ -147,17 +147,15 @@ git.useGitDescribe := true
git.uncommittedSignifier := Some("DIRTY")

lazy val packageAll = taskKey[Unit]("Package all artifacts")
packageAll := Def
.sequential(
root / clean,
Def.task {
(node / assembly).value
(node / Debian / packageBin).value
(`grpc-server` / Universal / packageZipTarball).value
(`grpc-server` / Debian / packageBin).value
}
)
.value
packageAll := {
(node / assembly).value
(`grpc-server` / Universal / packageZipTarball).value

val nodeDebFile = (node / Debian / packageBin).value
val grpcDebFile = (`grpc-server` / Debian / packageBin).value
IO.copyFile(nodeDebFile, new File(baseDirectory.value, "docker/target/waves.deb"))
IO.copyFile(grpcDebFile, new File(baseDirectory.value, "docker/target/grpc-server.deb"))
}

lazy val checkPRRaw = taskKey[Unit]("Build a project and run unit tests")
checkPRRaw := Def
Expand Down
83 changes: 16 additions & 67 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,81 +1,30 @@
FROM openjdk:8-jdk-stretch as builder
ARG SBT_VERSION=1.2.8
ARG WAVES_VERSION="latest"
ARG BRANCH="version-1.1.x"
ARG DEB_PACKAGE_NETWORKS

RUN \
{ \
WAVES_VERSION=$WAVES_VERSION && \
test $WAVES_VERSION = "latest" && \
WAVES_VERSION=$(curl -fsSL \
https://api.github.com/repos/wavesplatform/Waves/releases/latest \
| tac | grep -m 1 'tag_name.:' | tr -cd '[0-9\.]') && \
echo "Using latest version '${WAVES_VERSION}'" \
;} ; \
{ \
curl -fsSL https://api.github.com/repos/wavesplatform/Waves/releases \
| tac | grep -q "tag_name.*${WAVES_VERSION}" && \
echo "GitHub release '${WAVES_VERSION}' found" \
;} && \
{ \
echo "Downloading Waves '${WAVES_VERSION}' from GitHub" && \
mkdir -p /waves/node/target && \
releaseUrl="https://github.com/wavesplatform/Waves/releases/download" && \
\
echo "Downloading jar file" && \
curl -fL ${releaseUrl}/v${WAVES_VERSION}/waves-all-${WAVES_VERSION}.jar \
-o /waves/node/target/waves-all-${WAVES_VERSION}.jar \
;} || \
{ \
echo "Downloading sbt '${SBT_VERSION}'" && \
curl -fL -o sbt-$SBT_VERSION.deb \
https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && rm sbt-$SBT_VERSION.deb && \
git clone https://github.com/wavesplatform/Waves.git \
--branch $BRANCH waves && cd waves && \
git config --global user.name "Sbt Builder" && \
git config --global user.email "[email protected]" && \
git tag -a "v${WAVES_VERSION}" -m "Docker build" && \
SBT_OPTS="-Xmx2g -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=128m" \
sbt "node/assembly" && \
for network in $DEB_PACKAGE_NETWORKS ; do \
echo "Building '${network}' package" && \
SBT_OPTS="-XX:ReservedCodeCacheSize=128m \
-Xmx2g -Dnetwork=${network}" sbt 'packageAll' && \
mkdir -p /out/${network} && \
mv node/target/waves*.deb /out/${network}/ && \
cp node/target/waves-all*.jar /out/${network}/ && \
mv grpc-server/target/universal/grpc-server*.tgz /out/${network}/ && \
mv grpc-server/target/grpc-server*.deb /out/${network}/ ; \
done \
;}

FROM openjdk:11-jre-slim
ARG WAVES_VERSION="latest"
FROM debian:stable-slim
ARG WAVES_LOG_LEVEL="INFO"
ARG WAVES_HEAP_SIZE="2g"
ARG WAVES_NETWORK="mainnet"
ARG ENABLE_GRPC="true"

ENV WAVES_VERSION=$WAVES_VERSION
ENV WAVES_LOG_LEVEL=$WAVES_LOG_LEVEL
ENV WAVES_HEAP_SIZE=$WAVES_HEAP_SIZE
ENV WAVES_NETWORK=$WAVES_NETWORK
ENV ENABLE_GRPC=$ENABLE_GRPC

COPY --from=builder /waves/node/target/waves-all-*.jar /usr/share/waves/lib/
COPY entrypoint.sh /usr/share/waves/bin/
COPY build-scripts /tmp/

RUN groupadd -g 143 waves && \
useradd -d /var/lib/waves -g 143 -u 143 -s /bin/bash -M waves && \
mkdir -p /var/lib/waves /etc/waves /usr/share/waves/lib/plugins && \
chown -R 143:143 /var/lib/waves /usr/share/waves /etc/waves && \
chmod -R 755 /var/lib/waves /usr/share/waves /etc/waves && \
ln -fs /var/lib/waves/log /var/log/waves
# Additional dependencies
RUN /bin/bash /tmp/setup-deps.sh

WORKDIR /var/lib/waves
EXPOSE 6869 6868 6863 6862
# Node DEB files
ENV WVDATA=/var/lib/waves
ENV WVLOG=/var/log/waves
COPY target /tmp/
RUN /bin/bash /tmp/setup-node.sh

USER waves
EXPOSE 6869 6868 6863 6862 6870
VOLUME /var/lib/waves
VOLUME /var/log/waves
VOLUME /usr/share/waves/lib/plugins
WORKDIR /var/lib/waves

STOPSIGNAL SIGINT
ENTRYPOINT ["/usr/share/waves/bin/entrypoint.sh"]
47 changes: 13 additions & 34 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Waves Node in Docker

## About Waves
Waves is a decentralized platform that allows any user to issue, transfer, swap and trade custom blockchain tokens on an integrated peer-to-peer exchange. You can find more information about Waves at [wavesplatform.com](https://wavesplatform.com) and in the official [documentation]((https://docs.wavesplatform.com)).
Waves is a decentralized platform that allows any user to issue, transfer, swap and trade custom blockchain tokens on an integrated peer-to-peer exchange. You can find more information about Waves at [waves.tech](https://waves.tech/) and in the official [documentation](https://docs.waves.tech).


## About the image
Expand All @@ -11,26 +11,18 @@ The image is focused on fast and convenient deployment of Waves Node.
GitHub repository: https://github.com/wavesplatform/Waves/tree/master/docker

## Prerequisites
It is highly recommended to read more about [Waves Node configuration](https://docs.wavesplatform.com/en/waves-Node/Node-configuration.html) before running the container.
It is highly recommended to read more about [Waves Node configuration](https://docs.waves.tech/en/waves-node/node-configuration) before running the container.

## Building Docker image

Dockerfile supports 3 main scenarios:
1. Basic scenario `docker build -t wavesplatform/wavesnode .` - build an image with the latest Waves Node release available
*Note*: pre-releases are skipped
2. Existing Version scenario `docker build --build-arg WAVES_VERSION=1.1.1` - specify the version of Waves Node available in GitHub Releases. If this version does not exist, this is the next scenario.
3. Build scenario `docker build --build-arg WAVES_VERSION=99.99.99 --build-arg BRANCH=version-0.17.x` - this scenario assumes that you want to build Waves Node from sources. Use `WAVES_VERSION` build argument to specify a Git tag ('v' is added automatically) and `BRANCH` to specify a Git branch to checkout to. Make sure you specify a tag that does not exist in the repo, otherwise it is the previous scenario.
`./build-with-docker.sh && docker build -t wavesplatform/wavesnode docker` (from the repository root) - builds an image with the current local repository

**You can specify following arguments when building the image:**


|Argument | Default value |Description |
|----------------------|-------------------|--------------|
|`WAVES_NETWORK` | `mainnet` | Waves Blockchain network. Available values are `mainnet`, `testnet`, `stagenet`. Can be overridden in a runtime using environment variable with the same name.|
|`WAVES_VERSION` | `latest` | A node version which corresponds to the Git tag we want to use/create. |
|`BRANCH` | `version-0.17.x` | Relevant if Git tag 'v`WAVES_VERSION`' does not exist in the public repository. This option represents a Git branch we will use to compile Waves node and set a Git tag on.|
|`SBT_VERSION` | `1.2.8` | Scala build tool version.|
|`WAVES_LOG_LEVEL` | `DEBUG` | Default Waves Node log level. Available values: `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`. More details about logging are available [here](https://docs.wavesplatform.com/en/waves-Node/logging-configuration.html). Can be overridden in a runtime using environment variable with the same name. |
|`WAVES_LOG_LEVEL` | `DEBUG` | Default Waves Node log level. Available values: `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`. More details about logging are available [here](https://docs.waves.tech/en/waves-node/logging-configuration). Can be overridden in a runtime using environment variable with the same name. |
|`WAVES_HEAP_SIZE` | `2g` | Default Waves Node JVM Heap Size limit in -X Command-line Options notation (`-Xms=[your value]`). More details [here](https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html). Can be overridden in a runtime using environment variable with the same name. |

**Note: All build arguments are optional.**
Expand All @@ -57,7 +49,7 @@ docker run -v /docker/waves/waves-data:/var/lib/waves -v /docker/waves/waves-con
|-----------------------------------|--------------|
| `WAVES_WALLET_SEED` | Base58 encoded seed. Overrides `-Dwaves.wallet.seed` JVM config option. |
| `WAVES_WALLET_PASSWORD` | Password for the wallet file. Overrides `-Dwaves.wallet.password` JVM config option. |
| `WAVES_LOG_LEVEL` | Node logging level. Available values: `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`. More details about logging are available [here](https://docs.wavesplatform.com/en/waves-Node/logging-configuration.html).|
| `WAVES_LOG_LEVEL` | Node logging level. Available values: `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`. More details about logging are available [here](https://docs.waves.tech/en/waves-node/logging-configuration).|
| `WAVES_HEAP_SIZE` | Default Java Heap Size limit in -X Command-line Options notation (`-Xms=[your value]`). More details [here](https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html). |
|`WAVES_NETWORK` | Waves Blockchain network. Available values are `mainnet`, `testnet`, `stagenet`.|
|`JAVA_OPTS` | Additional Waves Node JVM configuration options. |
Expand Down Expand Up @@ -93,18 +85,7 @@ Once container is launched it will create:

3. If you already have Waves Node configuration/data - place it in the corresponsing directories


4. *Configure access permissions*. We use `waves` user with predefined uid/gid `143/143` to launch the container. As such, either change permissions of the created directories or change their owner:

```
sudo chmod -R 777 /docker/waves
```
or
```
sudo chown -R 143:143 /docker/waves <-- prefered
```

5. Add the appropriate arguments to ```docker run``` command:
4. Add the appropriate arguments to ```docker run``` command:
```
docker run -v /docker/waves/waves-data:/var/lib/waves -v /docker/waves/waves-config:/etc/waves -e WAVES_NETWORK=stagenet -e WAVES_WALLET_PASSWORD=myWalletSuperPassword -ti wavesplatform/wavesnode
```
Expand All @@ -119,27 +100,25 @@ You can speed this process up by downloading a compressed blockchain state from

|Network |Link |
|------------|--------------|
|`mainnet` | http://blockchain.wavesplatform.com/blockchain_last.tar |
|`testnet` | http://blockchain-testnet.wavesplatform.com/blockchain_last.tar |
|`stagenet` | http://blockchain-stagenet.wavesplatform.com/blockchain_last.tar |
|`mainnet` | http://blockchain.wavesnodes.com/blockchain_last.tar |
|`testnet` | http://blockchain-testnet.wavesnodes.com/blockchain_last.tar |
|`stagenet` | http://blockchain-stagenet.wavesnodes.com/blockchain_last.tar |


**Example:**
```
mkdir -p /docker/waves/waves-data
wget -qO- http://blockchain-stagenet.wavesplatform.com/blockchain_last.tar --show-progress | tar -xvf - -C /docker/waves/waves-data
chown -R 143:143 /docker/waves/waves-data
wget -qO- http://blockchain-stagenet.wavesnodes.com/blockchain_last.tar --show-progress | tar -xvf - -C /docker/waves/waves-data
docker run -v /docker/waves/waves-data:/var/lib/waves wavesplatform/Node -e WAVES_NETWORK=stagenet -e WAVES_WALLET_PASSWORD=myWalletSuperPassword -ti wavesplatform/wavesnode
```

### Network Ports

1. REST-API interaction with Node. Details are available [here](https://docs.wavesplatform.com/en/waves-Node/Node-configuration.html#section-530adfd0788eec3f856da976e4ce7ce7).
1. REST-API interaction with Node. Details are available [here](https://docs.waves.tech/en/waves-node/node-configuration#rest-api-settings).

2. Waves Node communication port for incoming connections. Details are available [here](https://docs.wavesplatform.com/en/waves-Node/Node-configuration.html#section-fd33d7a83e3b2854f614fd9d5ae733ba).
2. Waves Node communication port for incoming connections. Details are available [here](https://docs.waves.tech/en/waves-node/node-configuration#network-settings).


**Example:**
Expand All @@ -149,7 +128,7 @@ Below command will launch a container:
- Ports `6868` and `6870` mapped from the host to the container

```
docker run -v /docker/waves/waves-data:/var/lib/waves -v /docker/waves/waves-config:/etc/waves -p 6870:6870 -p 6868:6868 -e JAVA_OPTS="-Dwaves.network.declared-address=0.0.0.0:6868 -Dwaves.rest-api.port=6870 -Dwaves.rest-api.bind-address=0.0.0.0 -Dwaves.rest-api.enable=yes" -e WAVES_WALLET_PASSWORD=myWalletSuperPassword -ti wavesplatform/wavesnode
docker run -v /docker/waves/waves-data:/var/lib/waves -v /docker/waves/waves-config:/etc/waves -p 6870:6870 -p 6868:6868 -e JAVA_OPTS="-Dwaves.network.declared-address=0.0.0.0:6868 -Dwaves.rest-api.port=6870 -Dwaves.rest-api.bind-address=0.0.0.0 -Dwaves.rest-api.enable=yes" -e WAVES_WALLET_PASSWORD=myWalletSuperPassword -e WAVES_NETWORK=stagenet -ti wavesplatform/wavesnode
```

Check that REST API is up by navigating to the following URL from the host side:
Expand Down
58 changes: 58 additions & 0 deletions docker/build-scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
shopt -s nullglob
NETWORKS="mainnet testnet stagenet"

logEcho() {
echo $1 | gosu waves tee -a /var/log/waves/waves.log
}

mkdir -p $WVDATA $WVLOG
chmod 700 $WVDATA $WVLOG || :

user="$(id -u)"
if [ "$user" = '0' ]; then
find $WVDATA \! -user waves -exec chown waves '{}' +
find $WVLOG \! -user waves -exec chown waves '{}' +
fi

[ -z "${WAVES_CONFIG}" ] && WAVES_CONFIG="/etc/waves/waves.conf"
if [[ ! -f "$WAVES_CONFIG" ]]; then
logEcho "Custom '$WAVES_CONFIG' not found. Using a default one for '${WAVES_NETWORK,,}' network."
if [[ $NETWORKS == *"${WAVES_NETWORK,,}"* ]]; then
touch "$WAVES_CONFIG"
echo "waves.blockchain.type=${WAVES_NETWORK}" >>$WAVES_CONFIG

sed -i 's/include "local.conf"//' "$WAVES_CONFIG"
for f in /etc/waves/ext/*.conf; do
echo "Adding $f extension config to waves.conf"
echo "include required(\"$f\")" >>$WAVES_CONFIG
done
echo 'include "local.conf"' >>$WAVES_CONFIG
else
echo "Network '${WAVES_NETWORK,,}' not found. Exiting."
exit 1
fi
else
echo "Found custom '$WAVES_CONFIG'. Using it."
fi

[ -n "${WAVES_WALLET_PASSWORD}" ] && JAVA_OPTS="${JAVA_OPTS} -Dwaves.wallet.password=${WAVES_WALLET_PASSWORD}"
[ -n "${WAVES_WALLET_SEED}" ] && JAVA_OPTS="${JAVA_OPTS} -Dwaves.wallet.seed=${WAVES_WALLET_SEED}"
JAVA_OPTS="${JAVA_OPTS} -Dwaves.data-directory=$WVDATA/data -Dwaves.directory=$WVDATA"

logEcho "Node is starting..."
logEcho "WAVES_HEAP_SIZE='${WAVES_HEAP_SIZE}'"
logEcho "WAVES_LOG_LEVEL='${WAVES_LOG_LEVEL}'"
logEcho "WAVES_NETWORK='${WAVES_NETWORK}'"
logEcho "WAVES_WALLET_SEED='${WAVES_WALLET_SEED}'"
logEcho "WAVES_WALLET_PASSWORD='${WAVES_WALLET_PASSWORD}'"
logEcho "WAVES_CONFIG='${WAVES_CONFIG}'"
logEcho "JAVA_OPTS='${JAVA_OPTS}'"

JAVA_OPTS="-Dlogback.stdout.level=${WAVES_LOG_LEVEL}
-XX:+ExitOnOutOfMemoryError
-Xmx${WAVES_HEAP_SIZE}
-Dlogback.file.directory=$WVLOG
-Dconfig.override_with_env_vars=true
${JAVA_OPTS}
-cp '/usr/share/waves/lib/plugins/*:/usr/share/waves/lib/*'" exec gosu waves waves "$WAVES_CONFIG"
10 changes: 10 additions & 0 deletions docker/build-scripts/setup-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

mkdir -p /usr/share/man/man1
apt-get update && apt-get install -y wget unzip default-jre-headless gosu || exit 1

YOURKIT_ARCHIVE="YourKit-JavaProfiler-2019.8-docker.zip"
wget --quiet "https://www.yourkit.com/download/docker/$YOURKIT_ARCHIVE" -P /tmp/ && unzip /tmp/$YOURKIT_ARCHIVE -d /usr/local

# Clean
apt-get remove -y wget unzip && apt-get autoremove -y && apt-get autoclean && rm -rf /var/lib/apt/lists/*
22 changes: 22 additions & 0 deletions docker/build-scripts/setup-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Create user
groupadd -r waves --gid=999
useradd -r -g waves --uid=999 --home-dir=$WVDATA --shell=/bin/bash waves

# Install DEB packages
dpkg -i /tmp/waves.deb || exit 1
if [[ $ENABLE_GRPC == "true" ]]; then
echo "Installing gRPC server"
dpkg -i /tmp/grpc-server.deb || exit 1
fi

# Set permissions
chown -R waves:waves $WVDATA $WVLOG && chmod 777 $WVDATA $WVLOG

rm /etc/waves/waves.conf # Remove example config
cp /tmp/entrypoint.sh /usr/share/waves/bin/entrypoint.sh
chmod +x /usr/share/waves/bin/entrypoint.sh

# Cleanup
rm -rf /tmp/*
Loading

0 comments on commit b2351b8

Please sign in to comment.