├── .gitignore ├── README.md ├── aws_elastic_beanstalk ├── Dockerrun.aws.json └── README.md ├── docker-compose-development.yml ├── docker-compose.yml ├── docker ├── nginxbash.sh ├── puppiesbash.sh ├── puppiesconsole.sh └── puppiespry.sh ├── docs ├── Dockerrun.aws.json-short ├── README.md ├── cli_deployments.sh ├── development_setup_example │ └── Dockerfile.development ├── docker_composer_example-2.yml └── docker_composer_example.yml ├── logs └── .gitkeep ├── nginx ├── Dockerfile └── nginx.conf └── puppies ├── .dockerignore ├── .gitignore ├── Dockerfile ├── Dockerfile.development ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── application.js │ │ ├── cable.js │ │ ├── channels │ │ │ └── .keep │ │ └── puppies.coffee │ └── stylesheets │ │ ├── application.css │ │ └── puppies.scss ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── puppies_controller.rb ├── helpers │ └── application_helper.rb ├── jobs │ ├── application_job.rb │ └── increase_like_counter_job.rb ├── models │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ └── puppy.rb └── views │ ├── layouts │ ├── application.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb │ └── puppies │ └── index.html.erb ├── bin ├── bundle ├── rails ├── rake ├── setup ├── spring └── update ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── active_job.rb │ ├── application_controller_renderer.rb │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── cache_store.rb │ ├── cookies_serializer.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── new_framework_defaults.rb │ ├── session_store.rb │ ├── sidekiq.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── secrets.yml ├── sidekiq.yml └── spring.rb ├── db ├── migrate │ └── 20161101224400_create_puppies.rb ├── schema.rb └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico └── robots.txt ├── script └── start_server.sh ├── tmp └── .keep └── vendor └── assets ├── javascripts └── .keep └── stylesheets └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS ElasticBeanstalk Ruby on Rails Docker 2 | 3 | This is a Demo application related to the talk 4 | [AWS Elastic Beanstalk & Docker for Rails developers](http://www.eq8.eu/talks/2-aws-elastic-beanstalk-and-docker-for-rails-developers) 5 | 6 | **>>>>[Talk Video](https://www.youtube.com/watch?v=xhEyUYTuSQw)<<<<** 7 | 8 | Pre-built application (puppies app) Docker images: 9 | 10 | * https://hub.docker.com/r/equivalent/eb-demo-rails/ 11 | * https://hub.docker.com/r/equivalent/eb-demo-nginx/ 12 | 13 | ## Usage 14 | 15 | Clone this repo and `cd` into it: 16 | 17 | ```sh 18 | $ git clone git@github.com:equivalent/docker_rails_aws_elasticbeanstalk_demmo_app.git 19 | $ cd docker_rails_aws_elasticbeanstalk_demmo_app 20 | ``` 21 | 22 | Once the application is running and is successfully connected to DB be sure to 23 | run `rake db:seed` inside the container. You can leart out how to run commands 24 | inside Docker container [here](https://github.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app#how-to-debug-app-in-docker-containers). 25 | 26 | ### Running production application locally 27 | 28 | Production version of `docker-compose.yml` is located in the root folder of 29 | this git repo. 30 | 31 | to run in **production** mode, all you need to do: 32 | 33 | 1. [install Docker](https://docs.docker.com/engine/installation/) and [docker-compose](https://docs.docker.com/compose/install/) 34 | 2. `$ docker-compose up` or `$ sudo docker-compose up` 35 | 36 | ##### Running application locally (development mode) 37 | 38 | `docker-compose -f docker-compose-development.yml up` 39 | 40 | ### Running production application on AWS Elastic Beanstalk 41 | 42 | Elastic Beanstalk's `Dockerrun.aws.json` is located in `./aws_elastic_beanstalk`. 43 | 44 | In that folder is separate [README.md](https://github.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/blob/master/aws_elastic_beanstalk/README.md) file containing useful information on AWS Elastic Beanstalk CLI 45 | 46 | ##### Steps to lunch "puppies" demo application in AWS Elastic Beanstalk: 47 | 48 | **Step 1:** Configure new Docker based AWS Beanstalk Enviroment, PostgreSQL RDS, Redis Elastic Cache and 49 | ensure the Security Groups are set in a way that endpoints can 50 | communicate to each other. In order to achieve this you can follow 51 | steps in this article: http://www.eq8.eu/blogs/34-set-up-aws-elastic-beanstalk 52 | 53 | ###### Web interface deployment: 54 | 55 | **Step 2:**: Once in the configured EB environment, from web interface Click "Upload" and chose 56 | `./aws_elastic_beanstalk/Dockerrun.aws.json`. 57 | 58 | ###### CLI deployment: 59 | 60 | **Step 2:**: [Install](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html) 61 | and [configure](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html) 62 | EB CLI. You can find my instructions on EB CLI [here](https://github.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/blob/master/aws_elastic_beanstalk/README.md) 63 | 64 | **Step 3:** `$ cd ./aws_elastic_beanstalk` and `$ eb deploy` 65 | 66 | ## Nginx proxy container 67 | 68 | Nginx image source code located in `./nginx` folder. 69 | 70 | 71 | ## How lunch stuff / debug app inside the Docker containers 72 | 73 | From host machine you can lunch: 74 | 75 | ```sh 76 | bash docker/puppiesbash.sh # enter bash in the puppies_web container 77 | bash docker/puppiesconsole.sh # enter rails console in the puppies_web container 78 | bash docker/puppiespry.sh # pry debugger - where you introduce `binding.pry` 79 | 80 | bash docker/nginxbash.sh # enter bash in the proxy container 81 | ``` 82 | 83 | Or manually type: 84 | 85 | ```sh 86 | docker ps 87 | docker exec -it xxIdOfAContainerxx bash 88 | ``` 89 | 90 | ## How to Build Docker image and how to push a change to Docker registry 91 | 92 | ```sh 93 | docker-compose build 94 | docker-compose push 95 | ``` 96 | 97 | ## Other Resources 98 | 99 | ##### Articles 100 | 101 | * http://www.eq8.eu/blogs/25-common-aws-elastic-beanstalk-docker-issues-and-solutions 102 | 103 | ##### How the Ruby on Rails application was generated 104 | 105 | ```bash 106 | mkdir docker_rails_aws_elasticbeanstalk_demo_app 107 | cd docker_rails_aws_elasticbeanstalk_demo_app 108 | 109 | gem install bundler rails 110 | 111 | rails new puppies --skip-test --skip-action-mailer 112 | 113 | rake db:create 114 | rake db:seed 115 | ``` 116 | -------------------------------------------------------------------------------- /aws_elastic_beanstalk/Dockerrun.aws.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSEBDockerrunVersion": 2, 3 | "volumes": [ 4 | { 5 | "name": "run_folder", 6 | "host": { 7 | "sourcePath": "/home/ec2-user/run" 8 | } 9 | }, 10 | { 11 | "name": "assets_folder", 12 | "host": { 13 | "sourcePath": "/home/ec2-user/assets" 14 | } 15 | }, 16 | { 17 | "name": "log_folder", 18 | "host": { 19 | "sourcePath": "/home/ec2-user/log" 20 | } 21 | } 22 | ], 23 | "containerDefinitions": [ 24 | { 25 | "name": "proxy", 26 | "image": "equivalent/eb-demo-nginx:v1", 27 | "essential": true, 28 | "memory": 500, 29 | "portMappings": [ 30 | { 31 | "hostPort": 80, 32 | "containerPort": 80 33 | } 34 | ], 35 | "mountPoints": [ 36 | { 37 | "sourceVolume": "run_folder", 38 | "containerPath": "/var/run" 39 | }, 40 | { 41 | "sourceVolume": "assets_folder", 42 | "containerPath": "/var/www" 43 | }, 44 | { 45 | "sourceVolume": "log_folder", 46 | "containerPath": "/var/log" 47 | } 48 | ] 49 | }, 50 | { 51 | "name": "puppies_web", 52 | "image": "equivalent/eb-demo-rails:v1", 53 | "essential": true, 54 | "memory": 600, 55 | "mountPoints": [ 56 | { 57 | "sourceVolume": "run_folder", 58 | "containerPath": "/var/run" 59 | }, 60 | { 61 | "sourceVolume": "assets_folder", 62 | "containerPath": "/var/www" 63 | }, 64 | { 65 | "sourceVolume": "log_folder", 66 | "containerPath": "/app/log" 67 | } 68 | ], 69 | "environment": [ 70 | { 71 | "name": "CONTAINER_ROLE", 72 | "value": "app_server" 73 | }, 74 | { 75 | "name": "MAX_THREADS", 76 | "value": 2 77 | }, 78 | { 79 | "name": "WEB_CONCURRENCY", 80 | "value": 1 81 | }, 82 | { 83 | "name": "RAILS_SERVE_STATIC_FILES", 84 | "value": "false" 85 | }, 86 | { 87 | "name": "RAILS_ENV", 88 | "value": "production" 89 | }, 90 | { 91 | "name": "REDIS_HOST", 92 | "value": "puppies.qgminx.0001.euw1.cache.amazonaws.com" 93 | }, 94 | { 95 | "name": "REDIS_PORT", 96 | "value": 6379 97 | }, 98 | { 99 | "name": "REDIS_DB_ID", 100 | "value": 0 101 | }, 102 | { 103 | "name": "REL_DATABASE_HOST", 104 | "value": "puppies-demo.cverdzyuvijq.eu-west-1.rds.amazonaws.com" 105 | }, 106 | { 107 | "name": "REL_DATABASE_PORT", 108 | "value": "5432" 109 | }, 110 | { 111 | "name": "REL_DATABASE_USERNAME", 112 | "value": "puppies" 113 | }, 114 | { 115 | "name": "REL_DATABASE_DATABASE", 116 | "value": "puppies" 117 | }, 118 | { 119 | "name": "REL_DATABASE_PASSWORD", 120 | "value": "puppiespuppies" 121 | }, 122 | { 123 | "name": "SECRET_KEY_BASE", 124 | "value": "99999_this_should_be_set_in_ElasticBeanstark_ENV_variable_not_commited_in_git_b35d63e353a1472057e90f8c4" 125 | } 126 | ] 127 | }, 128 | { 129 | "name": "puppies_bg_worker", 130 | "image": "equivalent/eb-demo-rails:v1", 131 | "essential": true, 132 | "memory": 600, 133 | "mountPoints": [ 134 | { 135 | "sourceVolume": "run_folder", 136 | "containerPath": "/var/run/" 137 | }, 138 | { 139 | "sourceVolume": "log_folder", 140 | "containerPath": "/app/log" 141 | } 142 | ], 143 | "environment": [ 144 | { 145 | "name": "CONTAINER_ROLE", 146 | "value": "bg_worker" 147 | }, 148 | { 149 | "name": "MAX_THREADS", 150 | "value": 3 151 | }, 152 | { 153 | "name": "RAILS_ENV", 154 | "value": "production" 155 | }, 156 | { 157 | "name": "REDIS_HOST", 158 | "value": "puppies.qgminx.0001.euw1.cache.amazonaws.com" 159 | }, 160 | { 161 | "name": "REDIS_PORT", 162 | "value": 6379 163 | }, 164 | { 165 | "name": "REDIS_DB_ID", 166 | "value": 0 167 | }, 168 | { 169 | "name": "REL_DATABASE_HOST", 170 | "value": "puppies-demo.cverdzyuvijq.eu-west-1.rds.amazonaws.com" 171 | }, 172 | { 173 | "name": "REL_DATABASE_PORT", 174 | "value": "5432" 175 | }, 176 | { 177 | "name": "REL_DATABASE_USERNAME", 178 | "value": "puppies" 179 | }, 180 | { 181 | "name": "REL_DATABASE_DATABASE", 182 | "value": "puppies" 183 | }, 184 | { 185 | "name": "REL_DATABASE_PASSWORD", 186 | "value": "puppiespuppies" 187 | }, 188 | { 189 | "name": "SECRET_KEY_BASE", 190 | "value": "99999_this_should_be_set_in_ElasticBeanstark_ENV_variable_not_commited_in_git_b35d63e353a1472057e90f8c4" 191 | } 192 | ] 193 | } 194 | ] 195 | } 196 | -------------------------------------------------------------------------------- /aws_elastic_beanstalk/README.md: -------------------------------------------------------------------------------- 1 | # EB CLI 2 | 3 | 4 | 5 | I recommend to create a new AWS EB application via Web interface as 6 | described in this article: http://www.eq8.eu/blogs/34-set-up-aws-elastic-beanstalk 7 | and only then use this app 8 | 9 | http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html 10 | 11 | 12 | ## Install 13 | 14 | 15 | Since 2019 the instalation process of AWS EB CLI has changed ([source](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html)) 16 | In ordrer to install the CLI you need to clone and run this repo: https://github.com/aws/aws-elastic-beanstalk-cli-setup 17 | 18 | 19 | 20 | ### config 21 | 22 | ``` 23 | eb init # set up your login and region 24 | # Go to AWS Identity and Access Management (IAM) product and 25 | # create a new user => that will generete credentials (secret 26 | # ID and key) 27 | 28 | ``` 29 | 30 | `eb init` will generate file in `~/.aws/config` with your AWS credentials and 31 | will generate `.elasticbeanstalk/config.yml` in this folder. The content 32 | will be similar to this: 33 | 34 | ``` 35 | branch-defaults: 36 | default: 37 | environment: puppiesDemo-env 38 | environment-defaults: 39 | puppiesDemo-env: 40 | branch: null 41 | repository: null 42 | global: 43 | application_name: puppies-demo 44 | default_ec2_keyname: puppies 45 | default_platform: 64bit Amazon Linux 2016.09 v2.2.0 running 46 | Multi-container Docker 47 | 1.11.2 (Generic) 48 | default_region: eu-west-1 49 | profile: eb-cli 50 | sc: null 51 | ``` 52 | 53 | ### Usage 54 | 55 | In all examples I expect that you've `cd` to the folder where this README.md file 56 | is located. 57 | 58 | ```sh 59 | cd docker_rails_aws_elasticbeanstalk_demmo_app/aws_elastic_beanstalk/ 60 | ``` 61 | 62 | ##### Deployment 63 | 64 | ```sh 65 | eb deploy 66 | ``` 67 | 68 | ##### Status and events 69 | 70 | ```sh 71 | eb status 72 | eb event 73 | ``` 74 | 75 | ##### SSH to the server 76 | 77 | Given you have the Puppies.pem in your `~/.ssh/` folder 78 | 79 | ```sh 80 | eb ssh 81 | ``` 82 | 83 | 84 | 85 | -------------- 86 | 87 | # Old instructions 88 | 89 | 90 | ### how to install (old not working) 91 | 92 | * http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html 93 | * http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html 94 | 95 | ``` 96 | # pip is python package manager 97 | 98 | pip install --upgrade --user awsebcli # install eb cli 99 | ``` 100 | -------------------------------------------------------------------------------- /docker-compose-development.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | db_dev: 4 | image: postgres:9.5.1 5 | environment: 6 | POSTGRES_PASSWORD: mysecretlocalpassword 7 | POSTGRES_USER: postgres 8 | POSTGRES_DB: puppies_app 9 | sharedbox: 10 | image: busybox 11 | volumes: 12 | - /var/www 13 | - /var/run 14 | redis_dev: 15 | image: redis 16 | proxy: 17 | image: puppies_nginx_development 18 | build: 19 | context: ./nginx 20 | dockerfile: Dockerfile # we mean the ./nginx/Dockerfile 21 | volumes: 22 | - ./logs:/var/log 23 | volumes_from: 24 | - sharedbox 25 | ports: 26 | - "80:80" 27 | depends_on: 28 | - puppies_web 29 | puppies_web: 30 | image: puppies_app_development 31 | build: 32 | context: ./puppies 33 | dockerfile: Dockerfile.development 34 | environment: &app_server_enviroment_vars 35 | CONTAINER_ROLE: 'app_server' 36 | RAILS_ENV: production 37 | MAX_THREADS: 2 38 | WEB_CONCURRENCY: 1 39 | SECRET_KEY_BASE: 19d07059ab81ff584bd8fd7be03ed765c63f5f4c3518d05f39b41c7152134e294b2f09cbf5d925045caab0ef6475862fc42c8e6b35d63e353a1472057e90f8c4 40 | 41 | REL_DATABASE_PASSWORD: mysecretlocalpassword 42 | REL_DATABASE_USERNAME: postgres 43 | REL_DATABASE_DATABASE: puppies_app 44 | REL_DATABASE_HOST: db_dev 45 | REL_DATABASE_PORT: 5432 46 | 47 | REDIS_HOST: redis_dev 48 | REDIS_PORT: 6379 49 | REDIS_DB_ID: 0 50 | volumes: 51 | - ./logs:/app/log 52 | volumes_from: 53 | - sharedbox 54 | links: 55 | - db_dev 56 | - redis_dev 57 | puppies_bg_worker: 58 | image: puppies_app_development 59 | environment: 60 | <<: *app_server_enviroment_vars 61 | CONTAINER_ROLE: 'bg_worker' 62 | MAX_THREADS: 5 # Sidekiq threads, watch out so you don't run out of DB connection pool 63 | volumes: 64 | - ./logs:/app/log 65 | volumes_from: 66 | - sharedbox 67 | links: 68 | - db_dev 69 | - redis_dev 70 | depends_on: 71 | - puppies_web 72 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | db: 4 | image: postgres:9.5.1 5 | environment: 6 | POSTGRES_PASSWORD: mysecretlocalpassword 7 | POSTGRES_USER: postgres 8 | POSTGRES_DB: puppies_app 9 | sharedbox: 10 | image: busybox 11 | volumes: 12 | - /var/www 13 | - /var/run 14 | redis: 15 | image: redis 16 | proxy: 17 | image: equivalent/eb-demo-nginx:v1 18 | build: 19 | context: ./nginx 20 | dockerfile: Dockerfile # we mean the ./nginx/Dockerfile 21 | volumes: 22 | - ./logs:/var/log 23 | volumes_from: 24 | - sharedbox 25 | ports: 26 | - "80:80" 27 | depends_on: 28 | - puppies_web 29 | puppies_web: 30 | image: equivalent/eb-demo-rails:v1 31 | build: 32 | context: ./puppies 33 | dockerfile: Dockerfile # we mean the ./puppies/Dockerfile 34 | environment: &app_server_enviroment_vars 35 | CONTAINER_ROLE: 'app_server' 36 | RAILS_ENV: production 37 | MAX_THREADS: 2 # Puma threads, watch out so you don't run out of DB connection pool 38 | WEB_CONCURRENCY: 1 # should match CPU of server 39 | SECRET_KEY_BASE: 19d07059ab81ff584bd8fd7be03ed765c63f5f4c3518d05f39b41c7152134e294b2f09cbf5d925045caab0ef6475862fc42c8e6b35d63e353a1472057e90f8c4 40 | 41 | REL_DATABASE_PASSWORD: mysecretlocalpassword 42 | REL_DATABASE_USERNAME: postgres 43 | REL_DATABASE_DATABASE: puppies_app 44 | REL_DATABASE_HOST: db 45 | REL_DATABASE_PORT: 5432 46 | 47 | REDIS_HOST: redis 48 | REDIS_PORT: 6379 49 | REDIS_DB_ID: 0 # id of redis db 50 | volumes: 51 | - ./logs:/app/log 52 | volumes_from: 53 | - sharedbox 54 | links: 55 | - db 56 | - redis 57 | puppies_bg_worker: 58 | image: equivalent/eb-demo-rails:v1 59 | environment: 60 | <<: *app_server_enviroment_vars 61 | CONTAINER_ROLE: 'bg_worker' 62 | MAX_THREADS: 5 # Sidekiq threads, watch out so you don't run out of DB connection pool 63 | volumes: 64 | - ./logs:/app/log 65 | volumes_from: 66 | - sharedbox 67 | links: 68 | - db 69 | - redis 70 | depends_on: 71 | - puppies_web 72 | -------------------------------------------------------------------------------- /docker/nginxbash.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | docker exec -it $(docker ps | grep nginx | ruby -ne 'puts $_.split.first') bash 3 | -------------------------------------------------------------------------------- /docker/puppiesbash.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | docker exec -it $(docker ps | grep puppies_web | ruby -ne 'puts $_.split.first') bash 3 | -------------------------------------------------------------------------------- /docker/puppiesconsole.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | docker exec -it $(docker ps | grep puppies_web | ruby -ne 'puts $_.split.first') rails c 3 | 4 | -------------------------------------------------------------------------------- /docker/puppiespry.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | docker exec -it $(docker ps | grep puppies_web | ruby -ne 'puts $_.split.first') pry-remote 3 | -------------------------------------------------------------------------------- /docs/Dockerrun.aws.json-short: -------------------------------------------------------------------------------- 1 | { 2 | "AWSEBDockerrunVersion": 2, 3 | "containerDefinitions": [ 4 | # .... 5 | { 6 | "name": "puppies_web", 7 | "image": "equivalent/eb-demo-rails:v1", 8 | "memory": 600, 9 | # .... 10 | "environment": [ 11 | # .... 12 | { 13 | "name": "REDIS_HOST", 14 | "value": "puppies.qgminx.0001.euw1.cache.amazonaws.com" 15 | }, 16 | # .... 17 | { 18 | "name": "REL_DATABASE_HOST", 19 | "value": "puppies-demo.cverdzyuvijq.eu-west-1.rds.amazonaws.com" 20 | }, 21 | # .... 22 | } 23 | ] 24 | }, 25 | { 26 | "name": "puppies_bg_worker", 27 | "image": "equivalent/eb-demo-rails:v1", 28 | "environment": [ 29 | # .... 30 | ] 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | ## Outline 2 | 3 | 4 | In terms of structure of this talk, I first want to talk about philosophy of Docker 5 | deployments, then philosophy of how Amazon Web Services look at 6 | infrastructure in terms of their products, 7 | then some theory of what is ElasticBeanstalk and how to use it. 8 | And at the very end I'll show you some real examples. 9 | 10 | ## Example Application 11 | 12 | In this talk we will be describing deployment of an example application 13 | in which we will have our "cool Ruby on Rails" application. 14 | Of course we need some background processing worker. This can be either 15 | Resque, Background Job or Sidekiq. 16 | 17 | As for the primary relational data storage we will use PostgreSQL. For 18 | data cache and background worker primary data store we will use Redis. 19 | And we will use Nginx for some web-server/app-server proxy heavy lifting. 20 | 21 | 22 | ## Clasic Approach 23 | 24 | Now the clasic approch would be to set up and configure all these 25 | technologies on your laptop and then setup the technologies on 26 | Server either manually or using Puppet or Chef or Capistrano (or whatever). 27 | 28 | Then once all this is done we will just deploy the code to this server. 29 | 30 | ## Docker Approach 31 | 32 | Now with the Docker Approach you would wrap every individual technology 33 | into "Docker image" that is shipable with all it's configuration and content. 34 | 35 | I don't want to go into too much depth of how 36 | Docker really works, there are already many better talks explaining that. In 37 | brief you can think about Docker image as you would about virtual machine image, 38 | meaning it's entire stack from Operating System layer till the 39 | technology you are using. 40 | 41 | Amongs other, the main difference is that Docker image consist of layers that are based on 42 | ordered root fylesystem changes and those layers can be cached. 43 | Therfore you only deploy the top layers that has been changed. 44 | 45 | For example in our Ruby on Rails web image, if I make a code change maybe 46 | only 1 or 2 layers are changed. If I update a gem and bundler needs to 47 | run. it will be more layers. Even more layes if I change ruby version 48 | and so on. 49 | 50 | Another nice thing is that you can share lot of the bottom layers 51 | between different images. 52 | 53 | But the point is you are not transfering 1GB image but only few 54 | Megabytes, depening on layer change size. 55 | 56 | 57 | In order to actually use your Images in production server, the main 58 | approach is that you build your images in your laptop, you test if 59 | everything work, you push them to so-called "Docker Regigistry" and you tell your 60 | server to pull those images. 61 | Now again the nice thing is that your server will pull only those layers 62 | that were changed. 63 | 64 | If you think "hmm this kinda resamble how Capistrano local git -, 65 | Github - server git deployment works" then you are getting the point. 66 | 67 | There is also a different approach that you don't build your docker 68 | images in your laptop, but rather cloud solutions will build docker 69 | image each time you push a code change to Github, and maybe even deploy those to your server. 70 | But these solutions are outside the scope of this talk. 71 | 72 | But the core idea is that Docker image is in the Registry and Server pulls those images. 73 | 74 | 75 | ## Linking Docker Containers 76 | 77 | Now once you've deployed your docker images you want to lunch them. 78 | 79 | Runtime instances of Docker image is called "Docker Container" that's 80 | why I'll be refering about these boxes as "containers" rather than 81 | "images" 82 | 83 | You want to lunch your instances so that relevant containers 84 | are linked to each other. 85 | 86 | You can achive this bu using direct `docker run` options: 87 | 88 | ``` 89 | docker run -d --name puppies_web --link db:db puppies_rails 90 | ``` 91 | 92 | ...but in reality this command gets too long. 93 | 94 | Better way is to use `docker-composer` which will basically achive the 95 | same by loading configuration from YAML file. 96 | 97 | The "linking" will end up setting your `/etc/hosts` with the host 98 | reference, so all you will have to do in your application is tell it 99 | that you want to connect to host "db" or host "redis" 100 | 101 | In reality there is more then just `link`. You need to set environment 102 | variables, mount volumes and so on. But this is the basic principal. 103 | 104 | 105 | ## Inside VM 106 | 107 | So on your server or VM you will end up with fully linked containers. 108 | 109 | But one thing lot of developers missed out is that you can split out 110 | different containers to different VMs. 111 | 112 | Let say you extract your 113 | Relational Database container to one VM, your Redis container to another 114 | VM and your keep one VM to the core Application containers. 115 | You specially need to do this if you dealing with Load Ballanced 116 | enviroment which we will talk about soon. 117 | 118 | You can split this even further if you discover that your Application VM is runnig out of 119 | memory or you want introduce more Threads for puma server you can 120 | extract your worker out to own VM too. 121 | 122 | 123 | # AWS approach 124 | 125 | Now we finally getting to the part were we start talking about AWS and 126 | AWS Elastic Beanstalk 127 | 128 | # AWS approach to infrastructure 129 | 130 | First we need to understand how AWS look at your infrastructure 131 | . AWS been on the market for quite some time, they introduced 132 | many products and solutions for pretty much any problem that 133 | web-application may have. 134 | 135 | I'll just mention some that will be needed for this talk. 136 | 137 | I think pretty much everyone worked with S3 simple storage, at least everyone who was 138 | trying to upload images on a Heroku application. 139 | 140 | EC2 is prety much their product for provisioning VMs 141 | 142 | ELB is a loadbalancer product, so basically when you need to distribute 143 | load between multiple EC2 instances 144 | 145 | RDS is their Relational Database Solution, so you can run your Postgres 146 | database and they will take care of snapshots and recovery Really easy 147 | straight forward tool to use. 148 | 149 | ElasticCache is similar thing like RDS but for Redis or Memcache 150 | clusters. 151 | 152 | and CloudWatch is for monitoring of resources. 153 | 154 | 155 | Now you can imagine that instead of of our Postges container we will connect 156 | our application containers to the Postgres RDS product, 157 | Instead of Redis container we would connect to ElasticCache Redis 158 | product. 159 | 160 | So that means that all that is left is to deploy our application, worker and nginx 161 | container to an EC2 instance. 162 | 163 | This kind of separation helps when we need horizontal scaling. If the 164 | load on our website grow we will introduce more and more EC2 instances 165 | running our containers. Once the load is over we will discale them. This 166 | metricks are provided by AWS CloudWatch product. 167 | 168 | ## AWS Elastic Beanstalk 169 | 170 | That finally brings us to definition of what is Elastic Beanstalk. 171 | It's is another product of Amazon Web Services, that provides an easy 172 | way to setup your EC2 instances in Load Balanced enviroment. Think about 173 | it as a Seftware Wizard were you click next, next, next and you have 174 | your Environment set up. 175 | 176 | As part of that it will configure some basic CloudWatch setup and some basic 177 | scaling and descaling configuration of instances. For examples you will 178 | just specify that if the CPU load is bigger than 70% let it introduce 179 | new instance, if it's lower than 10% remove an EC2 instance. 180 | 181 | Elastic Beanstalk also provides a CLI tool. Now I would dare to compare this CLI tool to 182 | Heroku CLI in a sence that you type just one command `eb deploy` and boom your version 183 | is deployed, or `eb status` or `eb events` and you see what is happening in your environment. 184 | but it's definitelly not as much sophisticated as the Heroku one. I'll talk more 185 | about it later in the talk. 186 | 187 | Worth mentioning is that The Elastic Beanstalk suports not only Docker 188 | but also native Ruby and lot of other Languages. Now I want to keep this 189 | talk Docker based as that is the one that I have experiences with 190 | this product. 191 | 192 | 193 | ## AWS Elastic Beanstalk with Docker 194 | 195 | Similar to `docker-composer`'s provisioning from yaml config file, Elastic Beanstalk Docker 196 | has similar approach based on JSON config file. 197 | 198 | 199 | -------------------------------------------------------------------------------- /docs/cli_deployments.sh: -------------------------------------------------------------------------------- 1 | 2 | $ git clone git@github.com:equivalent/docker_rails_aws_elasticbeanstalk_demmo_app.git 3 | $ cd docker_rails_aws_elasticbeanstalk_demmo_app/ 4 | 5 | $ docker-composer build 6 | $ docker-composer push 7 | 8 | $ cd aws_elastic_beanstalk 9 | $ ls Dockerrun.aws.json README.md 10 | 11 | # $ eb init # login + initialize EB env 12 | $ eb deploy 13 | 14 | $ eb status 15 | $ eb events 16 | 17 | $ eb ssh 18 | -------------------------------------------------------------------------------- /docs/development_setup_example/Dockerfile.development: -------------------------------------------------------------------------------- 1 | FROM ruby:2.3.1 2 | 3 | RUN gem install bundler 4 | 5 | # Preinstall gems. This will ensure that Gem Cache wont drop on code change 6 | WORKDIR /tmp 7 | ADD ./Gemfile Gemfile 8 | ADD ./Gemfile.lock Gemfile.lock 9 | RUN (bundle check || bundle install) 10 | 11 | RUN mkdir /app 12 | ADD ./ /app 13 | WORKDIR /app 14 | RUN (bundle check || bundle install) 15 | 16 | ADD ./docker/start_server.sh /usr/local/bin/ 17 | CMD bash /usr/local/bin/start_server.sh 18 | -------------------------------------------------------------------------------- /docs/docker_composer_example-2.yml: -------------------------------------------------------------------------------- 1 | services: 2 | proxy: 3 | image: nginx 4 | puppies_web: 5 | image: equivalent/eb-demo-rails:v1 6 | environment: 7 | REL_DATABASE_HOST: 88.123.456.789 8 | REL_DATABASE_PORT: 5432 9 | # .......... 10 | REDIS_HOST: 83.123.456.789 11 | REDIS_PORT: 6379 12 | # .......... 13 | links: 14 | - proxy 15 | puppies_bg_worker: 16 | image: equivalent/eb-demo-rails:v1 17 | environment: 18 | REL_DATABASE_HOST: 88.123.456.789 19 | REL_DATABASE_PORT: 5432 20 | # .......... 21 | REDIS_HOST: 83.123.456.789 22 | REDIS_PORT: 6379 23 | # .......... 24 | -------------------------------------------------------------------------------- /docs/docker_composer_example.yml: -------------------------------------------------------------------------------- 1 | services: 2 | db: 3 | image: postgres:9.5.1 4 | environment: 5 | # .......... 6 | redis: 7 | image: redis 8 | proxy: 9 | image: nginx 10 | puppies_web: 11 | image: equivalent/eb-demo-rails:v1 12 | environment: 13 | # .......... 14 | links: 15 | - db 16 | - redis 17 | - proxy 18 | puppies_bg_worker: 19 | image: equivalent/eb-demo-rails:v1 20 | environment: 21 | # .......... 22 | links: 23 | - db 24 | - redis 25 | -------------------------------------------------------------------------------- /logs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/logs/.gitkeep -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:latest 2 | 3 | ADD ./nginx.conf /etc/nginx/nginx.conf 4 | -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | user root; 2 | 3 | error_log /var/log/puppies-nginx-error.log; 4 | pid /var/run/puppies-nginx.pid; 5 | 6 | events { 7 | worker_connections 8096; 8 | multi_accept on; 9 | use epoll; 10 | } 11 | 12 | http { 13 | include /etc/nginx/mime.types; 14 | default_type application/octet-stream; 15 | 16 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 17 | '$status $body_bytes_sent "$http_referer" ' 18 | '"$http_user_agent" "$http_x_forwarded_for"'; 19 | 20 | access_log /var/log/puppies-nginx-access.log main; 21 | 22 | sendfile on; 23 | tcp_nopush on; 24 | tcp_nodelay on; 25 | keepalive_timeout 10; 26 | 27 | upstream appserver { 28 | server unix:///var/run/puppies-puma-app.sock; 29 | } 30 | 31 | server { 32 | listen 80 default_server; 33 | root /var/www/public; 34 | client_max_body_size 16m; 35 | 36 | location ^~ /assets/ { 37 | gzip_static on; 38 | expires max; 39 | add_header Cache-Control public; 40 | } 41 | 42 | try_files $uri/index.html $uri @appserver; 43 | location @appserver { 44 | proxy_set_header Host $host; 45 | proxy_set_header X-Real-IP $remote_addr; 46 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 47 | proxy_set_header X-Forwarded-Host $server_name; 48 | proxy_set_header Client-IP $remote_addr; 49 | proxy_pass http://appserver; 50 | } 51 | 52 | access_log /var/log/puppies-nginx-access.log; 53 | error_log /var/log/puppies-nginx-error.log debug; 54 | error_page 500 502 503 504 /500.html; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /puppies/.dockerignore: -------------------------------------------------------------------------------- 1 | log 2 | tmp 3 | -------------------------------------------------------------------------------- /puppies/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | public/assets 20 | 21 | # Ignore Byebug command history file. 22 | .byebug_history 23 | -------------------------------------------------------------------------------- /puppies/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.3.1 2 | 3 | # check Dockerfile.development for development version of dockerfile 4 | 5 | RUN gem install bundler 6 | 7 | # Preinstall gems. This will ensure that Gem Cache wont drop on code change 8 | WORKDIR /tmp 9 | ADD ./Gemfile Gemfile 10 | ADD ./Gemfile.lock Gemfile.lock 11 | RUN (bundle check || bundle install --without development test) 12 | 13 | RUN mkdir /app 14 | ADD . /app 15 | WORKDIR /app 16 | RUN (bundle check || bundle install --without development test) 17 | 18 | RUN RAILS_ENV=production rake assets:precompile 19 | 20 | CMD bash script/start_server.sh 21 | -------------------------------------------------------------------------------- /puppies/Dockerfile.development: -------------------------------------------------------------------------------- 1 | FROM ruby:2.3.1 2 | 3 | RUN gem install bundler 4 | 5 | # Preinstall gems. This will ensure that Gem Cache wont drop on code change 6 | WORKDIR /tmp 7 | ADD ./Gemfile Gemfile 8 | ADD ./Gemfile.lock Gemfile.lock 9 | RUN (bundle check || bundle install) 10 | 11 | RUN mkdir /app 12 | ADD ./ /app 13 | WORKDIR /app 14 | RUN (bundle check || bundle install) 15 | 16 | CMD bash script/start_server.sh 17 | -------------------------------------------------------------------------------- /puppies/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Ruby on Rails Web Framework 4 | gem 'rails', '~> 5.0.0', '>= 5.0.0.1' 5 | 6 | # PostgreSQL database 7 | gem 'pg' 8 | 9 | # Use Puma as the app server 10 | gem 'puma', '~> 3.0' 11 | gem 'sidekiq' 12 | 13 | # Use SCSS for stylesheets 14 | gem 'sass-rails', '~> 5.0' 15 | # Use Uglifier as compressor for JavaScript assets 16 | gem 'uglifier', '>= 1.3.0' 17 | # Use CoffeeScript for .coffee assets and views 18 | gem 'coffee-rails', '~> 4.2' 19 | # See https://github.com/rails/execjs#readme for more supported runtimes 20 | gem 'therubyracer', platforms: :ruby 21 | 22 | # Use jquery as the JavaScript library 23 | gem 'jquery-rails' 24 | # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 25 | gem 'turbolinks', '~> 5' 26 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 27 | gem 'jbuilder', '~> 2.5' 28 | 29 | gem 'redis' 30 | gem 'redis-rails' 31 | 32 | # Use Redis adapter to run Action Cable in production 33 | # gem 'redis', '~> 3.0' 34 | # Use ActiveModel has_secure_password 35 | # gem 'bcrypt', '~> 3.1.7' 36 | 37 | group :development, :test do 38 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 39 | gem 'byebug', platform: :mri 40 | gem 'pry' 41 | gem 'pry-remote' 42 | end 43 | 44 | group :development do 45 | # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 46 | gem 'web-console' 47 | gem 'listen', '~> 3.0.5' 48 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 | gem 'spring' 50 | gem 'spring-watcher-listen', '~> 2.0.0' 51 | end 52 | 53 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 54 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 55 | -------------------------------------------------------------------------------- /puppies/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.0.0.1) 5 | actionpack (= 5.0.0.1) 6 | nio4r (~> 1.2) 7 | websocket-driver (~> 0.6.1) 8 | actionmailer (5.0.0.1) 9 | actionpack (= 5.0.0.1) 10 | actionview (= 5.0.0.1) 11 | activejob (= 5.0.0.1) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.0.0.1) 15 | actionview (= 5.0.0.1) 16 | activesupport (= 5.0.0.1) 17 | rack (~> 2.0) 18 | rack-test (~> 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.0.0.1) 22 | activesupport (= 5.0.0.1) 23 | builder (~> 3.1) 24 | erubis (~> 2.7.0) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 27 | activejob (5.0.0.1) 28 | activesupport (= 5.0.0.1) 29 | globalid (>= 0.3.6) 30 | activemodel (5.0.0.1) 31 | activesupport (= 5.0.0.1) 32 | activerecord (5.0.0.1) 33 | activemodel (= 5.0.0.1) 34 | activesupport (= 5.0.0.1) 35 | arel (~> 7.0) 36 | activesupport (5.0.0.1) 37 | concurrent-ruby (~> 1.0, >= 1.0.2) 38 | i18n (~> 0.7) 39 | minitest (~> 5.1) 40 | tzinfo (~> 1.1) 41 | arel (7.1.4) 42 | builder (3.2.2) 43 | byebug (9.0.6) 44 | coffee-rails (4.2.1) 45 | coffee-script (>= 2.2.0) 46 | railties (>= 4.0.0, < 5.2.x) 47 | coffee-script (2.4.1) 48 | coffee-script-source 49 | execjs 50 | coffee-script-source (1.10.0) 51 | concurrent-ruby (1.0.2) 52 | connection_pool (2.2.0) 53 | debug_inspector (0.0.2) 54 | erubis (2.7.0) 55 | execjs (2.7.0) 56 | ffi (1.9.14) 57 | globalid (0.3.7) 58 | activesupport (>= 4.1.0) 59 | i18n (0.7.0) 60 | jbuilder (2.6.0) 61 | activesupport (>= 3.0.0, < 5.1) 62 | multi_json (~> 1.2) 63 | jquery-rails (4.2.1) 64 | rails-dom-testing (>= 1, < 3) 65 | railties (>= 4.2.0) 66 | thor (>= 0.14, < 2.0) 67 | libv8 (3.16.14.15) 68 | listen (3.0.8) 69 | rb-fsevent (~> 0.9, >= 0.9.4) 70 | rb-inotify (~> 0.9, >= 0.9.7) 71 | loofah (2.0.3) 72 | nokogiri (>= 1.5.9) 73 | mail (2.6.4) 74 | mime-types (>= 1.16, < 4) 75 | method_source (0.8.2) 76 | mime-types (3.1) 77 | mime-types-data (~> 3.2015) 78 | mime-types-data (3.2016.0521) 79 | mini_portile2 (2.1.0) 80 | minitest (5.9.1) 81 | multi_json (1.12.1) 82 | nio4r (1.2.1) 83 | nokogiri (1.6.8.1) 84 | mini_portile2 (~> 2.1.0) 85 | pg (0.19.0) 86 | puma (3.6.0) 87 | rack (2.0.1) 88 | rack-protection (1.5.3) 89 | rack 90 | rack-test (0.6.3) 91 | rack (>= 1.0) 92 | rails (5.0.0.1) 93 | actioncable (= 5.0.0.1) 94 | actionmailer (= 5.0.0.1) 95 | actionpack (= 5.0.0.1) 96 | actionview (= 5.0.0.1) 97 | activejob (= 5.0.0.1) 98 | activemodel (= 5.0.0.1) 99 | activerecord (= 5.0.0.1) 100 | activesupport (= 5.0.0.1) 101 | bundler (>= 1.3.0, < 2.0) 102 | railties (= 5.0.0.1) 103 | sprockets-rails (>= 2.0.0) 104 | rails-dom-testing (2.0.1) 105 | activesupport (>= 4.2.0, < 6.0) 106 | nokogiri (~> 1.6.0) 107 | rails-html-sanitizer (1.0.3) 108 | loofah (~> 2.0) 109 | railties (5.0.0.1) 110 | actionpack (= 5.0.0.1) 111 | activesupport (= 5.0.0.1) 112 | method_source 113 | rake (>= 0.8.7) 114 | thor (>= 0.18.1, < 2.0) 115 | rake (11.3.0) 116 | rb-fsevent (0.9.7) 117 | rb-inotify (0.9.7) 118 | ffi (>= 0.5.0) 119 | redis (3.3.1) 120 | redis-actionpack (5.0.0) 121 | actionpack (>= 4.0.0, < 6) 122 | redis-rack (~> 2.0.0.pre) 123 | redis-store (~> 1.2.0.pre) 124 | redis-activesupport (5.0.1) 125 | activesupport (>= 3, < 6) 126 | redis-store (~> 1.2.0) 127 | redis-rack (2.0.0) 128 | rack (~> 2.0) 129 | redis-store (~> 1.2.0) 130 | redis-rails (5.0.1) 131 | redis-actionpack (~> 5.0.0) 132 | redis-activesupport (~> 5.0.0) 133 | redis-store (~> 1.2.0) 134 | redis-store (1.2.0) 135 | redis (>= 2.2) 136 | ref (2.0.0) 137 | sass (3.4.22) 138 | sass-rails (5.0.6) 139 | railties (>= 4.0.0, < 6) 140 | sass (~> 3.1) 141 | sprockets (>= 2.8, < 4.0) 142 | sprockets-rails (>= 2.0, < 4.0) 143 | tilt (>= 1.1, < 3) 144 | sidekiq (4.2.4) 145 | concurrent-ruby (~> 1.0) 146 | connection_pool (~> 2.2, >= 2.2.0) 147 | rack-protection (>= 1.5.0) 148 | redis (~> 3.2, >= 3.2.1) 149 | spring (2.0.0) 150 | activesupport (>= 4.2) 151 | spring-watcher-listen (2.0.1) 152 | listen (>= 2.7, < 4.0) 153 | spring (>= 1.2, < 3.0) 154 | sprockets (3.7.0) 155 | concurrent-ruby (~> 1.0) 156 | rack (> 1, < 3) 157 | sprockets-rails (3.2.0) 158 | actionpack (>= 4.0) 159 | activesupport (>= 4.0) 160 | sprockets (>= 3.0.0) 161 | therubyracer (0.12.2) 162 | libv8 (~> 3.16.14.0) 163 | ref 164 | thor (0.19.1) 165 | thread_safe (0.3.5) 166 | tilt (2.0.5) 167 | turbolinks (5.0.1) 168 | turbolinks-source (~> 5) 169 | turbolinks-source (5.0.0) 170 | tzinfo (1.2.2) 171 | thread_safe (~> 0.1) 172 | uglifier (3.0.2) 173 | execjs (>= 0.3.0, < 3) 174 | web-console (3.3.1) 175 | actionview (>= 5.0) 176 | activemodel (>= 5.0) 177 | debug_inspector 178 | railties (>= 5.0) 179 | websocket-driver (0.6.4) 180 | websocket-extensions (>= 0.1.0) 181 | websocket-extensions (0.1.2) 182 | 183 | PLATFORMS 184 | ruby 185 | 186 | DEPENDENCIES 187 | byebug 188 | coffee-rails (~> 4.2) 189 | jbuilder (~> 2.5) 190 | jquery-rails 191 | listen (~> 3.0.5) 192 | pg 193 | puma (~> 3.0) 194 | rails (~> 5.0.0, >= 5.0.0.1) 195 | redis 196 | redis-rails 197 | sass-rails (~> 5.0) 198 | sidekiq 199 | spring 200 | spring-watcher-listen (~> 2.0.0) 201 | therubyracer 202 | turbolinks (~> 5) 203 | tzinfo-data 204 | uglifier (>= 1.3.0) 205 | web-console 206 | 207 | BUNDLED WITH 208 | 1.13.6 209 | -------------------------------------------------------------------------------- /puppies/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | -------------------------------------------------------------------------------- /puppies/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /puppies/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /puppies/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/app/assets/images/.keep -------------------------------------------------------------------------------- /puppies/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /puppies/app/assets/javascripts/cable.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the rails generate channel command. 3 | // 4 | //= require action_cable 5 | //= require_self 6 | //= require_tree ./channels 7 | 8 | (function() { 9 | this.App || (this.App = {}); 10 | 11 | App.cable = ActionCable.createConsumer(); 12 | 13 | }).call(this); 14 | -------------------------------------------------------------------------------- /puppies/app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/app/assets/javascripts/channels/.keep -------------------------------------------------------------------------------- /puppies/app/assets/javascripts/puppies.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /puppies/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /puppies/app/assets/stylesheets/puppies.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the puppies controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | body { 5 | background-color: pink; 6 | } 7 | .puppy { 8 | width: 33%; 9 | float: left; 10 | img { 11 | max-width: 400px; 12 | max-height: 300px; 13 | border: white 2px solid; 14 | } 15 | a { 16 | text-decoration: none; 17 | color: red; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /puppies/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /puppies/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /puppies/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | end 4 | -------------------------------------------------------------------------------- /puppies/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /puppies/app/controllers/puppies_controller.rb: -------------------------------------------------------------------------------- 1 | class PuppiesController < ApplicationController 2 | def index 3 | @puppies = Puppy.ordered 4 | 5 | @cached_message = Rails.cache.fetch 'home-cached-message' do 6 | "This text is cached #{rand(1000...9999999999)}" 7 | end 8 | end 9 | 10 | def like 11 | puppy = Puppy.find(params[:id]) 12 | IncreaseLikeCounterJob.perform_later(resource_class: puppy.class.name, resource_id: puppy.id) 13 | flash[:notice] = "Your like was accepted" 14 | redirect_to root_path 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /puppies/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /puppies/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /puppies/app/jobs/increase_like_counter_job.rb: -------------------------------------------------------------------------------- 1 | class IncreaseLikeCounterJob < ApplicationJob 2 | queue_as :default 3 | 4 | def perform(resource_class:, resource_id:) 5 | resource_class 6 | .constantize 7 | .find(resource_id) 8 | .increment(:like_counter, 1) 9 | .save 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /puppies/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /puppies/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/app/models/concerns/.keep -------------------------------------------------------------------------------- /puppies/app/models/puppy.rb: -------------------------------------------------------------------------------- 1 | class Puppy < ApplicationRecord 2 | validates_presence_of :name, :url 3 | scope :ordered, -> { order :id } 4 | end 5 | -------------------------------------------------------------------------------- /puppies/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Puppies 5 | <%= csrf_meta_tags %> 6 | 7 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 8 | <%= stylesheet_link_tag 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', media: 'all', 'data-turbolinks-track': 'reload' %> 9 | 10 | 11 | 12 | <%= yield %> 13 | 14 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /puppies/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /puppies/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /puppies/app/views/puppies/index.html.erb: -------------------------------------------------------------------------------- 1 |

Puppies !!!

2 | 3 | <% @puppies.each do |puppy| %> 4 |
5 |

<%= puppy.name %>

6 | <%= image_tag puppy.url, alt: puppy.name %> 7 | 8 |
9 | Likes: <%= puppy.like_counter.to_i %> 10 |
11 | <%= link_to like_puppy_path(puppy), method: :post do %> 12 | 13 | Like 14 | <% end %> 15 |
16 | <% end %> 17 | 18 |

Rails cache config example

19 | 20 |

<%= @cached_message %>

21 | -------------------------------------------------------------------------------- /puppies/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /puppies/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /puppies/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /puppies/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'bin/rails db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'bin/rails log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'bin/rails restart' 34 | end 35 | -------------------------------------------------------------------------------- /puppies/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | if spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 13 | gem 'spring', spring.version 14 | require 'spring/binstub' 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /puppies/bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /puppies/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /puppies/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | require "action_controller/railtie" 9 | # require "action_mailer/railtie" 10 | require "action_view/railtie" 11 | require "action_cable/engine" 12 | require "sprockets/railtie" 13 | # require "rails/test_unit/railtie" 14 | 15 | # Require the gems listed in Gemfile, including any gems 16 | # you've limited to :test, :development, or :production. 17 | Bundler.require(*Rails.groups) 18 | 19 | module Puppies 20 | class Application < Rails::Application 21 | # Settings in config/environments/* take precedence over those specified here. 22 | # Application configuration should go into files in config/initializers 23 | # -- all .rb files in that directory are automatically loaded. 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /puppies/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /puppies/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: redis://localhost:6379/1 10 | -------------------------------------------------------------------------------- /puppies/config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: postgresql 3 | encoding: unicode 4 | timeout: 5000 5 | pool: <%= (ENV['MAX_THREADS'] || 5).to_i * 2 %> 6 | host: <%= ENV['REL_DATABASE_HOST'] %> 7 | port: <%= ENV['REL_DATABASE_PORT'] %> 8 | username: <%= ENV['REL_DATABASE_USERNAME'] %> 9 | password: <%= ENV['REL_DATABASE_PASSWORD'] %> 10 | 11 | production: 12 | <<: *default 13 | database: <%= ENV['REL_DATABASE_DATABASE'] %> 14 | 15 | development: 16 | <<: *default 17 | database: <%= ENV['REL_DATABASE_DATABASE'] %> 18 | -------------------------------------------------------------------------------- /puppies/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /puppies/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | 19 | config.cache_store = :memory_store 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => 'public, max-age=172800' 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Print deprecation notices to the Rails logger. 30 | config.active_support.deprecation = :log 31 | 32 | # Raise an error on page load if there are pending migrations. 33 | config.active_record.migration_error = :page_load 34 | 35 | # Debug mode disables concatenation and preprocessing of assets. 36 | # This option may cause significant delays in view rendering with a large 37 | # number of complex assets. 38 | config.assets.debug = true 39 | 40 | # Suppress logger output for asset requests. 41 | config.assets.quiet = true 42 | 43 | # Raises error for missing translations 44 | # config.action_view.raise_on_missing_translations = true 45 | 46 | # Use an evented file watcher to asynchronously detect changes in source code, 47 | # routes, locales, etc. This feature depends on the listen gem. 48 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 49 | end 50 | -------------------------------------------------------------------------------- /puppies/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Disable serving static files from the `/public` folder by default since 18 | # Apache or NGINX already handles this. 19 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 20 | 21 | # Compress JavaScripts and CSS. 22 | config.assets.js_compressor = :uglifier 23 | # config.assets.css_compressor = :sass 24 | 25 | # Do not fallback to assets pipeline if a precompiled asset is missed. 26 | config.assets.compile = false 27 | 28 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 29 | 30 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 31 | # config.action_controller.asset_host = 'http://assets.example.com' 32 | 33 | # Specifies the header that your server uses for sending files. 34 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 35 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 36 | 37 | # Mount Action Cable outside main process or domain 38 | # config.action_cable.mount_path = nil 39 | # config.action_cable.url = 'wss://example.com/cable' 40 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Use the lowest log level to ensure availability of diagnostic information 46 | # when problems arise. 47 | config.log_level = :debug 48 | 49 | # Prepend all log lines with the following tags. 50 | config.log_tags = [ :request_id ] 51 | 52 | # Use a different cache store in production. 53 | # config.cache_store = :mem_cache_store 54 | 55 | # Use a real queuing backend for Active Job (and separate queues per environment) 56 | # config.active_job.queue_adapter = :resque 57 | # config.active_job.queue_name_prefix = "puppies_#{Rails.env}" 58 | 59 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 60 | # the I18n.default_locale when a translation cannot be found). 61 | config.i18n.fallbacks = true 62 | 63 | # Send deprecation notices to registered listeners. 64 | config.active_support.deprecation = :notify 65 | 66 | # Use default logging formatter so that PID and timestamp are not suppressed. 67 | config.log_formatter = ::Logger::Formatter.new 68 | 69 | # Use a different logger for distributed setups. 70 | # require 'syslog/logger' 71 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 72 | 73 | if ENV["RAILS_LOG_TO_STDOUT"].present? 74 | logger = ActiveSupport::Logger.new(STDOUT) 75 | logger.formatter = config.log_formatter 76 | config.logger = ActiveSupport::TaggedLogging.new(logger) 77 | end 78 | 79 | # Do not dump schema after migrations. 80 | config.active_record.dump_schema_after_migration = false 81 | end 82 | -------------------------------------------------------------------------------- /puppies/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => 'public, max-age=3600' 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | 31 | # Print deprecation notices to the stderr. 32 | config.active_support.deprecation = :stderr 33 | 34 | # Raises error for missing translations 35 | # config.action_view.raise_on_missing_translations = true 36 | end 37 | -------------------------------------------------------------------------------- /puppies/config/initializers/active_job.rb: -------------------------------------------------------------------------------- 1 | if Rails.env.test? 2 | ActiveJob::Base.queue_adapter = :inline 3 | else 4 | ActiveJob::Base.queue_adapter = :sidekiq 5 | end 6 | 7 | ActiveJob::Base.logger = Rails.logger 8 | -------------------------------------------------------------------------------- /puppies/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /puppies/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /puppies/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /puppies/config/initializers/cache_store.rb: -------------------------------------------------------------------------------- 1 | Rails 2 | .application 3 | .config 4 | .cache_store = :redis_store, { 5 | host: ENV['REDIS_HOST'], 6 | port: ENV['REDIS_PORT'], 7 | db: ENV['REDIS_DB_ID'], 8 | namespace: "cache", 9 | expires_in: 90.minutes, 10 | } 11 | -------------------------------------------------------------------------------- /puppies/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /puppies/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /puppies/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /puppies/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /puppies/config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Read the Rails 5.0 release notes for more info on each option. 6 | 7 | # Enable per-form CSRF tokens. Previous versions had false. 8 | Rails.application.config.action_controller.per_form_csrf_tokens = true 9 | 10 | # Enable origin-checking CSRF mitigation. Previous versions had false. 11 | Rails.application.config.action_controller.forgery_protection_origin_check = true 12 | 13 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 14 | # Previous versions had false. 15 | ActiveSupport.to_time_preserves_timezone = true 16 | 17 | # Require `belongs_to` associations by default. Previous versions had false. 18 | Rails.application.config.active_record.belongs_to_required_by_default = true 19 | 20 | # Do not halt callback chains when a callback returns false. Previous versions had true. 21 | ActiveSupport.halt_callback_chains_on_return_false = false 22 | 23 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false. 24 | Rails.application.config.ssl_options = { hsts: { subdomains: true } } 25 | -------------------------------------------------------------------------------- /puppies/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | Rails.application.config.session_store :redis_store, 2 | key: '_puppies_session', 3 | expires_in: 90.minutes, 4 | servers: { 5 | host: ENV['REDIS_HOST'], 6 | port: ENV['REDIS_PORT'], 7 | db: ENV['REDIS_DB_ID'], 8 | namespace: 'myapp:session:', 9 | } 10 | -------------------------------------------------------------------------------- /puppies/config/initializers/sidekiq.rb: -------------------------------------------------------------------------------- 1 | # there is also config/sidekiq.yml including some other options 2 | 3 | Sidekiq.logger = Rails.logger 4 | 5 | Sidekiq.configure_server do |config| 6 | config.redis = { 7 | host: ENV['REDIS_HOST'], 8 | port: ENV['REDIS_PORT'], 9 | db: ENV['REDIS_DB_ID'] 10 | } 11 | end 12 | 13 | Sidekiq.configure_client do |config| 14 | config.redis = { 15 | host: ENV['REDIS_HOST'], 16 | port: ENV['REDIS_PORT'], 17 | db: ENV['REDIS_DB_ID'] 18 | } 19 | end 20 | -------------------------------------------------------------------------------- /puppies/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /puppies/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /puppies/config/puma.rb: -------------------------------------------------------------------------------- 1 | threads_count = ENV.fetch("MAX_THREADS") { 5 }.to_i 2 | threads threads_count, threads_count 3 | 4 | bind "unix:///var/run/puppies-puma-app.sock?umask=0000" 5 | 6 | stdout_redirect "/var/log/puppies-puma.stdout.log", "/var/log/puppies-puma.stderr.log", true 7 | 8 | environment ENV.fetch("RAILS_ENV") { "development" } 9 | 10 | workers ENV.fetch("WEB_CONCURRENCY") { 2 } 11 | 12 | preload_app! 13 | 14 | on_worker_boot do 15 | ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 16 | end 17 | -------------------------------------------------------------------------------- /puppies/config/routes.rb: -------------------------------------------------------------------------------- 1 | require "sidekiq/web" 2 | 3 | Rails.application.routes.draw do 4 | mount Sidekiq::Web => '/sidekiq' 5 | 6 | resources :puppies, only: [] do 7 | member do 8 | post :like 9 | end 10 | end 11 | 12 | root 'puppies#index' 13 | end 14 | -------------------------------------------------------------------------------- /puppies/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 15 | 16 | test: 17 | secret_key_base: d41c911c2b5d84f50e02e7ea72bc4a51a234bb828fc4ecd56d0232c843030690759f18fb2bb869617c308f1d4fd5ad22e6e357c086e311bf18c232ab53dbdf21 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /puppies/config/sidekiq.yml: -------------------------------------------------------------------------------- 1 | --- 2 | :verbose: true 3 | :concurrency: <%= (ENV['MAX_THREADS'] || 10).to_i %> 4 | :queues: 5 | - ["default", 10] 6 | 7 | :pidfile: /var/run/<%= ENV['RAILS_ENV'] %>_sidekiq.pid 8 | -------------------------------------------------------------------------------- /puppies/config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /puppies/db/migrate/20161101224400_create_puppies.rb: -------------------------------------------------------------------------------- 1 | class CreatePuppies < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :puppies do |t| 4 | t.string :url 5 | t.string :name 6 | t.integer :like_counter 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /puppies/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20161101224400) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "puppies", force: :cascade do |t| 19 | t.string "url" 20 | t.string "name" 21 | t.integer "like_counter" 22 | t.datetime "created_at", null: false 23 | t.datetime "updated_at", null: false 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /puppies/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | 9 | # image urls were googled under "Labeled for noncommercial reuse" filter 10 | Puppy.create(name: "Cute Golden Retriever Puppies", url: "https://c1.staticflickr.com/5/4046/4215831807_5c59dd85af.jpg") 11 | Puppy.create(name: "Adorable Toy Poodle", url: "https://c2.staticflickr.com/4/3189/2913168941_1272db8f53_z.jpg?zz=1") 12 | Puppy.create(name: "Fluffy Alaskan Malamute ", url: "https://c1.staticflickr.com/1/22/146828640_463b12e9af_z.jpg?zz=1") 13 | 14 | puts "done" 15 | -------------------------------------------------------------------------------- /puppies/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/lib/assets/.keep -------------------------------------------------------------------------------- /puppies/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/lib/tasks/.keep -------------------------------------------------------------------------------- /puppies/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/log/.keep -------------------------------------------------------------------------------- /puppies/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /puppies/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /puppies/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /puppies/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /puppies/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/public/apple-touch-icon.png -------------------------------------------------------------------------------- /puppies/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/public/favicon.ico -------------------------------------------------------------------------------- /puppies/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /puppies/script/start_server.sh: -------------------------------------------------------------------------------- 1 | # sleep 999999 # if you need to debug the container before starting server uncomment this line 2 | 3 | if [ "$CONTAINER_ROLE" == "bg_worker" ] 4 | then 5 | bundle exec sidekiq 6 | elif [ "$CONTAINER_ROLE" == "app_server" ] 7 | then 8 | cp -R /app/public /var/www/ 9 | bundle exec rake db:migrate && bundle exec puma -C /app/config/puma.rb 10 | else 11 | echo "Error: unknown CONTAINER_ROLE" 12 | exit 125 13 | fi 14 | -------------------------------------------------------------------------------- /puppies/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/tmp/.keep -------------------------------------------------------------------------------- /puppies/vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /puppies/vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/equivalent/docker_rails_aws_elasticbeanstalk_demmo_app/470a28fe892230a2f66e8a88c3922e5a08cf352f/puppies/vendor/assets/stylesheets/.keep --------------------------------------------------------------------------------