diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..3fa9d2c28cd4b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.dockerignore + .git + logs/ + tmp/ + node_modules/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..e2efd01b11488 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM starefossen/ruby-node:2-8-stretch + +WORKDIR /usr/src/app + +COPY Gemfile Gemfile.lock yarn.lock ./ + +RUN yarn install && yarn check --integrity + +ENV RAILS_ENV development + +ENV YARN_INTEGRITY_ENABLED "false" + +RUN bundle install --jobs 20 --retry 5 + +ENTRYPOINT ["bundle", "exec"] + +CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"] diff --git a/Envfile b/Envfile index cb5e47816d8b2..8c006be7614b4 100644 --- a/Envfile +++ b/Envfile @@ -15,8 +15,8 @@ variable :APP_PROTOCOL, :String, default: "http://" variable :DEVTO_USER_ID, :Integer, default: 1 # Service timeout length -variable :RACK_TIMEOUT_WAIT_TIMEOUT, :Integer, default: 100 -variable :RACK_TIMEOUT_SERVICE_TIMEOUT, :Integer, default: 100 +variable :RACK_TIMEOUT_WAIT_TIMEOUT, :Integer, default: 100000 +variable :RACK_TIMEOUT_SERVICE_TIMEOUT, :Integer, default: 100000 # Production related config that can be ignored variable :DEPLOYMENT_SIGNATURE, :String, default: "Optional" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000..97e82a017793d --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: run + +run: + docker-compose build && docker-compose run --rm web rails db:setup diff --git a/README.md b/README.md index 9b950f2afe690..b3ee6267bedf1 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ This section provides a high-level requirement & quick start guide. For detailed - [Yarn](https://yarnpkg.com/): please refer to their [installation guide](https://yarnpkg.com/en/docs/install). - [PostgreSQL](https://www.postgresql.org/) 9.4 or higher. -### Installation +### Standard Installation 0. Make sure all the prerequisites are installed. 1. Fork dev.to repository, ie. https://github.com/thepracticaldev/dev.to/fork @@ -177,6 +177,18 @@ This section provides a high-level requirement & quick start guide. For detailed [View Full Installation Documentation](https://docs.dev.to/installation/) +### Docker Installation (BETA) + +Our docker implementation is incomplete and may not work smoothly. Please kindly report any issues and any contribution is welcomed! + +1. Install `docker` and `docker-compose` +1. `git clone git@github.com:thepracticaldev/dev.to.git` +1. Set environment variables above as described in the "Basic Installation" +1. run `docker-compose build` +1. run `docker-compose run web rails db:setup` +1. run `docker-compose up` +1. That's it! Navigate to `localhost:3000` + #### Starting the application We're mostly a Rails app, with a bit of Webpack sprinkled in. **For most cases, simply running `bin/rails server` will do.** If you're working with Webpack though, you'll need to run the following: diff --git a/config/database.yml b/config/database.yml index 325afe2eb89d6..9604220e86ab2 100644 --- a/config/database.yml +++ b/config/database.yml @@ -24,9 +24,9 @@ default: &default checkout_timeout: 2 variables: statement_timeout: <%= ENV['STATEMENT_TIMEOUT'] || 2500 %> - development: <<: *default + url: <%= ENV.fetch('DATABASE_URL', '') %> database: PracticalDeveloper_development # The specified database role being used to connect to postgres. @@ -62,6 +62,7 @@ development: test: <<: *default host: localhost + url: <%= ENV.fetch('DATABASE_URL', '') %> database: PracticalDeveloper_test<%= ENV['TEST_ENV_NUMBER'] %> # As with config/secrets.yml, you never want to store sensitive information, diff --git a/config/environments/development.rb b/config/environments/development.rb index ff001e99d34b6..becaf3f0c6fe7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,8 +1,12 @@ # rubocop:disable Metrics/BlockLength +# +def yarn_integrity_enabled? + ENV.fetch("YARN_INTEGRITY_ENABLED", "true") == "true" +end Rails.application.configure do # Verifies that versions and hashed value of the package contents in the project's package.json - config.webpacker.check_yarn_integrity = true + config.webpacker.check_yarn_integrity = yarn_integrity_enabled? # Replace with a lambda or method name defined in ApplicationController # to implement access control for the Flipflop dashboard. diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb index c698447018dc8..076288f36d16d 100644 --- a/config/initializers/timeout.rb +++ b/config/initializers/timeout.rb @@ -1,6 +1,6 @@ if Rails.env.development? && ENV["RACK_TIMEOUT_WAIT_TIMEOUT"].nil? - ENV["RACK_TIMEOUT_WAIT_TIMEOUT"] = "100" - ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] = "100" + ENV["RACK_TIMEOUT_WAIT_TIMEOUT"] = "100000" + ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] = "100000" end Rack::Timeout.unregister_state_change_observer(:logger) if Rails.env.development? diff --git a/db/seeds.rb b/db/seeds.rb index 1e4e4e57a4892..84d70866a4b4f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -28,7 +28,7 @@ user = User.create!( name: name = Faker::Name.unique.name, summary: Faker::Lorem.paragraph_by_chars(199, false), - remote_profile_image_url: Faker::Avatar.image(nil, "300x300", "png", "set2", "bg2"), + profile_image: File.open("#{Rails.root}/app/assets/images/#{rand(1..40)}.png"), website_url: Faker::Internet.url, twitter_username: Faker::Internet.username(name), email_comment_notifications: false, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000..96befe1fbf506 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: "3" +services: + web: &rails_base + build: + dockerfile: Dockerfile + context: . + ports: + - "3000:3000" + depends_on: + - db + environment: + RAILS_ENV: development + DATABASE_URL: postgres://postgres:mysecretpassword@db:5432/postgres + YARN_INTEGRITY_ENABLED: "false" + volumes: + - .:/usr/src/app + command: bundle exec rails server -b 0.0.0.0 -p 3000 + jobs: + ports: [] + <<: *rails_base + command: rails jobs:work + webpacker: + ports: [] + <<: *rails_base + command: ./bin/webpack-dev-server + db: + image: postgres + ports: + - "5432:5432" diff --git a/package.json b/package.json index 1808f837ba9a2..43e0e697ec83a 100644 --- a/package.json +++ b/package.json @@ -91,5 +91,10 @@ "prop-types": "^15.6.2", "pusher-js": "^4.3.1", "twilio-video": "^1.14.0" + }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } } }