mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-10-29 23:32:35 +01:00
Deploy to Digital Ocean
This commit is contained in:
parent
94b355e560
commit
14985cf3e8
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.bundle
|
||||
.env
|
||||
bin
|
||||
log
|
||||
tmp
|
||||
vendor
|
||||
|
3
.pryrc
Normal file
3
.pryrc
Normal file
@ -0,0 +1,3 @@
|
||||
Pry.config.editor = 'vim'
|
||||
require './config/environment'
|
||||
puts "Loading #{App.env}"
|
@ -1,11 +1,4 @@
|
||||
deploy:
|
||||
provider: heroku
|
||||
api_key:
|
||||
secure: KfNLOG7IsAno2IQ3R9DikQ7nVhAGbYQitf6NbJo1jzA7eu/rKNAmqYoJyaNuwEoAd8Dwz98PtQEJb3DmAhtX3xJgZC1BKNPMh9s0NCQO03OsD7cRbyqeyJFgxSH+p+yKC3nILmaxTSLPji3w+h3Qg+Lu1SA+Q6KmxxeajUUSThc=
|
||||
app: fixer
|
||||
on:
|
||||
repo: hakanensari/fixer-io
|
||||
rvm:
|
||||
- 2.2.0
|
||||
- 2.2.1
|
||||
before_script:
|
||||
- psql -c 'create database fixer_test;' -U postgres
|
||||
|
4
Gemfile
4
Gemfile
@ -1,11 +1,11 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
ruby '2.2.0'
|
||||
ruby '2.2.1'
|
||||
|
||||
gem 'fixer'
|
||||
gem 'rollbar'
|
||||
gem 'newrelic_rpm'
|
||||
gem 'librato-rack'
|
||||
gem 'pry'
|
||||
gem 'rake'
|
||||
gem 'sequel_pg'
|
||||
gem 'sinatra-jsonp'
|
||||
|
41
Gemfile.lock
41
Gemfile.lock
@ -1,59 +1,56 @@
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
aggregate (0.2.2)
|
||||
axiom-types (0.1.1)
|
||||
descendants_tracker (~> 0.0.4)
|
||||
ice_nine (~> 0.11.0)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
coderay (1.1.0)
|
||||
coercible (1.0.0)
|
||||
descendants_tracker (~> 0.0.1)
|
||||
descendants_tracker (0.0.4)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
equalizer (0.0.9)
|
||||
faraday (0.9.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
fixer (0.5.0)
|
||||
nokogiri (~> 1.5)
|
||||
ice_nine (0.11.1)
|
||||
kgio (2.9.2)
|
||||
librato-metrics (1.5.0)
|
||||
aggregate (~> 0.2.2)
|
||||
faraday (~> 0.7)
|
||||
multi_json
|
||||
librato-rack (0.4.5)
|
||||
librato-metrics (~> 1.1)
|
||||
kgio (2.9.3)
|
||||
method_source (0.8.2)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.5.0)
|
||||
multi_json (1.10.1)
|
||||
multipart-post (2.0.0)
|
||||
newrelic_rpm (3.9.9.275)
|
||||
nokogiri (1.6.5)
|
||||
minitest (5.5.1)
|
||||
multi_json (1.11.0)
|
||||
newrelic_rpm (3.10.0.279)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
pg (0.18.0)
|
||||
pg (0.18.1)
|
||||
pry (0.10.1)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
rack (1.6.0)
|
||||
rack-protection (1.5.3)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
raindrops (0.13.0)
|
||||
rake (10.4.2)
|
||||
rollbar (1.3.1)
|
||||
rollbar (1.4.4)
|
||||
multi_json (~> 1.3)
|
||||
sequel (4.18.0)
|
||||
sequel (4.20.0)
|
||||
sequel_pg (1.6.11)
|
||||
pg (>= 0.8.0)
|
||||
sequel (>= 3.39.0)
|
||||
shotgun (0.9)
|
||||
shotgun (0.9.1)
|
||||
rack (>= 1.0)
|
||||
sinatra (1.4.5)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
sinatra-cross_origin (0.3.2)
|
||||
sinatra-jsonp (0.4.3)
|
||||
sinatra-jsonp (0.4.4)
|
||||
multi_json (~> 1.8)
|
||||
sinatra (~> 1.0)
|
||||
slop (3.6.0)
|
||||
thread_safe (0.3.4)
|
||||
tilt (1.4.1)
|
||||
unicorn (4.8.3)
|
||||
@ -72,9 +69,9 @@ PLATFORMS
|
||||
|
||||
DEPENDENCIES
|
||||
fixer
|
||||
librato-rack
|
||||
minitest
|
||||
newrelic_rpm
|
||||
pry
|
||||
rack-test
|
||||
rake
|
||||
rollbar
|
||||
|
@ -1 +1,5 @@
|
||||
# Fixer.io
|
||||
|
||||
[![Travis](https://travis-ci.org/hakanensari/fixer-io.svg)](https://travis-ci.org/hakanensari/fixer-io)
|
||||
|
||||
Fixer.io is a JSON API for foreign exchange rates and currency conversion.
|
||||
|
5
Rakefile
5
Rakefile
@ -1,3 +1,4 @@
|
||||
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
||||
require 'rollbar/rake'
|
||||
|
||||
task default: %w(db:migrate rates:reload test)
|
||||
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
||||
task default: %w(db:migrate rates:load test)
|
||||
|
@ -3,7 +3,7 @@ require 'pathname'
|
||||
|
||||
module App
|
||||
class << self
|
||||
attr :logger
|
||||
attr_reader :logger
|
||||
|
||||
def env
|
||||
ENV['RACK_ENV'] || 'development'
|
||||
@ -12,6 +12,10 @@ module App
|
||||
def root
|
||||
Pathname.pwd
|
||||
end
|
||||
|
||||
def version
|
||||
`git rev-parse --short HEAD 2>/dev/null`.strip!
|
||||
end
|
||||
end
|
||||
|
||||
@logger = Logger.new(STDOUT)
|
||||
|
3
config/schedule.rb
Normal file
3
config/schedule.rb
Normal file
@ -0,0 +1,3 @@
|
||||
every :hour do
|
||||
command "foreman run bundle exec rake rates:update"
|
||||
end
|
17
deploy/after_push
Executable file
17
deploy/after_push
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
oldrev=$1
|
||||
newrev=$2
|
||||
|
||||
run() {
|
||||
[ -x $1 ] && $1 $oldrev $newrev
|
||||
}
|
||||
|
||||
echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l)
|
||||
|
||||
umask 002
|
||||
|
||||
git submodule sync && git submodule update --init --recursive
|
||||
|
||||
run deploy/before_restart
|
||||
run deploy/restart && run deploy/after_restart
|
15
deploy/before_restart
Executable file
15
deploy/before_restart
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env ruby
|
||||
oldrev, newrev = ARGV
|
||||
|
||||
def run(cmd)
|
||||
exit($?.exitstatus) unless system "umask 002 && #{cmd}"
|
||||
end
|
||||
|
||||
run "foreman run bundle install --deployment --without development:test"
|
||||
|
||||
tasks = []
|
||||
num_migrations = `git diff #{oldrev} #{newrev} --diff-filter=A --name-only -z db/migrate`.split("\0").size
|
||||
tasks << "db:migrate" if num_migrations > 0
|
||||
tasks << "rates:update"
|
||||
|
||||
run "foreman run bundle exec rake #{tasks.join(" ")}" if tasks.any?
|
2
deploy/restart
Executable file
2
deploy/restart
Executable file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
sudo restart fixer 2>/dev/null || sudo start fixer
|
15
lib/api.rb
15
lib/api.rb
@ -1,3 +1,4 @@
|
||||
require 'rollbar/rack'
|
||||
require 'sinatra'
|
||||
require 'sinatra/cross_origin'
|
||||
require 'sinatra/jsonp'
|
||||
@ -6,14 +7,10 @@ require 'snapshot'
|
||||
|
||||
configure do
|
||||
enable :cross_origin
|
||||
set :root, File.expand_path('..', File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
configure :production do
|
||||
require 'newrelic_rpm'
|
||||
require 'librato-rack'
|
||||
|
||||
use Librato::Rack
|
||||
end
|
||||
|
||||
helpers do
|
||||
@ -32,13 +29,13 @@ helpers do
|
||||
params[:date] = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
|
||||
end
|
||||
|
||||
def halt_with_meaningful_response(status, message)
|
||||
halt status, Yajl::Encoder.encode(error: { status: status, message: message })
|
||||
def halt_with_message(status, message)
|
||||
halt status, Yajl::Encoder.encode(error: message)
|
||||
end
|
||||
end
|
||||
|
||||
get '/' do
|
||||
jsonp(description: 'Fixer.io is a JSON API for foreign exchange rates and currency conversion', docs: 'http://fixer.io')
|
||||
jsonp(details: 'http://fixer.io', version: App.version)
|
||||
end
|
||||
|
||||
get '/latest' do
|
||||
@ -51,9 +48,9 @@ get %r((?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})) do
|
||||
end
|
||||
|
||||
not_found do
|
||||
halt_with_meaningful_response 404, 'Not found'
|
||||
halt_with_message 404, 'Not found'
|
||||
end
|
||||
|
||||
error ArgumentError do
|
||||
halt_with_meaningful_response 422, env['sinatra.error'].message.capitalize
|
||||
halt_with_message 422, env['sinatra.error'].message.capitalize
|
||||
end
|
||||
|
@ -4,8 +4,8 @@ namespace :rates do
|
||||
require 'fixer'
|
||||
end
|
||||
|
||||
desc 'Reload all rates'
|
||||
task reload: :setup do
|
||||
desc 'Load all rates'
|
||||
task load: :setup do
|
||||
Currency.dataset.delete
|
||||
data = Fixer::Feed.new(:historical)
|
||||
Currency.multi_insert(data.to_a)
|
||||
|
Loading…
Reference in New Issue
Block a user