From 217726fccb5cb3e9abb4e6c12f6b6930ae6abf61 Mon Sep 17 00:00:00 2001 From: siddheshpkini Date: Mon, 25 Jan 2021 11:41:39 +0530 Subject: [PATCH 1/2] added Dockerfile, docker- compose.yml and entrypoint.sh file updated Gemfile 'pg as default databse' and changed the database.yml --- Dockerfile | 16 +++++++++++++++ Gemfile | 7 +++---- Gemfile.lock | 2 -- config/database.yml | 48 ++++++++++++++++++++++++++++++-------------- docker-compose.yml | 26 ++++++++++++++++++++++++ docker-entrypoint.sh | 8 ++++++++ 6 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..adbadfdc --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Gemfile b/Gemfile index 1bcbefd1..98506721 100644 --- a/Gemfile +++ b/Gemfile @@ -29,9 +29,11 @@ gem 'jbuilder', '~> 2.10' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.7', require: false +gem 'pg' + 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' @@ -58,9 +60,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] diff --git a/Gemfile.lock b/Gemfile.lock index 04523867..6be4ee26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -341,7 +341,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) @@ -406,7 +405,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) diff --git a/config/database.yml b/config/database.yml index a71c2331..714470a7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e5508736 --- /dev/null +++ b/docker-compose.yml @@ -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: \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..f04d2245 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +bundle install; + +rm -f /app/tmp/pids/server.pid + +exec "$@" \ No newline at end of file From 51e016da24e6952dc3e039bdfa8dd75e35b85037 Mon Sep 17 00:00:00 2001 From: siddheshpkini Date: Thu, 28 Jan 2021 14:18:12 +0530 Subject: [PATCH 2/2] using gem 'dotenv-rails' added '.env' and removed '.envrc' file updated Gemfile and README.md --- .env | 6 ++++++ .envrc | 6 ------ Gemfile | 1 + Gemfile.lock | 5 +++++ README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 .env delete mode 100644 .envrc diff --git a/.env b/.env new file mode 100644 index 00000000..77a0dccb --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +GITLAB_KEY=YOUR_KEY +GITLAB_SECRET=YOUR_SECRET +GITLAB_ACCESS_TOKEN=YOUR_TOKEN + +RAILS_ENV=development +PORT=3000 diff --git a/.envrc b/.envrc deleted file mode 100644 index 66c8f247..00000000 --- a/.envrc +++ /dev/null @@ -1,6 +0,0 @@ -export GITLAB_KEY=your-key -export GITLAB_SECRET=your-secret -export GITHUB_ACCESS_TOKEN=your-token - -export RAILS_ENV=development -export PORT=3000 diff --git a/Gemfile b/Gemfile index 98506721..352ed736 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem 'jbuilder', '~> 2.10' gem 'bootsnap', '>= 1.4.7', require: false gem 'pg' +gem 'dotenv-rails' group :development, :test do # Use sqlite3 as the database for Active Record diff --git a/Gemfile.lock b/Gemfile.lock index 6be4ee26..e32c45bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -390,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) diff --git a/README.md b/README.md index e90b7a01..e10e3b69 100644 --- a/README.md +++ b/README.md @@ -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:///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** @@ -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! \ No newline at end of file