Skip to content

Instantly share code, notes, and snippets.

@ziahamza
Created August 29, 2017 11:29
Show Gist options
  • Save ziahamza/2192f8d36ced1345f23f56d4d9926805 to your computer and use it in GitHub Desktop.
Save ziahamza/2192f8d36ced1345f23f56d4d9926805 to your computer and use it in GitHub Desktop.
Rainforest Docker Scripts

Why

Docker allows us to setup a consistent dev environment that is easy to start, upgrade and reset when required. It also does not pollute your local machines with rubishness if you dont work actively work on the backend.

1. Install Docker & Clone Gist

Install docker through docker toolbox here

Then clone this gist, at the same directory level as Rainforest & Regenwald (https://github.com/rainforestapp/regenwald) So the directory looks like

> folder
  > Rainforest
  > regenwald
  > docker-scripts

2. Build Docker Containers

Run the following command to pre-build docker containers for Redis, Postgres & Rails

docker-compose build

3. Setup DB

Setup your docker db container

docker-compose run --rm --service-ports web /rainforest/script/reset_db.sh

4. Setup DNS

Add the following lines to your hosts file. On Mac/Linux the file is located at /etc/hosts and on windows you can find it at C:\Windows\System32\Drivers\etc\hosts

127.0.0.1	app.rainforest.dev
127.0.0.1	admin.rainforest.dev
127.0.0.1	portal.rainforest.dev
127.0.0.1	vendor.rainforest.dev

Note: You may have to edit the file as root/Administrator

5. Start/Stop/Reset Docker

To start rainforest in docker, run

docker-compose up

This will start docker containers, and attach the logs to your terminal. Close the app (Ctrl + c) to stop the containers gracefully.

To reset your local rainforest docker setup, run

docker-compose rm -f -v
docker volume rm rainforest_data-volume
rm -f tmp/pids/server.pid
docker-compose run --rm --service-ports web /rainforest/script/reset_db.sh
version: '3'
services:
db:
image: postgres:9.6.2
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: 3x4mpl3
POSTGRES_USER: postgres
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- data-volume:/var/lib/postgresql/data
redis:
image: redis
ports:
- "6379:6379"
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
links:
- db:db.local
- redis:redis.local
environment:
DATABASE_URL: postgres://postgres:[email protected]:5432/rainforest_development
REDIS_URL: redis://redis.local:6379
PGHOST: db.local
PGUSER: postgres
PGPASSWORD: 3x4mpl3
DB_POOL: 10
volumes:
- .:/rainforest
ports:
- "3000:3000"
depends_on:
- db
- redis
volumes:
data-volume:
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs cmake postgresql-client
RUN mkdir /rainforest
WORKDIR /rainforest
ADD ../Rainforest/Gemfile /rainforest/Gemfile
ADD ../Rainforest/Gemfile.lock /rainforest/Gemfile.lock
RUN bundle install
ADD ../Rainforest /rainforest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment