Skip to content
This repository was archived by the owner on Mar 29, 2022. It is now read-only.

Commit 94c67f1

Browse files
authored
Merge pull request #450 from digitalocean/kjuell/docker-dev
Add local Docker setup
2 parents d0a2c03 + 38ea07c commit 94c67f1

18 files changed

+419
-61
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git*
2+
tmp/*
3+
.dockerignore
4+
Dockerfile
5+
docker-compose.yml
6+
README.md
7+
coverage/*
8+
ci/*
9+
docc/*
10+
log/*

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
AIRTABLE_APP_ID: ${{ secrets.AIRTABLE_APP_ID }}
3131
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
3232
SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
33+
REDIS_HOST: localhost
34+
REDIS_PORT: 6379
3335

3436
steps:
3537
- uses: actions/checkout@v1

Dockerfile-nginx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Config for nginx instance that serves community
2+
FROM nginx:1.13.12-alpine
3+
MAINTAINER web-experience@digitalocean.com
4+
5+
WORKDIR /home/deploy/hacktoberfest/current/public
6+
7+
# Copy the configuration over
8+
COPY config/nginx/nginx.conf /etc/nginx/conf.d/default.conf
9+
10+
# Create health check
11+
RUN echo "OK" > health_check.txt

Dockerfile.dev

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM ruby:2.5-slim AS base
2+
3+
ENV BUNDLER_VERSION=2.0.2
4+
ENV REDIS_HOST=redis
5+
6+
RUN apt-get update && apt-get install -y apt-transport-https bash curl git gnupg2 build-essential libpq-dev \
7+
&& curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
8+
&& echo 'deb https://deb.nodesource.com/node_12.x jessie main' > /etc/apt/sources.list.d/nodesource.list
9+
10+
RUN apt-get update \
11+
&& apt-get install -y \
12+
nodejs \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
WORKDIR /app
17+
18+
COPY . ./
19+
20+
RUN gem install bundler -v 2.1.4
21+
22+
COPY Gemfile Gemfile.lock ./
23+
24+
RUN bundle check || bundle install --without production
25+
26+
###############################
27+
FROM ruby:2.5
28+
29+
COPY --from=base /usr/bin/node /usr/bin/node
30+
COPY --from=base /usr/local/bundle /usr/local/bundle
31+
32+
WORKDIR /app
33+
34+
COPY --from=base /app /app
35+
36+
ENTRYPOINT ["./script/docker-entrypoint.sh"]
37+
38+
EXPOSE 3000

Gemfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
source 'https://rubygems.org'
4-
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5-
ruby File.read(File.expand_path("../.ruby-version", __FILE__)).chomp
4+
git_source(:github) { |repo| "https://github.com/digitalocean/hacktoberfest.git" }
65

76
gem 'airbrake', '~> 9.4'
87
gem 'airrecord'
@@ -39,18 +38,21 @@ gem 'rails', '~> 5.2.3'
3938

4039
gem 'sass-rails', '~> 5.0'
4140
gem 'sidekiq', '< 6.0'
41+
gem 'sidekiq-scheduler'
42+
43+
# commenting out these settings since we are not using enterprise sidekiq in local docker dev
44+
#unless ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging' || ENV['REDIS_HOST'] == 'redis'
45+
# require 'dotenv'
46+
# Dotenv.load['BUNDLE_ENTERPRISE__CONTRIBSYS__COM']
47+
#end
48+
49+
#install_if -> { ENV['BUNDLE_ENTERPRISE__CONTRIBSYS__COM'] } do
50+
# source 'https://enterprise.contribsys.com/' do
51+
# gem 'sidekiq-pro'
52+
# gem 'sidekiq-ent'
53+
# end
54+
#end
4255

43-
# unless ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
44-
# require 'dotenv'
45-
# Dotenv.load['BUNDLE_ENTERPRISE__CONTRIBSYS__COM']
46-
# end
47-
#
48-
# install_if -> { ENV['BUNDLE_ENTERPRISE__CONTRIBSYS__COM'] } do
49-
# source 'https://enterprise.contribsys.com/' do
50-
# gem 'sidekiq-pro'
51-
# gem 'sidekiq-ent'
52-
# end
53-
# end
5456

5557
gem 'state_machines'
5658
gem 'state_machines-activerecord'

Gemfile.lock

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ GEM
100100
dotenv-rails (2.7.5)
101101
dotenv (= 2.7.5)
102102
railties (>= 3.2, < 6.1)
103+
e2mmap (0.1.0)
103104
erubi (1.8.0)
105+
et-orbi (1.2.4)
106+
tzinfo
104107
execjs (2.7.0)
105108
factory_bot (5.0.2)
106109
activesupport (>= 4.2.0)
@@ -113,6 +116,9 @@ GEM
113116
faraday (>= 0.7.4, < 1.0)
114117
ffi (1.11.1)
115118
formatador (0.2.5)
119+
fugit (1.3.7)
120+
et-orbi (~> 1.1, >= 1.1.8)
121+
raabro (~> 1.3)
116122
globalid (0.4.2)
117123
activesupport (>= 4.2.0)
118124
guard (2.15.1)
@@ -202,6 +208,7 @@ GEM
202208
public_suffix (4.0.1)
203209
puma (4.1.1)
204210
nio4r (~> 2.0)
211+
raabro (1.3.1)
205212
rack (2.0.7)
206213
rack-protection (2.0.7)
207214
rack
@@ -271,6 +278,8 @@ GEM
271278
rubocop (>= 0.72.0)
272279
ruby-progressbar (1.10.1)
273280
ruby_dep (1.5.0)
281+
rufus-scheduler (3.6.0)
282+
fugit (~> 1.1, >= 1.1.6)
274283
safe_yaml (1.0.5)
275284
sass (3.4.25)
276285
sass-rails (5.1.0)
@@ -292,6 +301,13 @@ GEM
292301
rack (>= 1.5.0)
293302
rack-protection (>= 1.5.0)
294303
redis (>= 3.3.5, < 5)
304+
sidekiq-scheduler (3.0.1)
305+
e2mmap
306+
redis (>= 3, < 5)
307+
rufus-scheduler (~> 3.2)
308+
sidekiq (>= 3)
309+
thwait
310+
tilt (>= 1.4.0)
295311
spring (2.1.0)
296312
spring-watcher-listen (2.0.1)
297313
listen (>= 2.7, < 4.0)
@@ -316,6 +332,8 @@ GEM
316332
terminal-notifier-guard (1.7.0)
317333
thor (0.20.3)
318334
thread_safe (0.3.6)
335+
thwait (0.2.0)
336+
e2mmap
319337
tilt (2.0.9)
320338
turbolinks (5.2.0)
321339
turbolinks-source (~> 5.2)
@@ -379,6 +397,7 @@ DEPENDENCIES
379397
sass-rails (~> 5.0)
380398
shoulda-matchers
381399
sidekiq (< 6.0)
400+
sidekiq-scheduler
382401
spring
383402
spring-watcher-listen (~> 2.0.0)
384403
state_machines
@@ -391,8 +410,5 @@ DEPENDENCIES
391410
web-console (>= 3.3.0)
392411
webmock
393412

394-
RUBY VERSION
395-
ruby 2.5.8p224
396-
397413
BUNDLED WITH
398414
2.1.4

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ These instructions will get you a copy of the project up and running on your loc
3939
## Application Setup
4040

4141
1) [Install and Setup](#installing)
42-
2) [Setup Oauth Token](#setup-oauth-token)
43-
3) [Configure remaining environment variales](#env-variables)
44-
4) [Create first user](#create-first-user)
45-
5) [Import Projects](#import-projects)
42+
2) [Local Setup With Docker](#local-setup-with-docker)
43+
3) [Setup Oauth Token](#setup-oauth-token)
44+
4) [Configure remaining environment variales](#env-variables)
45+
5) [Create first user](#create-first-user)
46+
6) [Import Projects](#import-projects)
4647

4748
### Installing
4849

@@ -57,6 +58,44 @@ In your local repository, run script/setup, which will install all necessary dep
5758
```
5859
script/setup
5960
```
61+
### Local Setup With Docker
62+
63+
If you would like to use Docker to work with the application, first make sure that you have Docker and Docker Compose on your local machine.
64+
65+
Next clone the repo as described in [Step 1](#installing).
66+
67+
From there, create a local `.env` file, and add fill out the following values, using steps [3](#setup-oauth-token) and [4](#env-variables) to guide you:
68+
69+
```
70+
HACKTOBERFEST_DATABASE_HOST=database
71+
HACKTOBERFEST_DATABASE_USERNAME=
72+
HACKTOBERFEST_DATABASE_PASSWORD=
73+
REDIS_HOST=redis
74+
REDIS_PORT=6379
75+
GITHUB_CLIENT_ID=
76+
GITHUB_CLIENT_SECRET=
77+
START_DATE=
78+
END_DATE=
79+
AIRTABLE_API_KEY=
80+
AIRTABLE_APP_ID=
81+
```
82+
**Note**: Use the following values when setting up your Oauth token:
83+
84+
```
85+
> Homepage URL: `http://localhost`\
86+
> Authorization callback URL: `http://localhost/auth/github/callback`
87+
```
88+
The local Docker setup uses a webserver, in the same way that the application does in staging and production, so it will be reachable on port `80`.
89+
90+
Run `docker-compose up -d` to start your services.
91+
92+
**Testing**
93+
94+
If you would like to run commands against your app service, you can do that with the following command (using rubocop as an example):
95+
96+
```
97+
docker-compose run app --entrypoint "bundle exec rubocop app config db lib spec --safe-auto-correct"
98+
```
6099

61100
### Setup Oauth Token
62101

app/models/github_pull_request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
class GithubPullRequest
4+
attr_accessor :graphql_hash
5+
46
def initialize(hash)
57
@graphql_hash = hash
68
end

config/initializers/sidekiq.rb

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
url: redis_url,
1111
password: ENV.fetch('HACKTOBERFEST_REDIS_PASSWORD', nil)
1212
}
13+
elsif (redis_url = ENV.fetch('REDIS_HOST', nil))
14+
REDIS_LOCAL = { url: "redis://#{redis_url}:#{ENV['REDIS_PORT']}/12" }
1315
end
16+
1417
# rubocop:enable Style/MutableConstant
1518

1619
# Custom Error message reporting a job death to airbrake
@@ -28,46 +31,11 @@ def message
2831
end
2932

3033
Sidekiq.configure_server do |config|
31-
config.redis = REDIS_CONFIG if defined?(REDIS_CONFIG)
32-
33-
# https://github.com/mperham/sidekiq/wiki/Reliability#using-super_fetch
34-
config.super_fetch!
35-
36-
# Periodic job setup
37-
# See: https://github.com/mperham/sidekiq/wiki/Ent-Periodic-Jobs
38-
config.periodic do |mgr|
39-
# Every hour
40-
mgr.register(
41-
'0 */2 * * *',
42-
TransitionAllUsersJob,
43-
retry: 3,
44-
queue: :critical
45-
)
46-
# Every day at 3AM
47-
mgr.register('0 3 * * *', UpdateAllIssuesJob, retry: 3, queue: :critical)
48-
# Every day at 5AM
49-
mgr.register(
50-
'0 5 * * *',
51-
UpdateAllIssuesQualityJob,
52-
retry: 3,
53-
queue: :default
54-
)
55-
# Every hour. 1 hour max latency when updating banned repos in airtable
56-
mgr.register(
57-
'0 * * * *',
58-
BanAllReposJob,
59-
retry: 3,
60-
queue: :default
61-
)
62-
63-
# Every 15 minutes
64-
mgr.register(
65-
'*/15 * * * *',
66-
FetchSpamRepositoriesJob,
67-
retry: 3,
68-
queue: :default
69-
)
70-
end
34+
config.redis = if defined?(REDIS_CONFIG)
35+
REDIS_CONFIG
36+
elsif defined?(REDIS_LOCAL)
37+
REDIS_LOCAL
38+
end
7139

7240
config.death_handlers << lambda { |job, ex|
7341
error = Sidekiq::JobDeathError.new(job, ex)
@@ -78,5 +46,9 @@ def message
7846
end
7947

8048
Sidekiq.configure_client do |config|
81-
config.redis = REDIS_CONFIG if defined?(REDIS_CONFIG)
49+
config.redis = if defined?(REDIS_CONFIG)
50+
REDIS_CONFIG
51+
elsif defined?(REDIS_LOCAL)
52+
REDIS_LOCAL
53+
end
8254
end

0 commit comments

Comments
 (0)