Skip to content

Commit

Permalink
Move from Shoryuken to Sidekiq and add Heroku deploy button
Browse files Browse the repository at this point in the history
  • Loading branch information
petehamilton committed Feb 20, 2016
1 parent 95ae695 commit 8d159e3
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 258 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.4
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
language: ruby

rvm:
- 2.2
- 2.1

sudo: false

bundler_args: ''
Expand Down
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ruby "2.2.4"
source "https://rubygems.org"

gem "gemnasium-parser", "~> 0.1.9"
Expand All @@ -6,16 +7,15 @@ gem "prius", "~> 1.0.0"
gem "gems", "~> 0.8.3"
gem "sentry-raven", "~> 0.15.5"
gem "bundler", "~> 1.11.2"
gem "shoryuken", "~> 2.0.3"
gem "sidekiq", "~> 4.1.0"
gem "sinatra"

group :development do
gem "rspec", "~> 3.4.0"
gem "rspec-its", "~> 1.2.0"
gem "webmock", "~> 1.24.0"
gem "rubocop", "~> 0.36.0"
gem "highline", "~> 1.7.8"
gem "foreman", "~> 0.78.0"
gem "fake_sqs", require: false
gem "aws-sdk", require: false
gem "dotenv", require: false
gem "highline", "~> 1.7.8"
end
46 changes: 9 additions & 37 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,12 @@ GEM
specs:
addressable (2.3.8)
ast (2.2.0)
aws-sdk (2.2.13)
aws-sdk-resources (= 2.2.13)
aws-sdk-core (2.2.13)
jmespath (~> 1.0)
aws-sdk-resources (2.2.13)
aws-sdk-core (= 2.2.13)
builder (3.2.2)
celluloid (0.17.3)
celluloid-essentials
celluloid-extras
celluloid-fsm
celluloid-pool
celluloid-supervision
timers (>= 4.1.1)
celluloid-essentials (0.20.5)
timers (>= 4.1.1)
celluloid-extras (0.20.5)
timers (>= 4.1.1)
celluloid-fsm (0.20.5)
timers (>= 4.1.1)
celluloid-pool (0.20.5)
timers (>= 4.1.1)
celluloid-supervision (0.20.5)
timers (>= 4.1.1)
concurrent-ruby (1.0.0)
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
dotenv (2.1.0)
fake_sqs (0.3.1)
builder
sinatra
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
foreman (0.78.0)
Expand All @@ -42,8 +17,6 @@ GEM
gems (0.8.3)
hashdiff (0.3.0)
highline (1.7.8)
hitimes (1.2.3)
jmespath (1.1.3)
multipart-post (2.0.0)
octokit (4.2.0)
sawyer (~> 0.6.0, >= 0.5.3)
Expand All @@ -55,6 +28,7 @@ GEM
rack-protection (1.5.3)
rack
rainbow (2.1.0)
redis (3.2.2)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
Expand Down Expand Up @@ -83,17 +57,16 @@ GEM
faraday (~> 0.8, < 0.10)
sentry-raven (0.15.5)
faraday (>= 0.7.6)
shoryuken (2.0.3)
aws-sdk-core (~> 2)
celluloid (~> 0.16)
sidekiq (4.1.0)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
redis (~> 3.2, >= 3.2.1)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
thor (0.19.1)
tilt (2.0.2)
timers (4.1.1)
hitimes
webmock (1.24.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -103,10 +76,8 @@ PLATFORMS
ruby

DEPENDENCIES
aws-sdk
bundler (~> 1.11.2)
dotenv
fake_sqs
foreman (~> 0.78.0)
gemnasium-parser (~> 0.1.9)
gems (~> 0.8.3)
Expand All @@ -117,7 +88,8 @@ DEPENDENCIES
rspec-its (~> 1.2.0)
rubocop (~> 0.36.0)
sentry-raven (~> 0.15.5)
shoryuken (~> 2.0.3)
sidekiq (~> 4.1.0)
sinatra
webmock (~> 1.24.0)

BUNDLED WITH
Expand Down
7 changes: 2 additions & 5 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
file_fetcher: AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_SQS_ENDPOINT="http://localhost:4568" bundle exec shoryuken -q bump-repos_to_fetch_files_for -r ./app/init_shoryuken.rb -C ./config/shoryuken.yml
file_parser: AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_SQS_ENDPOINT="http://localhost:4568" bundle exec shoryuken -q bump-dependency_files_to_parse -r ./app/init_shoryuken.rb -C ./config/shoryuken.yml
update_checker: AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_SQS_ENDPOINT="http://localhost:4568" bundle exec shoryuken -q bump-dependencies_to_check -r ./app/init_shoryuken.rb -C ./config/shoryuken.yml
file_updater: AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_SQS_ENDPOINT="http://localhost:4568" bundle exec shoryuken -q bump-dependencies_to_update -r ./app/init_shoryuken.rb -C ./config/shoryuken.yml
pull_request_creator: AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=fake AWS_SECRET_ACCESS_KEY=fake AWS_SQS_ENDPOINT="http://localhost:4568" bundle exec shoryuken -q bump-updated_dependency_files -r ./app/init_shoryuken.rb -C ./config/shoryuken.yml
worker: bundle exec sidekiq -q bump-repos_to_fetch_files_for -q bump-dependency_files_to_parse -q bump-dependencies_to_check -q bump-dependencies_to_update -q bump-updated_dependency_files -r ./app/init_sidekiq.rb -c 1
web: bundle exec rackup ./sidekiq_web.ru -p $PORT
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,28 @@ the dependencies you'd like to update.
# token with access to your project and all of its private dependencies.
```

2. Set up a local SQS compatible message queue. We use [fake_sqs](https://github.com/iain/fake_sqs):
```bash
bundle exec fake_sqs
```

3. In a new window, create queues (persisted in memory only) for each of Bump's services:
```bash
bundle exec bin/set_up_sqs_queues
```

4. Start a worker for each queue. We use [foreman](http://ddollar.github.io/foreman/) to automate the process:
2. Start a worker for each queue. We use [foreman](http://ddollar.github.io/foreman/) to automate the process:
```bash
bundle exec foreman start
```

5. In a new window, push a message to `DependencyFileFetcher` (the first of Bump's services):
3. In a new window, push a message to `DependencyFileFetcher` (the first of Bump's services):
```bash
bundle exec bin/bump_dependencies_for_repo
```

### Hosting bump on AWS
### Hosting Bump
You can launch your own instance of Bump via Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

Bump is designed to be easily deployed to AWS's Elastic Container Service (ECS)
so you can set it up to run daily. More details TBC.
Once you've deployed, you'll want to click through to heroku scheduler in the
list of addons and set up a scheduled task to bump your dependencies each day.

You can use the `./bin/bump_dependencies_for_repo` script to do this:
```
./bin/bump_dependencies_for_repo gocardles/bump ruby
```

# The code / contributing

Expand All @@ -76,6 +74,7 @@ We'd love to see the following improvements to Bump:
actual install.
- Support for more languages. Python should be relatively easy, for example.


---

GoCardless ♥ open source. If you do too, come [join us](https://gocardless.com/jobs#software-engineer).
31 changes: 31 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "Bump",
"description": "Gives your repo dependencies a much needed bump",
"repository": "https://github.com/gocardless/bump",
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
},
{
"url": "https://github.com/heroku/heroku-buildpack-ruby"
}
],
"env": {
"AUTH_USERNAME": {
"description": "Username to access the sidekiq UI",
"required": true
},
"AUTH_PASSWORD": {
"description": "Password to access the sidekiq UI",
"required": true
},
"BUMP_GITHUB_TOKEN": {
"description": "The Github API key to use when accessing repos and creating pull requests",
"required": true
}
},
"addons": [
"heroku-redis",
"scheduler"
]
}
2 changes: 1 addition & 1 deletion app/boot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "prius"
require "shoryuken"
require "sidekiq"
require "raven"
require "./lib/null_logger"

Expand Down
File renamed without changes.
16 changes: 7 additions & 9 deletions app/workers/dependency_file_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
require "shoryuken"
require "sidekiq"
require "./app/boot"
require "./app/dependency_file_fetchers/ruby"
require "./app/dependency_file_fetchers/node"
require "./app/workers/dependency_file_parser"

$stdout.sync = true

module Workers
class DependencyFileFetcher
include Shoryuken::Worker
include Sidekiq::Worker

shoryuken_options(
queue: "bump-repos_to_fetch_files_for",
body_parser: :json,
auto_delete: true,
retry_intervals: [60, 300, 3_600, 36_000] # specified in seconds
)
sidekiq_options queue: "bump-repos_to_fetch_files_for", retry: 4

def perform(_sqs_message, body)
sidekiq_retry_in { |count| [60, 300, 3_600, 36_000][count] }

def perform(body)
file_fetcher = file_fetcher_for(body["repo"]["language"])

dependency_files =
Expand Down
14 changes: 5 additions & 9 deletions app/workers/dependency_file_parser.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
require "shoryuken"
require "sidekiq"
require "./app/boot"
require "./app/dependency_file"
require "./app/dependency_file_parsers/ruby"
require "./app/dependency_file_parsers/node"
require "./app/workers/update_checker"

$stdout.sync = true

module Workers
class DependencyFileParser
include Shoryuken::Worker
include Sidekiq::Worker

shoryuken_options(
queue: "bump-dependency_files_to_parse",
body_parser: :json,
auto_delete: true
)
sidekiq_options queue: "bump-dependency_files_to_parse", retry: false

def perform(sqs_message, body)
def perform(body)
parser = parser_for(body["repo"]["language"])
dependency_files = body["dependency_files"].map do |file|
DependencyFile.new(name: file["name"], content: file["content"])
Expand All @@ -32,7 +29,6 @@ def perform(sqs_message, body)
end
rescue => error
Raven.capture_exception(error, extra: { body: body })
sqs_message.delete
raise
end

Expand Down
16 changes: 6 additions & 10 deletions app/workers/dependency_file_updater.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
require "shoryuken"
require "sidekiq"
require "./app/boot"
require "./app/dependency"
require "./app/dependency_file_updaters/ruby"
require "./app/dependency_file_updaters/node"
require "./app/workers/pull_request_creator"

$stdout.sync = true

module Workers
class DependencyFileUpdater
include Shoryuken::Worker
include Sidekiq::Worker

shoryuken_options(
queue: "bump-dependencies_to_update",
body_parser: :json,
auto_delete: true
)
sidekiq_options queue: "bump-dependencies_to_update", retry: false

def perform(sqs_message, body)
def perform(body)
updated_dependency = Dependency.new(
name: body["updated_dependency"]["name"],
version: body["updated_dependency"]["version"]
Expand All @@ -35,10 +32,9 @@ def perform(sqs_message, body)
body["updated_dependency"],
file_updater.updated_dependency_files)
rescue DependencyFileUpdaters::VersionConflict
sqs_message.delete
nil
rescue => error
Raven.capture_exception(error, extra: { body: body })
sqs_message.delete
raise
end

Expand Down
15 changes: 6 additions & 9 deletions app/workers/pull_request_creator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "shoryuken"
require "sidekiq"
require "./app/boot"
require "./app/dependency"
require "./app/dependency_file"
Expand All @@ -8,16 +8,13 @@

module Workers
class PullRequestCreator
include Shoryuken::Worker
include Sidekiq::Worker

shoryuken_options(
queue: "bump-updated_dependency_files",
body_parser: :json,
auto_delete: true,
retry_intervals: [60, 300, 3_600, 36_000] # specified in seconds
)
sidekiq_options queue: "bump-updated_dependency_files", retry: 4

def perform(_sqs_message, body)
sidekiq_retry_in { |count| [60, 300, 3_600, 36_000][count] }

def perform(body)
updated_dependency = Dependency.new(
name: body["updated_dependency"]["name"],
version: body["updated_dependency"]["version"],
Expand Down
Loading

0 comments on commit 8d159e3

Please sign in to comment.