Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

feat: dockerize test suite #28

Merged
merged 7 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DASHJS_SEED=
DAPI_CLIENT_SEEDS=ip1,ip2
DAPI_CLIENT_PORT=3000
FAUCET_PRIVATE_KEY=
Expand Down
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ node_js:
branches:
only:
- master
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)-dev$/
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/

services:
- docker
Expand All @@ -30,3 +32,10 @@ script:
- ~/.local/bin/dash-network test $DEVNET
- cd $TRAVIS_BUILD_DIR
- npm run test

deploy:
provider: script
script: bash bin/travis-deploy.sh
on:
tags: true
repo: dashevo/dash-platform-test-suite
Copy link
Member

@shumkov shumkov Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dashevo/platform-test-suite

33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:12-alpine

RUN apk update && \
apk --no-cache upgrade && \
apk add --no-cache git \
alpine-sdk

# Install dependencies first, in a different location
# for easier app bind mounting for local development
WORKDIR /

COPY package.json package-lock.json ./
RUN npm ci --production

FROM node:12-alpine

LABEL maintainer="Dash Developers <[email protected]>"
LABEL description="Test suite for Dash Platform"

# Copy NPM modules
COPY package.json package-lock.json ./
COPY --from=0 /node_modules/ /node_modules

ENV PATH /node_modules/.bin:$PATH

# Copy project files
WORKDIR /usr/src/app
COPY . ./

ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}

ENTRYPOINT ["./bin/test.sh"]
61 changes: 61 additions & 0 deletions bin/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
Copy link
Member

@shumkov shumkov Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it duplicate?


set -ea

cmd_usage="Run test suite

Usage: run-test <seed> [options]

<seed> can be IP or IP:port

Options:
-ni --npm-install - run npm install before running the suite
-s=a,b,c --scope=a,b,c - run only scope
-h --help - Show help

Possible scopes:
e2e
functional
core
platform
e2e:dpns
e2e:contacts
functional:core
functional:platform"


DASHJS_SEED="$1"

if [ -z "$DASHJS_SEED" ] || [[ $DASHJS_SEED == -* ]]
then
echo "Seed is not specified"
exit 0
fi

for i in "$@"
do
case ${i} in
-h|--help)
echo "$cmd_usage"
exit 0
;;
-ni|--npm-install)
npm_install=1
;;
-s=*|--scope=*)
scope="${i#*=}"
;;
esac
done

if [ -n "$npm_install" ]
then
cd .. && npm install
fi

if [ -n "$scope" ]
then
cd .. && DASHJS_SEED="$DASHJS_SEED" npm run test:"$scope"
else
cd .. && DASHJS_SEED="$DASHJS_SEED" npm run test
fi
61 changes: 61 additions & 0 deletions bin/travis-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

# Show script in output, and error if anything fails
set -xe

# Update this whenever the latest Node.js LTS version changes (~ every year).
# Do not forget to add this version to .travis.yml config also.
LATEST_LTS_VERSION="12"

# We want this command to succeed whether or not the Node.js version is the
# latest (so that the build does not show as failed), but _only_ the latest
# should be used to publish the module.
if [[ "$TRAVIS_NODE_VERSION" != "$LATEST_LTS_VERSION" ]]; then
echo "Node.js v$TRAVIS_NODE_VERSION is not latest LTS version -- will not deploy with this version."
exit 0
fi

# Parse version and it's segments
VERSION="$(jq -r .version package.json)"
PACKAGE_TAG=v"$VERSION"

VERSION_NO_PRERELEASE=$(awk -F- '{print $1}' <<< $VERSION)
PRERELEASE=$(awk -F- '{print $2}' <<< $VERSION)

MAJOR=$(awk -F. '{print $1}' <<< $VERSION_NO_PRERELEASE)
MINOR=$(awk -F. '{print $2}' <<< $VERSION_NO_PRERELEASE)
PATCH=$(awk -F. '{print $3}' <<< $VERSION_NO_PRERELEASE)

# Ensure the tag matches the one in package.json, otherwise abort.
if [[ "$PACKAGE_TAG" != "$TRAVIS_TAG" ]]; then
echo "Travis tag (\"$TRAVIS_TAG\") is not equal to package.json tag (\"$PACKAGE_TAG\"). Please push a correct tag and try again."
exit 1
fi

IMAGE_NAME="dashpay/platform-test-suite"

# If prerelease is empty it is a stable release
# so we add latest tag, otherwise a full version tag
LAST_TAG="${MAJOR}.${MINOR}.${PATCH}-${PRERELEASE}"
TAG_POSTFIX="-dev"
if [[ -z "$PRERELEASE" ]]; then
LAST_TAG="latest"
TAG_POSTFIX=""
fi

# Build an image with multiple tags
docker build --build-arg NODE_ENV=development \
-t "${IMAGE_NAME}:${MAJOR}${TAG_POSTFIX}" \
-t "${IMAGE_NAME}:${MAJOR}.${MINOR}${TAG_POSTFIX}" \
-t "${IMAGE_NAME}:${MAJOR}.${MINOR}.${PATCH}${TAG_POSTFIX}" \
-t "${IMAGE_NAME}:${LAST_TAG}" \
.

# Login to Docker Hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

# Push an image and all the tags
docker push "${IMAGE_NAME}:${MAJOR}${TAG_POSTFIX}"
docker push "${IMAGE_NAME}:${MAJOR}.${MINOR}${TAG_POSTFIX}"
docker push "${IMAGE_NAME}:${MAJOR}.${MINOR}.${PATCH}${TAG_POSTFIX}"
docker push "${IMAGE_NAME}:${LAST_TAG}"
11 changes: 11 additions & 0 deletions lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const dotenvSafe = require('dotenv-safe');
const { expect, use } = require('chai');
const dirtyChai = require('dirty-chai');
const chaiAsPromised = require('chai-as-promised');
const Dash = require('dash');

use(chaiAsPromised);
use(dirtyChai);
Expand All @@ -14,3 +15,13 @@ dotenvSafe.config({
});

global.expect = expect;

const seeds = [{ service: process.env.DASHJS_SEED }];

global.dashClient = new Dash.Client({
seeds,
});

before(async () => {
await global.dashClient.isReady();
});
Loading