Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 65 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. # Setup:
  2. # tddium config:add suite EY_API_TOKEN xxxxxxxx
  3. # (take EY_API_TOKEN value from ~/.eyrc)
  4. # tddium config:add suite EY_DEPLOY_KEY yyyyyyy
  5. # (EY_DEPLOY_KEY value is Base64-encoded content of your ~/.ssh/id_rsa OR any other ssh key authorised for a given EY env)
  6.  
  7. require 'timeout'
  8. require 'etc'
  9. require 'base64'
  10.  
  11. def current_branch
  12.   `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`.strip
  13. end
  14.  
  15. def tddium?
  16.   ENV['TDDIUM'].present?
  17. end
  18.  
  19. namespace :tddium do
  20.   desc "Run post-build script"
  21.   task :post_build_hook do
  22.     print_status_info
  23.     if deploy?
  24.       Rake::Task["deploy:dev"].execute
  25.     end
  26.   end
  27.  
  28.   private
  29.  
  30.   def print_status_info
  31.     puts "tddium? " + tddium?.inspect
  32.     puts "passed? " + passed?.inspect
  33.     puts "on_tracked_branch? " + on_tracked_branch?.inspect
  34.     puts "deploy? " + deploy?.inspect
  35.   end
  36.  
  37.   def deploy?
  38.     tddium? && on_tracked_branch? && passed?
  39.   end
  40.  
  41.   def passed?
  42.     ENV['TDDIUM_BUILD_STATUS'] == 'passed'
  43.   end
  44.  
  45.   def on_tracked_branch?
  46.     current_branch == tracked_branch
  47.   end
  48.  
  49.   def tracked_branch
  50.     "develop"
  51.   end
  52. end
  53.  
  54. namespace :deploy do
  55.   desc "Deploy master branch to dev server"
  56.   task :dev do
  57.     deploy_with_timeout
  58.   end
  59.  
  60.   private
  61.  
  62.   def deploy_with_timeout
  63.     Timeout::timeout(600) do
  64.       deploy
  65.     end
  66.   end
  67.  
  68.   def ey_deploy_cmd
  69.     "ey deploy -m -e healthism_dev -r #{current_branch}"
  70.   end
  71.  
  72.   def write_deploy_key
  73.     #It works. Now someone please tell me how to do it properly.
  74.  
  75.     if tddium?
  76.       puts "We're on Tddium: writing deployment key"
  77.       FileUtils.mkdir_p("#{home_dir}/.ssh")
  78.       File.open("#{home_dir}/.ssh/id_rsa", "w") do |f|
  79.         f.write(deploy_key)
  80.         f.chmod(0600)
  81.       end
  82.     end
  83.   end
  84.  
  85.   def write_eyrc
  86.     puts "Writing .eyrc key"
  87.     content = "---\napi_token: #{ENV['EY_API_TOKEN']}"
  88.     File.open("#{home_dir}/.eyrc", "w") do |f|
  89.       f.write(content)
  90.       f.chmod(0600)
  91.     end
  92.   end
  93.  
  94.   def home_dir
  95.     Etc.getpwuid.dir
  96.   end
  97.  
  98.   def deploy_key
  99.     Base64.decode64(ENV['EY_DEPLOY_KEY'])
  100.   end
  101.  
  102.   def deploy
  103.     write_deploy_key
  104.     write_eyrc
  105.     system ey_deploy_cmd
  106.   end
  107. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top