Skip to content

Commit

Permalink
Merge pull request #2899 from betagouv/dev
Browse files Browse the repository at this point in the history
2018-10-24-01
  • Loading branch information
LeSim authored Oct 24, 2018
2 parents 2b65bee + 5b8c640 commit 840faf7
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 227 deletions.
27 changes: 0 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,6 @@ jobs:
- run:
name: Run linters
command: bundle exec rake lint
deploy:
<<: *defaults
steps:
- checkout
- *bundle_restore_cache
- *bundle_install
- add_ssh_keys:
fingerprints:
- "0e:db:db:9c:54:ac:60:1a:d3:ba:28:03:2e:7d:0e:9a"
- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "dev" ]; then
bundle exec rake deploy to=staging
fi
if [ "${CIRCLE_BRANCH}" == "master" ]; then
bundle exec rake deploy to=production
fi

workflows:
version: 2
Expand All @@ -122,12 +104,3 @@ workflows:
- lint:
requires:
- build
- deploy:
filters:
branches:
only:
- dev
- master
requires:
- test
- lint
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ gem 'deep_cloneable'

gem 'warden', git: 'https://github.com/hassox/warden.git', branch: 'master'

# Use Unicorn as the app server
gem 'unicorn'
# Use Puma as the app server
gem 'puma'

# serializer
gem 'active_model_serializers'
Expand Down Expand Up @@ -171,7 +171,7 @@ group :development, :test do
gem 'rspec-rails'

# Deploy
gem 'mina', ref: '343a7', git: 'https://github.com/mina-deploy/mina.git'
gem 'mina', git: 'https://github.com/mina-deploy/mina.git'

gem 'rspec_junit_formatter'
end
13 changes: 4 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ GIT

GIT
remote: https://github.com/mina-deploy/mina.git
revision: 343a7ab672d8b4f0ddb84ec240cde7d94b46397a
ref: 343a7
revision: 0dd5fdb8bb82a180d35e1fc033de2fac48257e30
specs:
mina (0.3.8)
mina (1.2.3)
open4 (~> 1.3.4)
rake

Expand Down Expand Up @@ -450,7 +449,6 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kgio (2.11.2)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.6.0)
Expand Down Expand Up @@ -558,6 +556,7 @@ GEM
byebug (~> 10.0)
pry (~> 0.10)
public_suffix (3.0.2)
puma (3.12.0)
rack (2.0.5)
rack-handlers (0.7.3)
rack
Expand Down Expand Up @@ -607,7 +606,6 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
raindrops (0.19.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
Expand Down Expand Up @@ -764,9 +762,6 @@ GEM
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)
unicorn (5.4.1)
kgio (~> 2.6)
raindrops (~> 0.7)
validate_email (0.1.6)
activemodel (>= 3.0)
mail (>= 2.2.5)
Expand Down Expand Up @@ -863,6 +858,7 @@ DEPENDENCIES
prawn_rails
premailer-rails
pry-byebug
puma
rack-handlers
rack-mini-profiler
rails
Expand Down Expand Up @@ -891,7 +887,6 @@ DEPENDENCIES
timecop
turbolinks
typhoeus
unicorn
vcr
warden!
web-console
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/champs/dossier_link_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Champs::DossierLinkController < ApplicationController
before_action :authenticate_logged_user!

def show
@position = params[:position]

if params[:dossier].key?(:champs_attributes)
@dossier_id = params[:dossier][:champs_attributes][params[:position]][:value]
else
Expand Down
2 changes: 1 addition & 1 deletion app/views/champs/dossier_link/show.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= render_to_element('.dossier-link .help-block',
<%= render_to_element(".dossier-link-#{@position} .help-block",
partial: 'shared/champs/dossier_link/help_block',
locals: { id: @dossier_id }) %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.dossier-link
.dossier-link{ class: "dossier-link-#{form.index}" }
= form.number_field :value,
placeholder: "Numéro de dossier",
autocomplete: 'off',
Expand Down
128 changes: 51 additions & 77 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,91 +13,47 @@
# forward_agent - SSH forward_agent
# user - Username in the server to SSH to

if !["staging", "production"].include?(ENV['to'])
raise "missing or incorrect `to` (should be 'staging' or 'production')"
end

if ENV['domain'].nil?
raise "missing `domain`"
end

set :domain, ENV['domain']
set :domain, ENV.fetch('domain')
set :repository, 'https://github.com/betagouv/tps.git'
set :port, 2200
set :rails_env, 'production'
set :rbenv_path, "/usr/local/rbenv/bin/rbenv"
set :forward_agent, true
deploy_to = '/var/www/ds'
set :deploy_to, deploy_to
set :user, 'ds'
set :branch, ENV.fetch('branch')

# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, [
'.env',
set :shared_dirs, [
'log',
'uploads',
'sockets',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'public/system',
'public/uploads',
'config/unicorn.rb'
'tmp/cache'
]

case ENV["to"]
when "staging"
set :branch, ENV['branch'] || 'dev'
set :deploy_to, '/var/www/tps_dev'
set :user, 'tps_dev'
appname = 'tps_dev'
when "production"
set :branch, ENV['branch'] || 'master'
set :deploy_to, '/var/www/tps'
set :user, 'tps'
appname = 'tps'
end
set :rbenv_path, "/home/ds/.rbenv/bin/rbenv"
set :forward_agent, true # SSH forward_agent.

print "Deploy to #{ENV['to']} environment branch #{branch}\n"
puts "Deploy to #{ENV.fetch('domain')}, branch: #{ENV.fetch('branch')}"

# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

queue! %[mkdir -p "#{deploy_to}/shared/bin"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/bin"]

queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]

queue! %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]

queue! %[mkdir -p "#{deploy_to}/shared/tmp/sockets"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/sockets"]

queue! %[mkdir -p "#{deploy_to}/shared/public/system"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/public/system"]

queue! %[mkdir -p "#{deploy_to}/shared/public/uploads"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/public/uploads"]
task :setup do
command %[mkdir -p "#{deploy_to}/shared/log"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]

queue! %[mkdir -p "#{deploy_to}/shared/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
command %[mkdir -p "#{deploy_to}/shared/tmp/pids"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]

queue! %[mkdir -p "#{deploy_to}/shared/app"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/app"]
command %[mkdir -p "#{deploy_to}/shared/tmp/cache"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/cache"]

queue! %[mkdir -p "#{deploy_to}/shared/views/layouts"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/views/layouts"]

queue! %[mkdir -p "#{deploy_to}/shared/config/locales/dynamics"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config/locales/dynamics"]
command %[mkdir -p "#{deploy_to}/shared/sockets"]
command %[chmod g+rx,u+rwx "#{deploy_to}/shared/sockets"]
end

namespace :yarn do
desc "Install package dependencies using yarn."
task :install do
queue %{
command %{
echo "-----> Installing package dependencies using yarn"
#{echo_cmd %[yarn install --non-interactive]}
}
Expand All @@ -107,34 +63,52 @@
namespace :after_party do
desc "Run after_party tasks."
task :run do
queue %{
command %{
echo "-----> Running deploy tasks"
#{echo_cmd %[#{rake} after_party:run]}
#{echo_cmd %[bundle exec rake after_party:run]}
}
end
end

namespace :service do
desc "Restart puma"
task :restart_puma do
command %{
echo "-----> Restarting puma service"
#{echo_cmd %[sudo systemctl restart puma]}
echo "-----> Reloading nginx service"
#{echo_cmd %[sudo systemctl reload nginx]}
}
end

desc "Restart delayed_job"
task :restart_delayed_job do
command %{
echo "-----> Restarting delayed_job service"
#{echo_cmd %[sudo systemctl restart delayed_job]}
}
end
end

desc "Deploys the current version to the server."
task :deploy => :environment do
queue 'export PATH=$PATH:/usr/local/rbenv/bin:/usr/local/rbenv/shims'
task :deploy do
command 'export PATH=$PATH:/home/ds/.rbenv/bin:/home/ds/.rbenv/shims'
command 'source /home/ds/.profile'
deploy do
queue %[sudo service delayed_job_#{user!} stop || true]
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'

invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'yarn:install'
invoke :'rails:db_migrate'
invoke :'after_party:run'
invoke :'rails:assets_precompile:force'

to :launch do
queue "/etc/init.d/#{user} upgrade "
queue! %[sudo service delayed_job_#{user!} start]
invoke :'rails:assets_precompile'

# If you are deploying a review app on a fresh testing environment,
# now can be a good time to seed the database.
on :launch do
invoke :'service:restart_puma'
invoke :'service:restart_delayed_job'
end
end
end
56 changes: 56 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!

# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end

# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
Loading

0 comments on commit 840faf7

Please sign in to comment.