Skip to content

Commit

Permalink
Add Docker support for development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Feb 24, 2022
1 parent 7ce643f commit 51f2cc6
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 20 deletions.
19 changes: 19 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SECRET_KEY_BASE=djiv7839b9j69ew89gf9n5495rh9bvksmk23i8cv9oi54kju1gfi
SITE_HOST=localhost:8282
MAILER_DELIVERY_METHOD=smtp
RAILS_SERVE_STATIC_FILES=true
SMTP_PORT=1025
LOG_RECAPTCHA_RESPONSES=true
RECAPTCHA_SITE_KEY=
RECAPTCHA_SECRET_KEY=
SERVER_TIME_ZONE=UTC
RAILS_LOG_LEVEL=info
RAILS_LOG_TO_STDOUT=true
CAPTCHA_GATEWAY_PERMISSION_TIME=30000
DATABASE_DEV_USERNAME=lumen
DATABASE_DEV_PASSWORD=so-secret
DATABASE_DEV_DB_NAME=lumen_dev
DATABASE_DEV_HOST=postgres
DATABASE_DEV_PORT=5432
ELASTICSEARCH_URL=elasticsearch
TEST_CLUSTER_COMMAND=/elasticsearch_test/elasticsearch-7.17.0/bin/elasticsearch
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ruby:3.0.2

WORKDIR /root

# Google-chrome needs an additional repository
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list
RUN wget https://chromedriver.storage.googleapis.com/98.0.4758.102/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip \
&& mv chromedriver /usr/local/share/ \
&& chmod +x /usr/local/share/chromedriver \
&& ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver \
&& ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

RUN apt-get update && apt-get -y install tzdata git build-essential patch ruby-dev zlib1g-dev liblzma-dev default-jre sudo google-chrome-stable vim nano

# Container user and group
ARG USERNAME=lumen
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create a user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

USER $USERNAME

# Install and cache gems
WORKDIR /
COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install

# Download a standalone version of Elasticsearch, will be used by rspec
WORKDIR /elasticsearch_test
RUN sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.0-linux-x86_64.tar.gz && sudo tar -xvf elasticsearch-7.17.0-linux-x86_64.tar.gz
RUN sudo chown -R $USERNAME:$USERNAME /elasticsearch_test

# Code mounted as a volume
WORKDIR /app

# Just to keep the containder running
CMD (while true; do sleep 1; done;)
78 changes: 67 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,80 @@ Development
* Mail server (SMTP, Sendmail)
* ChromeDriver (used only by test runner)

#### Setup
#### Using Docker

The easiest way to start is to use `Docker`. Make sure you have the `Docker Engine` and `docker-compose` installed.

Clone the repository.

```
cp config/database.yml.docker config/database.yml
```

```
cp .env.docker .env
```

```
docker-compose up
```

```
docker-compose exec website bash
```

```
rake db:drop db:create db:migrate
```

```
rake comfy:cms_seeds:import[lumen_cms,lumen_cms]
```

```
rake db:seed
```

```
rails s -b 0.0.0.0
```

Lumen will be available at `http://localhost:8282`.

#### Manual setup

By default, the app will try to connect to Elasticsearch on `http://localhost:9200`. If you want to use a different host set the `ELASTICSEARCH_URL` environment variable.

$ bundle install
$ cp config/database.yml.example config/database.yml
(edit database.yml as you wish)
(ensure PostgreSQL and Elasticsearch are running)
$ rails db:setup
$ rails lumen:set_up_cms
```
bundle install
```

```
cp config/database.yml.example config/database.yml
```

(edit database.yml as you wish)
(ensure PostgreSQL and Elasticsearch are running)

```
rails db:setup
```

```
rails lumen:set_up_cms
```

#### Running the app
###### Running the app

$ rails s
```
rails s
```

#### Viewing the app
###### Viewing the app

$BROWSER 'http://localhost:3000'
```
$BROWSER 'http://localhost:3000'
```

You can customize behavior during seeding (db:setup) with a couple of environment variables:

Expand Down
32 changes: 32 additions & 0 deletions config/database.yml.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
default: &default
adapter: postgresql
encoding: utf8
min_messages: warning
pool: 5
timeout: 5000

test:
<<: *default
username: <%= ENV['DATABASE_DEV_USERNAME'] %>
password: <%= ENV['DATABASE_DEV_PASSWORD'] %>
host: <%= ENV['DATABASE_DEV_HOST'] %>
port: <%= ENV['DATABASE_DEV_PORT'].to_i %>
database: lumen_test

development:
<<: *default
username: <%= ENV['DATABASE_DEV_USERNAME'] %>
password: <%= ENV['DATABASE_DEV_PASSWORD'] %>
database: <%= ENV['DATABASE_DEV_DB_NAME'] %>
host: <%= ENV['DATABASE_DEV_HOST'] %>
port: <%= ENV['DATABASE_DEV_PORT'].to_i %>
timeout: <%= (ENV['DATABASE_DEV_TIMEOUT'] || 5000).to_i %>

production:
<<: *default
username: <%= ENV['DATABASE_PROD_USERNAME'] %>
password: <%= ENV['DATABASE_PROD_PASSWORD'] %>
database: <%= ENV['DATABASE_PROD_DB_NAME'] %>
host: <%= ENV['DATABASE_PROD_HOST'] %>
port: <%= ENV['DATABASE_PROD_PORT'].to_i %>
timeout: <%= (ENV['DATABASE_PROD_TIMEOUT'] || 5000).to_i %>
1 change: 0 additions & 1 deletion config/database.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ test:
pool: 5
username: postgres
password: postgres

8 changes: 0 additions & 8 deletions config/database.yml.travis

This file was deleted.

50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '2'

services:
postgres:
image: 'postgres:13.6-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
env_file:
- '.env'
environment:
POSTGRES_USER: ${DATABASE_DEV_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_DEV_PASSWORD}

website:
depends_on:
- 'postgres'
build: .
ports:
- '8282:3000'
- '1080:1080'
volumes:
- '.:/app'
env_file:
- '.env'

elasticsearch:
image: elasticsearch:7.17.0
environment:
- http.host=0.0.0.0
- transport.host=0.0.0.0
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
- discovery.type=single-node
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
mem_limit: 4g

volumes:
postgres:
esdata:
esdata_test:
1 change: 1 addition & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
--incognito
--mute-audio
--remote-debugging-port=9222
--no-sandbox
)

chrome_options = Selenium::WebDriver::Chrome::Options.new
Expand Down

0 comments on commit 51f2cc6

Please sign in to comment.