Skip to content

Commit

Permalink
Merge pull request #121 from fablabbcn/dockerised-local-development
Browse files Browse the repository at this point in the history
use docker for local development
  • Loading branch information
timcowlishaw authored Apr 23, 2024
2 parents 1698dee + fb7a404 commit 9f0cd70
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby:2.7.6
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-client
RUN mkdir /app
WORKDIR /app
copy .ruby-version /app/.ruby-version
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
CMD ["rails", "server", "-b", "0.0.0.0"]
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,8 @@ Staging web server:
- https://staging-makeworks.herokuapp.com/

### Getting started locally
- Install Ruby 2.7.6 with your version manager of choice:
`asdf install ruby 2.7.6; asdf local ruby 2.7.6` for asdf
- Install bundled gems:
`bundle install`
- Setup the database:
`bundle exec rake db:create && bundle exec rake db:schema:load`
- Install Node 14.21.2:
`nvm install 14.21.2; nvm use 14.21.2` for nvm
- Install Yarn dependencies:
`yarn install --check-files`
- Ensure ActionText is installed:
`bundle exec rails action_text install`
- Install chromedriver for system tests:
`brew install chromedriver` for homebrew on Mac OS X
- Run tests and check they pass:
`bundle exec rails test && bundle exec rails test:system`
- Run the development server:
`bundle exec rails server`

- This is newly dockerised! Simply `docker compose up` and you're away.
- To get a shell for running tests, console, etc `docker compose exec app bash`
### Development

* Run tests with `rails test`
Expand Down Expand Up @@ -98,7 +81,7 @@ There are 3 roles:

To become a 'champion' an admin needs to make you one, via the https://new.make.works/admin/user_regions interface.

Edit manufacturering tags in a not verified listing as an admin by deleting /admin/ out of listing URL to enter front end editor.
Edit manufacturering tags in a not verified listing as an admin by deleting /admin/ out of listing URL to enter front end editor.

## TODO consideration

Expand Down
26 changes: 26 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
db:
image: postgres
volumes:
- mw-postgres:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
app:
build: .
volumes:
- .:/app
ports:
- "3000:3000"
environment:
CHROME_SERVER_HOST: chrome-server
depends_on:
- db
- chrome-server
chrome-server:
image: selenium/standalone-chrome:96.0
ports:
- "7900:7900"
- "4444:4444"
volumes:
mw-postgres:

9 changes: 6 additions & 3 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ default: &default

development:
<<: *default
host: db
username: postgres
password: postgres
database: makeworks_dev

# Warning: The database defined as "test" will be erased and
Expand All @@ -19,9 +22,9 @@ development:
test:
<<: *default
database: <%= ENV['TEST_DB_NAME'] || 'makeworks_test' %>
host: <%= ENV['TEST_DB_HOST'] %>
username: <%= ENV['TEST_DB_USERNAME'] %>
password: <%= ENV['TEST_DB_PASSWORD'] %>
host: <%= ENV['TEST_DB_HOST'] || 'db' %>
username: <%= ENV['TEST_DB_USERNAME'] || 'postgres' %>
password: <%= ENV['TEST_DB_PASSWORD'] || 'postgres' %>

production:
<<: *default
Expand Down
13 changes: 9 additions & 4 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include CapybaraSelect2
Capybara.configure do |config|
config.ignore_hidden_elements = false
config.server_host = "0.0.0.0"
config.app_host = "http://#{ENV.fetch("HOSTNAME")}:#{Capybara.server_port}"
end

if ENV['SYSTEM_TEST']
driven_by :selenium, using: ENV['SYSTEM_TEST'].to_sym, screen_size: [1400, 1400]
options = if ENV["CHROME_SERVER_HOST"]
{ browser: :remote, url: "http://#{ENV['CHROME_SERVER_HOST']}:4444" , }
else
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
{}
end

driven_by :selenium, using: ENV.fetch('SYSTEM_TEST', 'chrome').to_sym, screen_size: [1400, 1400], options: options do |driver_options|
driver_options.add_argument "disable-dev-shm-usage"
end
end

0 comments on commit 9f0cd70

Please sign in to comment.