Sha256: f8a3ab54428dd9378db29d9abc920373aab1d4e7a57f5f9105a68916f9107831

Contents?: true

Size: 1.96 KB

Versions: 12

Compression:

Stored size: 1.96 KB

Contents

class App < ApplicationRecord
  belongs_to :user

  after_commit :make_folder, on: [:create]

  def make_folder
    Rails.logger.debug "DB8 app.rb:make_folder() called"
    username = self.user.apiusername
    Cmd.run(%Q[sudo -u #{username} mkdir /home/#{username}/#{self.name}.git])
    Cmd.run(%Q[sudo -u #{username} mkdir /home/#{username}/#{self.name}])

    Cmd.run(%Q[sudo -u postgres createuser -S -D -R -e #{username}])
    Cmd.run(%Q[sudo -u postgres createdb #{self.name}])
    Cmd.run(%Q[sudo -u postgres psql -c "ALTER ROLE #{username} WITH PASSWORD '#{self.user.apisecret}';"])

    Cmd.run(%Q[sudo -u #{username} sh -c "cd /home/#{username}/#{self.name}.git; git --bare init"])
    Cmd.run(%Q[sudo cp /sharedro/etc_nginx_sites-enabled_template /home/#{username}/#{self.name}.conf])
    Cmd.run(%Q[sudo sed -i -e 's/REPLACEMEAPPNAME/#{self.name}/g' /home/#{username}/#{self.name}.conf])
    Cmd.run(%Q[sudo sed -i -e 's/REPLACEMEUSERNAME/#{username}/g' /home/#{username}/#{self.name}.conf])
    Cmd.run(%Q[sudo -u #{username} sh -c "echo '#!/bin/bash
set -x
: Git hook is executing
cd /home/#{username}/#{self.name}
echo 'DATABASE_URL=postgres://#{self.user.apiusername}:#{self.user.apisecret}@localhost:5432/#{self.name}'
export DATABASE_URL="postgres://#{self.user.apiusername}:#{self.user.apisecret}@localhost:5432/#{self.name}"
git --work-tree=/home/#{username}/#{self.name} --git-dir=/home/#{username}/#{self.name}.git checkout -f
bundle install --path vendor/bundle
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake assets:precompile
RAILS_ENV=production bundle exec puma -d -b unix:///home/#{username}/#{self.name}.sock
' > /home/#{username}/#{self.name}.git/hooks/post-receive"])
    Cmd.run(%Q[sudo -u #{username} sh -c 'chmod u+x /home/#{username}/#{self.name}.git/hooks/post-receive'])
    Cmd.run(%Q[sudo ln -s /home/#{username}/#{self.name}.conf /etc/nginx/sites-enabled/#{self.name}])
    Cmd.run(%Q[sudo /usr/sbin/nginx -s reload])
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
meroku-2.0.22 frontend/app/models/app.rb
meroku-2.0.21 frontend/app/models/app.rb
meroku-2.0.20 frontend/app/models/app.rb
meroku-2.0.19 frontend/app/models/app.rb
meroku-2.0.18 frontend/app/models/app.rb
meroku-2.0.17 frontend/app/models/app.rb
meroku-2.0.16 frontend/app/models/app.rb
meroku-2.0.14 frontend/app/models/app.rb
meroku-2.0.13 frontend/app/models/app.rb
meroku-2.0.11 frontend/app/models/app.rb
meroku-2.0.10 frontend/app/models/app.rb
meroku-2.0.9 frontend/app/models/app.rb