Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize application #15

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .env.development.sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# 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

MODERATION_LOGIN="login"
MODERATION_PASSWORD="password"
# For local development:
DATABASE_URL=postgresql://localhost/rubyjobs_development
REDISTOGO_URL=redis://localhost:6379

ROLLBAR_KEY = 'test'
# 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

MODERATION_LOGIN=login
MODERATION_PASSWORD=password

ROLLBAR_KEY=test
5 changes: 0 additions & 5 deletions .env.test

This file was deleted.

14 changes: 14 additions & 0 deletions .env.test.sample
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/public/assets*
/tmp
/coverage

.env.development
.env.test
90 changes: 90 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
20 changes: 20 additions & 0 deletions Dockerfile.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ruby:2.5.0-alpine

# 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 \
&& 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 Gemfile Gemfile.lock ./
RUN bundle install -j $(nproc) --quiet

COPY . ./

ENTRYPOINT ["bundle", "exec"]
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
33 changes: 26 additions & 7 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
version: '3'

services:
redis:
image: redis:latest

postgres:
image: postgres:9.6.2-alpine
environment:
POSTGRES_USER: safelylaunch
POSTGRES_DB: core
POSTGRES_USER: rubyjobs
POSTGRES_DB: rubyjobs_development
ports:
- 5432:5432

web:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we need to add sidekiq too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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

sidekiq:
build:
context: .
dockerfile: Dockerfile.development
command: bundle exec sidekiq -r ./config/boot.rb -c 7
volumes:
- .:/app
depends_on:
- postgres
- redis