Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker dev environment #103

Merged
merged 9 commits into from Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
@@ -0,0 +1,5 @@
.git*
log/*
tmp/*
Dockerfile
README.md
19 changes: 19 additions & 0 deletions Dockerfile
@@ -0,0 +1,19 @@
FROM ruby:2.3.3

RUN apt-get update -qq && apt-get install -y \
build-essential \
libpq-dev \
nodejs

ENV app /app
ENV BUNDLE_PATH /gems

RUN mkdir -p $app
WORKDIR $app

# Copy the main application.
ADD . $app

EXPOSE 3000

CMD rails s -b 0.0.0.0
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -32,6 +32,25 @@
9. Run server
`bundle exec rails server`

## Docker development setup

Run / Stop (daemon mode)
```bash
$ docker-compose up -d
$ docker-compose stop
```

Forwarded ports and access:

Web: http://localhost:3000 (host machine)
Database: postgres://postgres@localhost:6543 (host machine)

Action | Command
------------ | -------------
Bundler | `docker-compose exec app bundle install`
Setup DB | `docker-compose exec app bundle exec rails db:create db:migrate`
Console | `docker-compose exec app bundle exec rails c`

## Guidelines

Use the following guides for getting things done, programming well, and
Expand Down
5 changes: 5 additions & 0 deletions bin/docker_up
@@ -0,0 +1,5 @@
#!/bin/bash

bundle check || bundle install
rm tmp/pids/*
bundle exec rails s -b 0.0.0.0
1 change: 1 addition & 0 deletions circle.yml
Expand Up @@ -6,4 +6,5 @@ test:
- COVERAGE=true bin/rake
machine:
environment:
DATABASE_URL: postgres://root@localhost:5432/it61
SECRET_KEY_BASE: abcdef123456
2 changes: 1 addition & 1 deletion config/cable.yml
Expand Up @@ -9,4 +9,4 @@ staging:

production:
adapter: redis
url: redis://localhost:6379/1
url: <%= ENV.fetch("REDIS_URL", "redis://localhost:6379/1") %>
7 changes: 3 additions & 4 deletions config/database.yml
@@ -1,6 +1,5 @@
development: &default
adapter: postgresql
database: it61_development
url: <%= ENV.fetch("DATABASE_URL") %>_development
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот эта строчка сломала локальное окружение (╯°□°)╯︵ ┻━┻

encoding: utf8
min_messages: warning
pool: <%= Integer(ENV.fetch("DB_POOL", 5)) %>
Expand All @@ -9,11 +8,11 @@ development: &default

test:
<<: *default
database: it61_test
database: <%= ENV.fetch("DATABASE_URL") %>_test

production:
encoding: utf8
min_messages: warning
pool: <%= [Integer(ENV.fetch("MAX_THREADS", 5)), Integer(ENV.fetch("DB_POOL", 5))].max %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может достаточно одной переменной?

Copy link
Member Author

@tamtamchik tamtamchik Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут ничего не менял, подумал раз так есть, может так и надо...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitallium, это нужно?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно. прод работает в контейнерах, и это нужно для горизонтального масштабирования.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это понятно, но почему мы не можем использовать всегда какую-то одну из этих env переменных?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А по поводу потоков, еще сам schneems писал, что:

You need your pool to at least be as large as your puma thread count.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Флудеры! 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, давайте (если есть желание) это обсудим в #rndrug :-) а то никогда не смержим

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тут я такой заметил, что в puma.rb переменная называется RAILS_MAX_THREADS, а не MAX_THREADS :O

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну т.е. это MAX_THREADS – это что-то неведомое. Я бы это выкосил

timeout: 5000
url: <%= ENV.fetch("DATABASE_URL", "") %>
url: <%= ENV.fetch("DATABASE_URL", "") %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для чего указывать пустую строку по умолчанию, путь лучше райзится исключение, если с конфигурацией что-то не так.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

См. комент выше, я просто лишний пробел убрал :)

33 changes: 33 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,33 @@
version: '2'
services:
# Main application container
app:
build: .
command: bin/docker_up
volumes:
- .:/app
volumes_from:
- gems
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://postgres@db:5432/it61
- REDIS_URL=redis://redis:6379/1
depends_on:
- db
- redis

# Mounted folder for Gemfile gems container
gems:
image: busybox
volumes:
- /gems

# Container with database
db:
image: postgres
ports:
- "6543:5432"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем пробрасывать порт из контейнера бд на хост?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мало ли надо будет в базу залезть, посмотреть что там...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я тоже использую такую настройку, чтобы смотреть, что с базой творится.


redis:
image: redis