From 03157b406883ff178b97646ee5698b7c6af05556 Mon Sep 17 00:00:00 2001 From: "yu.nakamura" Date: Fri, 29 Mar 2019 17:12:05 +0900 Subject: [PATCH 01/11] empty commit From c8b1328377765028e798ba3bca1f109dce64cb2a Mon Sep 17 00:00:00 2001 From: chanyou0311 Date: Fri, 29 Mar 2019 17:12:42 +0900 Subject: [PATCH 02/11] empty commit From 87177395acfde57f6cd83b7461bde0ecda329709 Mon Sep 17 00:00:00 2001 From: chanyou0311 Date: Sun, 14 Apr 2019 15:35:01 +0900 Subject: [PATCH 03/11] [ad --- config/database.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/database.yml b/config/database.yml index 5be855ea8..64a9442a8 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 From 5df076bdc6c58929eed3a87889d474d038966fb2 Mon Sep 17 00:00:00 2001 From: chanyou0311 Date: Sun, 14 Apr 2019 15:37:10 +0900 Subject: [PATCH 04/11] [add] rails and mysql container --- docker-compose.yml | 52 ++++++++++++++++++++++++++++++ docker/backend/Dockerfile.dev | 37 +++++++++++++++++++++ docker/mysql/Dockerfile.local | 19 +++++++++++ docker/mysql/init.d/initialize.sql | 0 docker/mysql/log.cnf | 8 +++++ docker/mysql/my.cnf | 7 ++++ 6 files changed, 123 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/backend/Dockerfile.dev create mode 100644 docker/mysql/Dockerfile.local create mode 100644 docker/mysql/init.d/initialize.sql create mode 100644 docker/mysql/log.cnf create mode 100644 docker/mysql/my.cnf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..2b40f9f52 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +version: '2' + +services: + db: + image: mysql:5.7.25 + environment: + MYSQL_DATABASE: cho_kure_web_development + MYSQL_USER: root + MYSQL_ROOT_PASSWORD: root + MYSQL_PASSWORD: root + MYSQL_PORT: 3306 + expose: + - "3306" + backend: + build: + context: . + dockerfile: ./docker/backend/Dockerfile.dev + command: rails s -p 3000 -b '0.0.0.0' + volumes: + - ./:/code + ports: + - "3000:3000" + links: + - "db" + environment: + DATABASE_PASSWORD: root + DATABASE_USER: root + DATABASE_HOST: db + # DATABASE_PASSWORD: homepage + # DATABASE_USER: homepage + # DATABASE_HOST: db + DATABASE_SOCKET: /tmp/mysql.sock + EC2_PRODUCTION_HOST: 52.199.95.54 + EC2_PRODUCTION_PROTOCOL: http + # frontend: + # build: + # context: . + # dockerfile: ./docker/frontend/Dockerfile.local + # command: echo "frontend command" + # volumes: + # - ./:/code + # ports: + # - "3000:3000" + # links: + # - "db" + # environment: + # DATABASE_PASSWORD: homepage + # DATABASE_USER: homepage + # DATABASE_HOST: db + # DATABASE_SOCKET: /tmp/mysql.sock + # EC2_PRODUCTION_HOST: 52.199.95.54 + # EC2_PRODUCTION_PROTOCOL: http diff --git a/docker/backend/Dockerfile.dev b/docker/backend/Dockerfile.dev new file mode 100644 index 000000000..677726a0c --- /dev/null +++ b/docker/backend/Dockerfile.dev @@ -0,0 +1,37 @@ +FROM ruby:2.4.5 +ENV LANG C.UTF-8 + +RUN mkdir /code/ + +WORKDIR /code + +ENV RUNTIME_PACKAGES="bash git perl libxml2-dev libxslt-dev libstdc++ tzdata mariadb-client"\ + DEV_PACKAGES="mysql-client" + +RUN apt-get update -qq +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils +RUN apt-get install -y libpq-dev graphviz imagemagick +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs build-essential +RUN npm install -g yarn + +RUN gem install bundler +RUN gem update + +ADD Gemfile* /code/ + +RUN bundle install + +ADD ./frontend/package.json /code/ +ADD ./frontend/yarn.lock /code/ +RUN yarn install + +RUN bundle exec rails assets:precompile + +# RUN apt-get update -qq &&\ +# apt-get install -y $RUNTIME_PACKAGES &&\ +# apt-get install -y $DEV_PACKAGES &&\ +# gem install bundler --no-document &&\ +# bundle config build.nokogiri --use-system-libraries &&\ +# bundle install + +CMD bundle exec rails s -p 3000 -b '0.0.0.0' diff --git a/docker/mysql/Dockerfile.local b/docker/mysql/Dockerfile.local new file mode 100644 index 000000000..f12969054 --- /dev/null +++ b/docker/mysql/Dockerfile.local @@ -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 diff --git a/docker/mysql/init.d/initialize.sql b/docker/mysql/init.d/initialize.sql new file mode 100644 index 000000000..e69de29bb diff --git a/docker/mysql/log.cnf b/docker/mysql/log.cnf new file mode 100644 index 000000000..2bc80cd6d --- /dev/null +++ b/docker/mysql/log.cnf @@ -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 diff --git a/docker/mysql/my.cnf b/docker/mysql/my.cnf new file mode 100644 index 000000000..bc4fb0b13 --- /dev/null +++ b/docker/mysql/my.cnf @@ -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 From 0012501f8534fd8093ba449b3b329f8c3e426082 Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Fri, 10 May 2019 22:04:19 +0900 Subject: [PATCH 05/11] auto remove server.pid & depends_on: db --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2b40f9f52..c0c056bbe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,6 @@ services: image: mysql:5.7.25 environment: MYSQL_DATABASE: cho_kure_web_development - MYSQL_USER: root MYSQL_ROOT_PASSWORD: root MYSQL_PASSWORD: root MYSQL_PORT: 3306 @@ -15,13 +14,15 @@ services: build: context: . dockerfile: ./docker/backend/Dockerfile.dev - command: rails s -p 3000 -b '0.0.0.0' + 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" + depends_on: + - "db" environment: DATABASE_PASSWORD: root DATABASE_USER: root From 285335d3dda4ed6f8450e264dc0479e83d19512b Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Fri, 10 May 2019 22:05:18 +0900 Subject: [PATCH 06/11] comment out frontend & ADD .env --- docker/backend/Dockerfile.dev | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docker/backend/Dockerfile.dev b/docker/backend/Dockerfile.dev index 677726a0c..cf67a99ea 100644 --- a/docker/backend/Dockerfile.dev +++ b/docker/backend/Dockerfile.dev @@ -11,21 +11,20 @@ ENV RUNTIME_PACKAGES="bash git perl libxml2-dev libxslt-dev libstdc++ tzdata mar RUN apt-get update -qq RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils RUN apt-get install -y libpq-dev graphviz imagemagick -RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs build-essential -RUN npm install -g yarn +# RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs build-essential +# RUN npm install -g yarn RUN gem install bundler RUN gem update ADD Gemfile* /code/ +ADD .env /code/ RUN bundle install -ADD ./frontend/package.json /code/ -ADD ./frontend/yarn.lock /code/ -RUN yarn install - -RUN bundle exec rails assets:precompile +# ADD ./frontend/package.json /code/ +# ADD ./frontend/yarn.lock /code/ +# RUN yarn install # RUN apt-get update -qq &&\ # apt-get install -y $RUNTIME_PACKAGES &&\ @@ -34,4 +33,4 @@ RUN bundle exec rails assets:precompile # bundle config build.nokogiri --use-system-libraries &&\ # bundle install -CMD bundle exec rails s -p 3000 -b '0.0.0.0' +# CMD bundle exec rails s -p 3000 -b '0.0.0.0' From e204df9005833a5f52dd4c8b2acf03a03fedd2ba Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Fri, 10 May 2019 22:05:32 +0900 Subject: [PATCH 07/11] write how to use with docker --- README.md | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bc9a8f9bf..d8658b295 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,54 @@ [![Test Coverage](https://api.codeclimate.com/v1/badges/cef3c1298621fa26dd1c/test_coverage)](https://codeclimate.com/github/kure-kosen/cho_kure_web/test_coverage) ## Ruby version -``` + +```bash % ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16] ``` ## Setup + 以下を実行すればセットアップは完了するはず。 mysqlに接続できなければ `.env` を編集して自分の環境に合わせてください。 + +```bash +% git clone git@github.com:kure-kosen/cho_kure_web.git +% cd cho_kure_web +% bin/setup ``` -git clone git@github.com:kure-kosen/cho_kure_web.git -cd cho_kure_web -bin/setup + +## Setup with Docker + +### Common + +```bash +% git clone git@github.com: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を出してください。 From b8ed6d9e733591cefd954cbbf46f6717beb7973f Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Fri, 10 May 2019 23:09:39 +0900 Subject: [PATCH 08/11] remove depends_on --- docker-compose.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c0c056bbe..3b872e16c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,15 +21,10 @@ services: - "3000:3000" links: - "db" - depends_on: - - "db" environment: DATABASE_PASSWORD: root DATABASE_USER: root DATABASE_HOST: db - # DATABASE_PASSWORD: homepage - # DATABASE_USER: homepage - # DATABASE_HOST: db DATABASE_SOCKET: /tmp/mysql.sock EC2_PRODUCTION_HOST: 52.199.95.54 EC2_PRODUCTION_PROTOCOL: http From 9c04e416610766c6c2752e55ca64fa871f4e35e2 Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Sat, 11 May 2019 01:24:13 +0900 Subject: [PATCH 09/11] separate fixed env and variable env --- .env.sample | 5 ----- docker-compose.yml | 21 +-------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/.env.sample b/.env.sample index 8ef224621..3da01d6ff 100644 --- a/.env.sample +++ b/.env.sample @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 3b872e16c..e20a5dd56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,28 +21,9 @@ services: - "3000:3000" links: - "db" + env_file: .env environment: DATABASE_PASSWORD: root DATABASE_USER: root DATABASE_HOST: db DATABASE_SOCKET: /tmp/mysql.sock - EC2_PRODUCTION_HOST: 52.199.95.54 - EC2_PRODUCTION_PROTOCOL: http - # frontend: - # build: - # context: . - # dockerfile: ./docker/frontend/Dockerfile.local - # command: echo "frontend command" - # volumes: - # - ./:/code - # ports: - # - "3000:3000" - # links: - # - "db" - # environment: - # DATABASE_PASSWORD: homepage - # DATABASE_USER: homepage - # DATABASE_HOST: db - # DATABASE_SOCKET: /tmp/mysql.sock - # EC2_PRODUCTION_HOST: 52.199.95.54 - # EC2_PRODUCTION_PROTOCOL: http From 1e9dfd33aa2c5523fdf9875ca940cc63391ec64f Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Sat, 11 May 2019 01:48:08 +0900 Subject: [PATCH 10/11] remove comment out --- docker/backend/Dockerfile.dev | 39 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/docker/backend/Dockerfile.dev b/docker/backend/Dockerfile.dev index cf67a99ea..4e1228b63 100644 --- a/docker/backend/Dockerfile.dev +++ b/docker/backend/Dockerfile.dev @@ -1,36 +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 -ENV RUNTIME_PACKAGES="bash git perl libxml2-dev libxslt-dev libstdc++ tzdata mariadb-client"\ - DEV_PACKAGES="mysql-client" - -RUN apt-get update -qq -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils -RUN apt-get install -y libpq-dev graphviz imagemagick -# RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs build-essential -# RUN npm install -g yarn - -RUN gem install bundler -RUN gem update +# 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 - -# ADD ./frontend/package.json /code/ -# ADD ./frontend/yarn.lock /code/ -# RUN yarn install - -# RUN apt-get update -qq &&\ -# apt-get install -y $RUNTIME_PACKAGES &&\ -# apt-get install -y $DEV_PACKAGES &&\ -# gem install bundler --no-document &&\ -# bundle config build.nokogiri --use-system-libraries &&\ -# bundle install - -# CMD bundle exec rails s -p 3000 -b '0.0.0.0' +RUN bundle install -j4 From 3fc78bcff224fe827cae181035bf060d7a28348f Mon Sep 17 00:00:00 2001 From: kobakakzu0429 Date: Sat, 1 Jun 2019 10:54:09 +0900 Subject: [PATCH 11/11] fix readme --- README.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d8658b295..31e3b4ae2 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,20 @@ ## Ruby version ```bash -% ruby -v +$ ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16] ``` -## Setup +## Setup without Docker 以下を実行すればセットアップは完了するはず。 -mysqlに接続できなければ `.env` を編集して自分の環境に合わせてください。 +mysql に接続できなければ `.env` を編集して自分の環境に合わせてください。 ```bash -% git clone git@github.com:kure-kosen/cho_kure_web.git -% cd cho_kure_web -% bin/setup +... installed ruby, mysql +$ git clone git@github.com:kure-kosen/cho_kure_web.git +$ cd cho_kure_web +$ bin/setup ``` ## Setup with Docker @@ -27,32 +28,32 @@ mysqlに接続できなければ `.env` を編集して自分の環境に合わ ### Common ```bash -% git clone git@github.com:kure-kosen/cho_kure_web.git -% cd cho_kure_web +$ git clone git@github.com: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 +$ 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 +$ cd ./frontend +$ yarn install # Commands -% yarn start # Start webpack-dev-server -% yarn build # Build to dist/ -% yarn lint # Check type and syntax, auto fix +$ 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 を出してください。