Skip to content

Basic SOA implementation using node, rails et. al. with docker and docker-compose

License

Notifications You must be signed in to change notification settings

tyronewilson/rocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rocker

I learned a lot in the first few months of using docker. Some of what I learned has been encoded into this repo so that you can use and build on it.

Purpose

Originally created for a developer meetup and formed part of demonstration for this presentation

'Rocker' (I had to call it something) can be used as a starter project or simply as an educational guide. In essence rocker is an example project built using the following technologies and generators (in no particular order).

  • Docker
  • Docker Compose
  • Rails
  • Yeoman
  • Gulp
  • AngularJS
  • Redis
  • PostgreSQL
  • DynamoDB (local)
  • Nginx

Suite Scripts

The main working part of the code is in the glue scripts which are provided in the ./suite directory.

Prerequisites

  1. Docker
  2. Docker Compose
  3. Direnv

You can install docker and docker-compose by following their respective installation guides.

NB: You will need to use direnv to ensure that the scripts work seamlessly.

If you do not want to use direnv you can edit the suite scripts to use the relative path. This is not recommended since the relative paths will change if change working directory within the project and most of the convenience is largely moot.

Once you have direnv installed you can run the direnv allow command if required.

Overview

This demo app has the following components installed

Name Tech Notes/Comments
API Ruby on Rails /api
web NodeJS/AngularJS/BootstrapUI /
postgres PostgreSQL 9.6 postgres:5432 (internally)
dynamodb AWS DynamoDB (Local) dynamodb (internally)

Getting started

Once you have docker and docker-compose installed you can run the init command to get the development environment ready and fire up the application with the up command. This may take some time as you pull all of the docker images onto your machine as well as install gems, node and bower dependencies.

Rails API

The suite scripts allow you to write rails commands as normal. For example bundle install You will get a line of output telling you that the script is running in the api container.

$ bundle install
Running bundler in api container...
etc.

web

Included with this project is the default project generated by the angular-styleguide angular1 yeoman generator. Note that this is a good starting point but it would be very simple to use your prefered generator by clearing out the web folder and running your favourite yeoman generator instead.

Router

The router here is an Nginx based container acting as a proxy to the various app components.

App commands

The below table provides an explanation of the various files, commands and intent.

FILE COMMAND EXAMPLE PURPOSE
./suite/build build api or build To build one or more services. On it's own, the build command will build all services declared in the docker-compose.yml file
./suite/bundle bundle install or bundle update Runs bundle in the appropriate ruby based container. All of the usual commands for bundle will work except bundle open as there is no link to the text editor in the container
./suite/down down Tears down your docker-compose set up and destroys all containers. NOTE: won't destroy volume powered install cache like ./bundle
./suite/enter enter api Enter a running container instance.
./suite/follow follow router Tail a service's docker logs
./suite/init init helper for initializing development environment
./suite/ps ps or ps web Lists the status of the various services in the current stack. Note if you are running direnv you won't be able to access the native ps command as it will have effectively been overridden in the context of the app. To use the native ps you must cd .. to get out of the project root directory
./suite/psql psql launches a psql session inside of the db service container
./suite/rails rails c or rails g migration <...> Mimmicks the rails command in the console but runs inside the api container.
./suite/rake rake routes or rake db:migrate Mimmicks rake command in the api container
./suite/rebuild rebuild or rebuild <service_name> Stop, build and start all services (when none is specified) or a specific service.
./suite/remove remove dynamodb Removes the specified container from the stack. Useful if wanting to remove defunct/redundant services.
./suite/restart restart or restart router Restarts existing container ( Note: this does not build the container. If you want to build as well then use rebuild <service_name> )
./suite/retake retake Since commands run inside containers can result in files that are owned by root, this script simply claims the files back. For example running rake g migration etc. will result in a migration file that is owned by root and therefore not editable by the developer. If you find you have permissions issues on any file just run retake to recursively take back all project files.
./suite/rspec rspec or cd api && rspec spec/models Mimmicks the rspec command in the console. For ease of use change directory to the api directory when using this command and it will feel like running rspec in a bog standard rails project NOTE: this command expects a tdd service
./suite/run run <service_name> <command> e.g. run web npm install bower -g Runs command in the given service container
./suite/scale scale <service_name>=<n> e.g. scale workers=3 Scales the number of containers for a given container using the docker-compose scale command. NOTE: this is not magic and won't have an effect if your service doesn't support scaling. To scale web or api use ha proxy or nginx to load balance
./suite/start start api Starts the given service
./suite/stop stop api Stops the given service
./suite/tag tag <container> <repo> tags container with docker tag
./suite/up up -d or up web or up -d router brings up the given service either live or as a daemon ( when given the -d switch )
./suite/stats stats Shows CPU, Memory, Net and I/O stats of all running containers.

Disclaimer

This code has been used extensively on Ubuntu Linux. There are known issues when running Docker on Mac including poor start and build performances. Please do not contact me regarding Mac issues as I will not be able to help.

About

Basic SOA implementation using node, rails et. al. with docker and docker-compose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published