Skip to content

Commit

Permalink
Adds optional support for Docker/Compose (forem#296)
Browse files Browse the repository at this point in the history
* Adds optional support for Docker/Compose

* Upgrades Dockerfile to use a multi-stage build

* Gets rest of stack running in Docker

* Renames queue to jobs, uses jobs namespace command

* Reverts file

* Adds webpacker

* Fixes yarn check issue

* Adds Database URL default connection string

* Remove daemons gem

* Update huskyhook config

* Update seed.rb

* Create .dockerignore

* Increase RackTimeout's config

* Simplify Docker config

* Update README

* Remove postgres url default

* Change docker entry point to 3000

* Remove duped integrity setting
  • Loading branch information
iMerica authored and benhalpern committed Oct 12, 2018
1 parent 8c70c95 commit cfda390
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dockerignore
.git
logs/
tmp/
node_modules/
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: run

run:
docker-compose build && docker-compose run --rm web rails db:setup
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [email protected]: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:
Expand Down
3 changes: 2 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/timeout.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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: "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"
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit cfda390

Please sign in to comment.