microservices-demo/deploy_doc

Name: deploy_doc

Owner: Microservices Demo

Description: Test the deployment documentation of your application from the markdown source

Created: 2016-11-24 14:22:10.0

Updated: 2016-12-01 10:08:56.0

Pushed: 2017-01-06 10:11:16.0

Homepage: null

Size: 120

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

DeployDoc

Synopsis

With DeployDoc, you can test the deployment of your microservice constellation to multiple platforms, based on your end user documentation. Usually, a project will have documented the required steps to deploy the microservices. This documentation typically consists of a text with these steps embedded in it. We realized that by adding some annotations, these steps could be parsed by a computer and run in a CI pipeline. See the syntax section below for more information about how to write these Markdown files.

Architecture

Usage

Install the deploy_doc gem, see the installation instructions below.

E: deploy_doc <markdown_file> [options]
-h, --help                       Print help
-r, --run-test                   Run tests
-j, --dump-json                  Just parse the Markdown file and dump the steps to JSON
-c, --shell-in-container         Start a (temporary) docker container with the same environment as the tests will run in
-i, --docker-image=IMG_NAME      Use this docker image instead of the default 'ruby:2.3'
-d, --data-dir=DIR               Set the data directory, instead of the default '.'

 STATUS:
 all test passed, and the infrastructure has been cleaned up, 0 is returned.
 something went wrong, but there the infrastructure has been destroyed correctly,
1 error status is returned, but if the destruction of the infrastructure did not complete,
e process returns an error status 2. These cases will probably require manual cleanup steps.
nally, a error status 3 is returned if the program is aborted. We cannot give any guarantees in this case!

NOTE: If you use a custom docker image, be sure that it contains a Ruby implementation with version >= 2.1

Phases in a DeployDoc

The test runner has four phases:

Secrets phase

There is an additional require-env phase, that can be used to pass in environmental variables to the steps. If they are not present, testing the documentation will result in an error message that these variables are not present.

Syntax

The expected syntax is compatible with Jekyll. We expect the Markdown file to start with a YAML section, enclosed in a --- delimiter.

Defining phases and steps

Multiple shell snippets (steps) can be added to a phase. The phases are run in the order give in the previous section, after which each snippet is executed in the order of declaration in the file.

The following syntaxes are supported to add snippets:

  1. Single line annotation, not visible in Markdown output

    <!-- deploy-doc PHASE [VALUE]* -->
    
  2. Hidden multi-line annotation

    <!-- deploy-doc-start PHASE [VALUE]*
    CONTENT
    -->
    
  3. Visible multi-line annotation

    <!-- deploy-doc-start PHASE [VALUE]* -->
    CONTENT
    <!-- deploy-doc-end -->
    

Note that due to current technical limitations of the test runner, each step is executed in a separate shell. This implies that setting an environmental variable in one step, will not be available in a next step. A work-around is to load/store this information in files. The externally required environmental variables to store secrets are available in all steps.

Example DeployDoc

oyDoc: true

llo World
 deploy-doc require-env ENV_A ENV_B -->

 deploy-doc-start pre-install -->

apt-get update
apt-get install -yq jq terraform

 deploy-doc-end -->

 deploy-doc-hidden pre-install

rl https://nixos.org/nix/install | sh
x-env -i nixops



 deploy-doc-start create-infrastructure -->

# This both creates the infrastructure, and
# deploys a distributed application to it.
nixops create -d test_deployment ./deployment.nix
nixops deploy -d test_deployment

 deploy-doc-end -->

 deploy-doc-start run-tests -->

# Get the public endpoint
WEBAPP_HOST=`nixops export -d test_deployment | jq ' .[].resources["load-balancer"].publicIpv4' -r`

# Test that the webapp is up.
curl $WEBAPP_HOST

 deploy-doc-end -->

 deploy-doc-start destroy-infrastructure -->

nixops destroy -d test_deployment

 deploy-doc-end -->
Installation

Add this line to your application's Gemfile:

'deploy_doc'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deploy_doc
Development of this gem

After checking out the repo, run bundle install to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/microservices-demo/deploy_doc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.