Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

[WIP] Dockerising the app #62

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GITLAB_KEY=YOUR_KEY
GITLAB_SECRET=YOUR_SECRET
GITLAB_ACCESS_TOKEN=YOUR_TOKEN

RAILS_ENV=development
PORT=3000
6 changes: 0 additions & 6 deletions .envrc

This file was deleted.

16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ruby:2.7.1

RUN mkdir /app
WORKDIR /app

RUN gem install bundler:2.1.4
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y yarn
RUN yarn install



COPY docker-entrypoint.sh docker-entrypoint.sh
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["/app/docker-entrypoint.sh"]
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ gem 'jbuilder', '~> 2.10'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.7', require: false

gem 'pg'
gem 'dotenv-rails'

group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
#gem 'sqlite3', '~> 1.4'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'factory_bot_rails', '~> 6.1'
Expand All @@ -58,9 +61,6 @@ group :test do
gem 'webdrivers'
end

group :production do
gem 'pg'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
Expand Down
7 changes: 5 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ GEM
rest-client (>= 1.8.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
railties (>= 3.2)
erubi (1.9.0)
excon (0.76.0)
factory_bot (6.1.0)
Expand Down Expand Up @@ -341,7 +345,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.0.1)
Expand Down Expand Up @@ -391,6 +394,7 @@ DEPENDENCIES
byebug
capybara (~> 3.33)
dependabot-omnibus (~> 0.118.8)
dotenv-rails
factory_bot_rails (~> 6.1)
faker (~> 2.13)
jbuilder (~> 2.10)
Expand All @@ -406,7 +410,6 @@ DEPENDENCIES
shoulda-matchers (~> 4.0)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.4)
turbolinks (~> 5.2, >= 5.2.1)
tzinfo-data
web-console (>= 3.3.0)
Expand Down
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,49 @@ We’re going to use [rbenv](https://github.com/sstephenson/rbenv) to install
```
**Environment variables**

There is a file called `.envrc` in the root directory of this project with all the environment variables set to empty value. You can set the correct values as per the following options:
To generate your GITLAB_KEY and GITLAB_SECRET sign in to your gitlab and go to 'User Settings > Applications'
```
-provide a suitable name
-redirect URI = https://<your_hostname>/auth/gitlab/callback
-check all the necessary access
-click on 'Save Application'
```

export GITLAB_KEY=your-key
export GITLAB_SECRET=your-secret
Doing this will generate your application ID and SECRET which will be your KEY and SECRET respectively.

export GITHUB_ACCESS_TOKEN=your-token
To generate your GITLAB_ACCESS_TOKEN sign in to your gitlab and go to 'User Settings > Access Tokens'

export RAILS_ENV=development
export PORT=3000
```
-provide a suitable name
-keep the date section blank if you want to use the toke indefinitely
-check all the necessary access
-click on 'Create Personal Access Token'
```
Doing this will generate your Access Token.

There is a file called `.env` in the root directory of this project with all the environment variables set to empty value. You can set the correct values as per the following options:

GITLAB_KEY=your-key
GITLAB_SECRET=your-secret

GITLAB_ACCESS_TOKEN=your-token

RAILS_ENV=development
PORT=3000

**Starting Docker**

Make sure to be in the 'gitlab-dependabot-example' folder then follow the below steps

```
$ docker-compose build
$ docker-compose run web bash
* it will bash in the container *
# rake db:create
# rake db:migrate
# exit
$ docker-compose up
```

**Test on LocalHost**

Expand All @@ -71,6 +104,10 @@ Make sure your are in the root directory and start the web server:

Run with `—help` or `-h` for options.

**Ps:** you'll need to make your `url` public inorder for Gitlab OAuth to work. Try using `ngrok` or some other service to test locally.
**Ps:**

you'll need to make your `url` public inorder for Gitlab OAuth to work. Try using `ngrok` or some other service to test locally.

Make sure 'merge requests' in gitlab repository settings is enabled.

Go to http://localhost:3000 and Play around!
48 changes: 33 additions & 15 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3
#default: &default
# adapter: sqlite3
# pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# timeout: 5000
#
#development:
# <<: *default
# database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
#test:
# <<: *default
# database: db/test.sqlite3
#
#production:
# adapter: postgresql
# database: project_pipe_production
# pool: 5
# timeout: 5000

#Below config is for docker for deploying otherwise un comment the production test default and development section

production:
development:
adapter: postgresql
host: db
database: sample_app
username: postgres
password: password1234

test:
adapter: postgresql
database: project_pipe_production
pool: 5
timeout: 5000
host: db
database: sample_app_test
username: postgres
password: password1234


26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
- bundle-volume:/usr/local/bundle
ports:
- "3000:3000"
depends_on:
- db


db:
image: postgres:12
volumes:
- db-volume:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: password1234

volumes:
bundle-volume:
db-volume:
8 changes: 8 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e

bundle install;

rm -f /app/tmp/pids/server.pid

exec "$@"