<commit_before># 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

'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

## 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][76afb1a3] and [docker-compose][82a8a185] by following their respective installation guides.

  [76afb1a3]: https://docs.docker.com/engine/installation/ "docker"
  [82a8a185]: https://docs.docker.com/compose/install/ "docker-compose"

**NB: You will need to use [direnv][459184eb] to ensure that the scripts work seamlessly.**

  [459184eb]: https://github.com/direnv/direnv "Direnv"

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 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](https://github.com/johnpapa/angular-styleguide/tree/master/a1#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.

## 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.<commit_msg>add some more info on commands<commit_after># 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

'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][76afb1a3] and [docker-compose][82a8a185] by following their respective installation guides.

  [76afb1a3]: https://docs.docker.com/engine/installation/ "docker"
  [82a8a185]: https://docs.docker.com/compose/install/ "docker-compose"

**NB: You will need to use [direnv][459184eb] to ensure that the scripts work seamlessly.**

  [459184eb]: https://github.com/direnv/direnv "Direnv"

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](https://github.com/johnpapa/angular-styleguide/tree/master/a1#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.
{'fraction_non_alphanumeric': 0.11110112359550561, 'fraction_numerical': 0.007820224719101123, 'mean_word_length': 2.282974328710534, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '694891', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2612, 'n_words': 1412}