aggkit

Helper tools for work with docker and consul

pipeline status Gem Version coverage report

Scripts

Some useful scripts to run inside or outside container

aggexec

aggexec to start process in context of consul:

  • load environment variables from Consul KV
  • preprocess template files with loaded environment variables
  • wait for healty status of consul services
Usage: aggexec [options] -- exec
        --consul=http://localhost:8500
                                     Set consul http address. CONSUL_HTTP_ADDR env can be used instead
        --depends=mq,db,router...    Set list of services to wait for ready before start
        --prefix=kv/folder/path      Consul KV prefix to load envs from. Multiple prefixes are merged from left to right.
        --service=<SERVICE>          Showrtcut for --prefix=services/env/<SERVICE>. Multiple prefixes are merged from left to right.
        --templates=<FOLDER>         Folder for recursive envsubst *.in templates. Multiple prefixes are merged from left to right.
        --no-exec                    skip exec command at the end

aggwait

aggwait allows to wait many conditions:

  • tcp port opening
  • PostgreSQL database creation
  • PostgreSQL table creation
  • file creation
  • healthy Consul service
Usage: aggwait [options] -- exec
        --tcp host:port              Wait for tcp accepts on host:port
        --db dbname                  Wait for PG database exists. Using --tcp to conenct PG
        --tb tablename               Wait for PG table exists. Using --tcp to conenct PG
    -f, --file filename              Wait for file exists.
        --consul-addr addr=http://localhost:8500
                                     HTTP addres to connect to consul
        --consul                     Wait for local consul agent to be ready
        --consul-service service     Wait for service appear in consul
        --consul-service-count count=1
                                     Wait for this count of service appear in consul
        --consul-tag tag             Filter consul service by tag
        --user user                  username
        --pass pass                  password
        --docker=SOCKET              wait for docker available
    -t, --timeout secs=15            Total timeout
    -i, --interval secs=2            Interval between attempts
    -q, --quiet                      Do not output any status messages

consul.rb

Helper to use Consul in 12Factor application. Inspired by https://github.com/hashicorp/envconsul:

  • export Consul key/value as environment variables
  • references in Consul key/value store
  • read config file and store values in Consul
  • read files and store it in Consul key/value store
Usage: aggconsul [options] -- exec
        --consul url                 Set up a custom Consul URL
        --token token                Connect into consul with custom access token (ACL)
        --init [service]             Initialize Consul services from config
        --config file                Read service configulation from file
        --upload                     Upload files to variables
        --show [service]             Show service configulation from Consul
        --override                   override existed keys
    -d, --dereference                dereference consul values in form of "consul://key/subkey"
        --env prefix                 export KV values from prefix as env varaibles
        --export                     add export to --env output
        --pristine                   not include the parent processes' environment when exec child process
        --put path:value             put value to path
        --get path                   get value from

Example config.yml:

.dbconfig: &dbconfig
  DATABASE_HOST:
    value: db
  DATABASE_NAME:
    value: dbname

srv1: &srv1
  <<: [*dbconfig]
  LOG_LEVEL:
    value: debug
  CA_CERT:
    file: /tmp/ca/cacert.pem
  CLIENT_CERT:
    value: consul://services/ca/private/cert.pem
  CLIENT_KEY:
    value: consul://services/ca/private/key.pem

srv2:
  <<: *srv1
  CA_CERT:
    value: consul://services/env/srv1/ca_cert

aggmerge

Merge docker-compose file of any version. Allow inheritance and extending services.

COMPOSE_FILE=file1.yml:file2.yml aggmerge > /tmp/result.yml