From 08b27df575b07bc4b8eb7392dc4013b5f716e4ee Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Mon, 29 Apr 2019 12:57:31 +0300 Subject: [PATCH 1/9] Dockerize application --- .env.development.sample | 17 +++++++++-------- .gitignore | 2 ++ Dockerfile.development | 9 +++++++++ Makefile | 12 ++++++++++++ README.md | 29 ++++++++++++----------------- docker-compose.development.yml | 20 +++++++++++++++----- 6 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 Dockerfile.development create mode 100644 Makefile diff --git a/.env.development.sample b/.env.development.sample index f4a47d6..465361e 100644 --- a/.env.development.sample +++ b/.env.development.sample @@ -1,11 +1,12 @@ # Define ENV variables for development environment -DATABASE_URL="postgresql://localhost/ruby_jobs_development" -SERVE_STATIC_ASSETS="true" -WEB_SESSIONS_SECRET="238d8ece1579f59647fe3d7c5ca2c78f02142a6392506a929d14c46424e52543" -MODERATION_SESSIONS_SECRET="f62e64af694897dd5a3b949891f2715ada568401017905098809aa80e8943dd0" -REDISTOGO_URL="redis://localhost:6379" +HANAMI_ENV=development +DATABASE_URL=postgres://safelylaunch@postgres/core +SERVE_STATIC_ASSETS=true +WEB_SESSIONS_SECRET=238d8ece1579f59647fe3d7c5ca2c78f02142a6392506a929d14c46424e52543 +MODERATION_SESSIONS_SECRET=f62e64af694897dd5a3b949891f2715ada568401017905098809aa80e8943dd0 +REDISTOGO_URL=redis://redis:6379 -MODERATION_LOGIN="login" -MODERATION_PASSWORD="password" +MODERATION_LOGIN=login +MODERATION_PASSWORD=password -ROLLBAR_KEY = 'test' +ROLLBAR_KEY=test diff --git a/.gitignore b/.gitignore index 85f8226..4280e88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /public/assets* /tmp /coverage + +.env.development diff --git a/Dockerfile.development b/Dockerfile.development new file mode 100644 index 0000000..d89bbca --- /dev/null +++ b/Dockerfile.development @@ -0,0 +1,9 @@ +FROM ruby:2.5.0-alpine + +RUN apk add --no-cache build-base postgresql postgresql-dev libpq git + +WORKDIR /app +COPY . /app +RUN bundle install -j $(nproc) --quiet + +ENTRYPOINT ["bundle", "exec"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..09c8383 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +.PHONY: help dockerize shell + +help: + @echo 'Available targets:' + @echo ' make dockerize' + @echo ' make shell' + +dockerize: + docker-compose -f docker-compose.development.yml up --build + +shell: + docker-compose -f docker-compose.development.yml exec web sh diff --git a/README.md b/README.md index f108bba..fcae53f 100644 --- a/README.md +++ b/README.md @@ -3,32 +3,27 @@ Welcome to your new Hanami project! -## Setup +## How to run app inside Docker -How to run tests: +Copy development env-file from sample file: -``` -% bundle exec rake +```bash +cp .env.development.sample .env.development ``` -How to run the development console: +Then simply run in your terminal: +```bash +make dockerize ``` -% bundle exec hanami console -``` - -How to run the development server: -``` -% bundle exec hanami server -``` +Open [http://localhost:2300](http://localhost:2300) in your browser. -How to prepare (create and migrate) DB for `development` and `test` environments: +## How to get container's shell -``` -% bundle exec hanami db prepare +Run in your terminal: -% HANAMI_ENV=test bundle exec hanami db prepare +```bash +make shell ``` -Explore Hanami [guides](http://hanamirb.org/guides/), [API docs](http://docs.hanamirb.org/1.3.0.beta1/), or jump in [chat](http://chat.hanamirb.org) for help. Enjoy! 🌸 diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 7af3f01..d28344a 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -1,18 +1,28 @@ version: '3' + services: + redis: + image: redis:latest + postgres: image: postgres:9.6.2-alpine environment: POSTGRES_USER: safelylaunch POSTGRES_DB: core + ports: + - 5432:5432 + web: - build: . + build: + context: . + dockerfile: Dockerfile.development + command: sh -c "hanami db migrate && hanami server --host=0.0.0.0" volumes: - .:/app ports: - - "2300:2300" + - 2300:2300 depends_on: - postgres - environment: - DATABASE_URL: postgres://safelylaunch@postgres/core - HANAMI_ENV: development + - redis + env_file: + - .env.development From 52b9783cea7ccd8f0b72b17a9eae2775246641f8 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Tue, 30 Apr 2019 11:35:02 +0300 Subject: [PATCH 2/9] Minimize Docker image size --- Dockerfile.development | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Dockerfile.development b/Dockerfile.development index d89bbca..64154e5 100644 --- a/Dockerfile.development +++ b/Dockerfile.development @@ -1,9 +1,19 @@ FROM ruby:2.5.0-alpine -RUN apk add --no-cache build-base postgresql postgresql-dev libpq git +RUN apk add --update --no-cache build-base postgresql-dev tzdata git \ + && gem install -N bundler \ + && bundle config --global silence_root_warning 1 \ + && echo -e 'gem: --no-document' >> /etc/gemrc \ + && rm -rf /var/cache/apk/* \ + && rm -rf /usr/local/bundle/cache/*.gem \ + && find /usr/local/bundle/gems/ -name "*.c" -delete \ + && find /usr/local/bundle/gems/ -name "*.o" -delete WORKDIR /app -COPY . /app + +COPY Gemfile Gemfile.lock ./ RUN bundle install -j $(nproc) --quiet +COPY . ./ + ENTRYPOINT ["bundle", "exec"] From ee68610e4a5fbe299ab450c6d0ca3a8cc1a9fe43 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 15:26:05 +0300 Subject: [PATCH 3/9] Ignore .env.test --- .env.test | 5 ----- .gitignore | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 .env.test diff --git a/.env.test b/.env.test deleted file mode 100644 index 31bbd39..0000000 --- a/.env.test +++ /dev/null @@ -1,5 +0,0 @@ -# Define ENV variables for test environment -DATABASE_URL="postgresql://localhost/ruby_jobs_test" -SERVE_STATIC_ASSETS="true" -WEB_SESSIONS_SECRET="ef09acb9b6d59ea2c7565bfbeb0fce5253445d6a8c784339d5cea71305ed8b85" -MODERATION_SESSIONS_SECRET="d0111ed3e5f320d69e38f88fc351197cb56e2d67bf4ba61c2f0a294fb3bfc534" diff --git a/.gitignore b/.gitignore index 4280e88..ea3973e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /coverage .env.development +.env.test From b27f9abb5edabb3130f17ae224c1eff76606da29 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 15:37:40 +0300 Subject: [PATCH 4/9] Add postgresql-client to run tests inside Docker --- Dockerfile.development | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.development b/Dockerfile.development index 64154e5..adfd289 100644 --- a/Dockerfile.development +++ b/Dockerfile.development @@ -1,6 +1,7 @@ FROM ruby:2.5.0-alpine -RUN apk add --update --no-cache build-base postgresql-dev tzdata git \ +# NOTE: postgresql-client required by `hanami db prepare` to create test database +RUN apk add --update --no-cache build-base postgresql-dev postgresql-client tzdata git \ && gem install -N bundler \ && bundle config --global silence_root_warning 1 \ && echo -e 'gem: --no-document' >> /etc/gemrc \ From 97dea3a12f5fddefa8cbd87aba4faee2503e3284 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 15:38:27 +0300 Subject: [PATCH 5/9] Update env files --- .env.development.sample | 11 +++++++++-- .env.test.sample | 14 ++++++++++++++ docker-compose.development.yml | 6 ++---- 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .env.test.sample diff --git a/.env.development.sample b/.env.development.sample index 465361e..8a0ef92 100644 --- a/.env.development.sample +++ b/.env.development.sample @@ -1,10 +1,17 @@ # Define ENV variables for development environment HANAMI_ENV=development -DATABASE_URL=postgres://safelylaunch@postgres/core + +# For local development: +DATABASE_URL=postgresql://localhost/rubyjobs_development +REDISTOGO_URL=redis://localhost:6379 + +# For Docker development uncomment these lines (and comment similar lines above): +# DATABASE_URL=postgres://rubyjobs@postgres/rubyjobs_development +# REDISTOGO_URL=redis://redis:6379 + SERVE_STATIC_ASSETS=true WEB_SESSIONS_SECRET=238d8ece1579f59647fe3d7c5ca2c78f02142a6392506a929d14c46424e52543 MODERATION_SESSIONS_SECRET=f62e64af694897dd5a3b949891f2715ada568401017905098809aa80e8943dd0 -REDISTOGO_URL=redis://redis:6379 MODERATION_LOGIN=login MODERATION_PASSWORD=password diff --git a/.env.test.sample b/.env.test.sample new file mode 100644 index 0000000..a8bfb5d --- /dev/null +++ b/.env.test.sample @@ -0,0 +1,14 @@ +# Define ENV variables for test environment + +# For local development: +DATABASE_URL=postgresql://localhost/rubyjobs_test +REDISTOGO_URL=redis://localhost:6379 + +# For Docker development uncomment these lines (and comment similar lines above): +# DATABASE_URL=postgres://rubyjobs@postgres/rubyjobs_test +# REDISTOGO_URL=redis://redis:6379 +# DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true + +SERVE_STATIC_ASSETS=true +WEB_SESSIONS_SECRET=ef09acb9b6d59ea2c7565bfbeb0fce5253445d6a8c784339d5cea71305ed8b85 +MODERATION_SESSIONS_SECRET=d0111ed3e5f320d69e38f88fc351197cb56e2d67bf4ba61c2f0a294fb3bfc534 diff --git a/docker-compose.development.yml b/docker-compose.development.yml index d28344a..103f2c9 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -7,8 +7,8 @@ services: postgres: image: postgres:9.6.2-alpine environment: - POSTGRES_USER: safelylaunch - POSTGRES_DB: core + POSTGRES_USER: rubyjobs + POSTGRES_DB: rubyjobs_development ports: - 5432:5432 @@ -24,5 +24,3 @@ services: depends_on: - postgres - redis - env_file: - - .env.development From 184132604868f80a5e4d7197d4f1bd7e804e8264 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 15:40:19 +0300 Subject: [PATCH 6/9] Move documentation from README.md to CONTRIBUTING.md --- CONTRIBUTING.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 29 +++++++++------- 2 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..21f9e64 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,90 @@ +RubyJobs.dev is an open source project and we would love you to help us make it better. + +## Reporting Issues + +A well formatted issue is appreciated, and goes a long way in helping us help you. + +* Make sure you have a [GitHub account](https://github.com/signup/free) +* Submit a [Github issue](https://github.com/davydovanton/rubyjobs.dev/issues/new) by: + * Clearly describing the issue + * Provide a descriptive summary + * Explain the expected behavior + * Explain the actual behavior + * Provide steps to reproduce the actual behavior + * Put application stacktrace as text (in a [Gist](https://gist.github.com) for bonus points) + * Any relevant stack traces + +If you provide code, make sure it is formatted with the triple backticks (\`). + +At this point, we'd love to tell you how long it will take for us to respond, +but we just don't know. + +## Pull requests + +We accept pull requests to RubyJobs.dev for: + +* Fixing bugs +* Adding new features + +Not all features proposed will be added but we are open to having a conversation +about a feature you are championing. + +Here's a quick guide: + +1. Fork the repo. + +2. Run the tests. + +3. Create a new branch and make your changes. This includes tests for features! + +4. Push to your fork and submit a pull request. For more information, see +[Github's pull request help section](https://help.github.com/articles/using-pull-requests/). + +At this point you're waiting on us. Expect a conversation regarding your pull +request, questions, clarifications, and so on. + +## How to install project + +The first thing what you need to start project is copying sample configs: + +```bash +$ cp .env.development.sample .env.development +$ cp .env.test.sample .env.test +``` + +If you want to contribute inside Docker instead of local development, +then you need to uncomment `DATABASE_URL`, `REDISTOGO_URL` and other variables +in Docker section in these configs. + +Project will be available on [http://localhost:2300](http://localhost:2300). + +### Local development + +```bash +$ bundle install +$ bundle exec hanami db prepare +$ bundle exec hanami s +``` + +### Docker development + +```bash +$ make dockerize +``` + +## How to run tests + +### Local development + +```bash +$ HANAMI_ENV=test bundle exec hanami db prepare +$ bundle exec rspec +``` + +### Docker development + +```bash +$ make shell +$ HANAMI_ENV=test bundle exec hanami db prepare +$ bundle exec rspec +``` diff --git a/README.md b/README.md index fcae53f..f108bba 100644 --- a/README.md +++ b/README.md @@ -3,27 +3,32 @@ Welcome to your new Hanami project! -## How to run app inside Docker +## Setup -Copy development env-file from sample file: +How to run tests: -```bash -cp .env.development.sample .env.development +``` +% bundle exec rake ``` -Then simply run in your terminal: +How to run the development console: -```bash -make dockerize ``` +% bundle exec hanami console +``` + +How to run the development server: -Open [http://localhost:2300](http://localhost:2300) in your browser. +``` +% bundle exec hanami server +``` -## How to get container's shell +How to prepare (create and migrate) DB for `development` and `test` environments: -Run in your terminal: +``` +% bundle exec hanami db prepare -```bash -make shell +% HANAMI_ENV=test bundle exec hanami db prepare ``` +Explore Hanami [guides](http://hanamirb.org/guides/), [API docs](http://docs.hanamirb.org/1.3.0.beta1/), or jump in [chat](http://chat.hanamirb.org) for help. Enjoy! 🌸 From c8c7910144726584bd7ee516fe65f481ee0527db Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 16:09:42 +0300 Subject: [PATCH 7/9] Increase Redis ConnectionPool size to 12 because of Sidekiq --- system/boot/redis.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/boot/redis.rb b/system/boot/redis.rb index e74c311..63dd444 100644 --- a/system/boot/redis.rb +++ b/system/boot/redis.rb @@ -3,7 +3,7 @@ Container.boot(:redis) do |container| init do uri = URI.parse(ENV.fetch('REDISTOGO_URL', '')) - redis = ConnectionPool.new(size: 10, timeout: 3) do + redis = ConnectionPool.new(size: 12, timeout: 3) do Redis.new(driver: :hiredis, host: uri.host, port: uri.port, password: uri.password) end From 46067d612a68db52d5732d7ef440e4d293431e81 Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sat, 4 May 2019 16:10:09 +0300 Subject: [PATCH 8/9] Add Sidekiq to dockerized app --- docker-compose.development.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 103f2c9..1414697 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -24,3 +24,14 @@ services: depends_on: - postgres - redis + + sidekiq: + build: + context: . + dockerfile: Dockerfile.development + command: bundle exec sidekiq -r ./config/boot.rb + volumes: + - .:/app + depends_on: + - postgres + - redis From 49679990f7ef828f039fda8af764edae27d052df Mon Sep 17 00:00:00 2001 From: Alexander Kadyrov Date: Sun, 5 May 2019 02:15:31 +0300 Subject: [PATCH 9/9] Revert Redis ConnectionPool size to 10 --- docker-compose.development.yml | 2 +- system/boot/redis.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 1414697..5212a4f 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -29,7 +29,7 @@ services: build: context: . dockerfile: Dockerfile.development - command: bundle exec sidekiq -r ./config/boot.rb + command: bundle exec sidekiq -r ./config/boot.rb -c 7 volumes: - .:/app depends_on: diff --git a/system/boot/redis.rb b/system/boot/redis.rb index 63dd444..e74c311 100644 --- a/system/boot/redis.rb +++ b/system/boot/redis.rb @@ -3,7 +3,7 @@ Container.boot(:redis) do |container| init do uri = URI.parse(ENV.fetch('REDISTOGO_URL', '')) - redis = ConnectionPool.new(size: 12, timeout: 3) do + redis = ConnectionPool.new(size: 10, timeout: 3) do Redis.new(driver: :hiredis, host: uri.host, port: uri.port, password: uri.password) end