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

dockerize of development #348

Merged
merged 12 commits into from
Jun 2, 2019
Merged
5 changes: 0 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
DATABASE_USER=root
DATABASE_PASSWORD=
DATABASE_HOST=localhost
DATABASE_SOCKET=/tmp/mysql.sock

EC2_PRODUCTION_HOST=52.199.95.54
EC2_PRODUCTION_PROTOCOL=http

Expand Down
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,55 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/test_coverage)](https://codeclimate.com/github/kure-kosen/cho_kure_web/test_coverage)

## Ruby version
```
% ruby -v

```bash
$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
```

## Setup
## Setup without Docker

以下を実行すればセットアップは完了するはず。
mysqlに接続できなければ `.env` を編集して自分の環境に合わせてください。
mysql に接続できなければ `.env` を編集して自分の環境に合わせてください。

```bash
... installed ruby, mysql
$ git clone [email protected]:kure-kosen/cho_kure_web.git
$ cd cho_kure_web
$ bin/setup
```
git clone [email protected]:kure-kosen/cho_kure_web.git
cd cho_kure_web
bin/setup

## Setup with Docker

### Common

```bash
$ git clone [email protected]:kure-kosen/cho_kure_web.git
$ cd cho_kure_web
```

### Backend

```bash
... installed docker-compose
$ docker-compose build
$ docker-compose up
$ docker-compose run backend bin/rails db:create db:schema:load db:seed_fu
```

### Frontend

```bash
$ cd ./frontend
$ yarn install

# Commands
$ yarn start # Start webpack-dev-server
$ yarn build # Build to dist/
$ yarn lint # Check type and syntax, auto fix
```

## その他
* 開発中にアプリケーションが送信したメールは `/letter_opener` で確認できます。
* `bundle exec rubocop` でコードの静的チェックが走ります。指摘箇所を修正してPRを出してください。

- 開発中にアプリケーションが送信したメールは `/letter_opener` で確認できます。
- `bundle exec rubocop` でコードの静的チェックが走ります。指摘箇所を修正して PR を出してください。
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ default: &default
username: <%= ENV.fetch("DATABASE_USER") { "root" } %>
password: <%= ENV.fetch("DATABASE_PASSWORD") { "" } %>
socket: <%= ENV.fetch("DATABASE_SOCKET") { "/tmp/mysql.sock" } %>
host: <%= ENV.fetch("DATABASE_HOST") { "db" } %>

development:
<<: *default
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '2'

services:
db:
image: mysql:5.7.25
environment:
MYSQL_DATABASE: cho_kure_web_development
MYSQL_ROOT_PASSWORD: root
MYSQL_PASSWORD: root
MYSQL_PORT: 3306
expose:
- "3306"
backend:
build:
context: .
dockerfile: ./docker/backend/Dockerfile.dev
command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- ./:/code
ports:
- "3000:3000"
links:
- "db"
env_file: .env
environment:
DATABASE_PASSWORD: root
DATABASE_USER: root
DATABASE_HOST: db
DATABASE_SOCKET: /tmp/mysql.sock
25 changes: 25 additions & 0 deletions docker/backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ruby:2.4.5
LABEL maintainer="Kobatake Kazuhiro<@kobakazu0429>"

ENV LANG C.UTF-8

# noninteractive: インストール時にインタラクティブな入力待ちが発生しなくなる
ENV DEBIAN_FRONTEND noninteractive

RUN mkdir /code/

WORKDIR /code

# apt-get [-qq]: エラー以外は表示しない
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends apt-utils && \
apt-get install -y libpq-dev graphviz imagemagick && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get install -y nodejs build-essential && \
gem install bundler --no-document --conservative && \
gem update

ADD Gemfile* /code/
ADD .env /code/

RUN bundle install -j4
19 changes: 19 additions & 0 deletions docker/mysql/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mysql:5.7

ADD log.cnf /etc/mysql/conf.d/log.cnf
ADD my.cnf /etc/mysql/conf.d/my.cnf

RUN chmod 644 /etc/mysql/conf.d/log.cnf

RUN apt-get update && apt-get install -y locales \
--no-install-recommends && rm -rf /var/lib/apt/lists/*

RUN dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8

# 初期データベースの作成
COPY init.d/ /docker-entrypoint-initdb.d/

ENV LC_ALL C.UTF-8
ENV TERM xterm
Empty file.
8 changes: 8 additions & 0 deletions docker/mysql/log.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[mysqld]
slow_query_log=1
long_query_time=1
log_queries_not_using_indexes=1
slow_query_log-file = /var/log/mysql/mysql-slow.sql

[mysqld_safe]
log-err=/var/log/mysql/mysql-error.log
7 changes: 7 additions & 0 deletions docker/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mysqld]
default-storage-engine=InnoDB
character-set-server=utf8mb4
sql_mode=""
default_authentication_plugin= mysql_native_password
[client]
default-character-set = utf8mb4