Skip to content

Build And Deploy

Jez Higgins edited this page Jan 16, 2018 · 7 revisions

Tymly Logo

An open source low-code platform - that's built for collaboration

Build Status JavaScript Style Guide lerna license PRs Welcome Gitter Greenkeeper badge

Tymly is a monorepo using Lerna to install and manage the various package dependencies. While it's perfectly possible to happily develop using only npm and lerna, the scope of these tools is limited to node package management (the clue is in the name!). Consequently, to ease our build and deployment automation, we layer another tool, in our case Gradle, over the top of them.

Pre-requisites

  • Node
  • JVM
  • Docker Tools

Very Brief Gradle Intro

Gradle is an extensible build tool, written in Groovy and running on the Java Virtual Machine. It is portable across platforms. If you're on Windows wherever you see ./gradlew in the notes below simply substitute gradlew. Gradle bootstraps itself so there is nothing to manually install, beyond the JVM itself which you probably already have.

Build and Test

$ ./gradlew test

Running the test target runs the tests for every package, plugin, and blueprint in the Tymly monorepo. On the face of it, this may not sound hugely different from lerna run test, but the gradle build is doing a little more work for us.

The test target performs the following steps

  • npm install
  • lerna bootstrap
  • start a local PostGres server
  • run all the tests
  • shutdown PostGres

Gradle can automatically download, unpack, and cache PostGres so that it can start it afresh for each test run. At the end of the test run, the database is discarded. If you don't want to use the embedded PostGres server, set the PG_CONNECTION_STRING environment variable to point to your PostGres server of choice and the Gradle build will use that instead.

Each testable package is run separately, in its own Node process.

Each testable package, plugin, or blueprint has a test task created for it, so it's possible to run a subset of the tests should you so wish. For example,

$ ./gradlew testStatebox testHl-pg-client 

would only run the Statebox and Hl-pg-client tests, but would still perform lerna bootstrap and start Postgres for the test run. To see a list of all available test targets, run

$ ./gradlew tasks

For ease of integration with Jenkins and similar CI tools, use the ci_test target which captures the test results to xUnit compatible XML files in the build/test directory.

Bundling and Deployment

$ ./gradlew bundle

The bundle target packages a deployable Tymly tarball. It includes all the necessary npm packages, while excluding dev-dependencies and test code. To deploy, it simply needs to be untarred. The is no need to run npm install, lerna bootstrap or anything else that will pull random code from the Internet. That's already done, so you're good to go.

$ ./gradlew dockerBuild

The dockerBuild task takes the tarball created by bundle and uses it to build a runnable Docker image. In fact it builds two images

  • tymly-core containing the Tymly server with a default configuration
  • tymly which builds on Tymly server to with WMFS specific authentication configuration

The dockerPush target retags the tymly-core and tymly Docker images with the wmfs organisation tag and pushes them to the Docker Hub.