This repository has been archived by the owner on Oct 16, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add some initial buildpack and application commands
- Loading branch information
Showing
4 changed files
with
184 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class Dokuen::Application | ||
|
||
attr_reader :name, :remote | ||
|
||
def initialize(remote, name) | ||
@remote = remote | ||
@name = name | ||
end | ||
|
||
def run(*args) | ||
remote.run(*args) | ||
end | ||
|
||
def sudo(*args) | ||
remote.sudo(*args) | ||
end | ||
|
||
def create! | ||
return if remote.application_exists?(name) | ||
|
||
remote.create_user(name) | ||
dirs = [ | ||
'releases', | ||
'env', | ||
'logs', | ||
'build' | ||
] | ||
dirs.each do |dir| | ||
sudo("mkdir -p #{remote.path}/apps/#{name}/#{dir}") | ||
end | ||
sudo("chown -R #{name}.#{name} #{remote.path}/apps/#{name}") | ||
end | ||
|
||
def destroy! | ||
return unless remote.application_exists?(name) | ||
|
||
sudo("rm -rf #{remote.path}/apps/#{name}") | ||
sudo("userdel #{name}") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,68 @@ | ||
require 'capistrano' | ||
require 'fileutils' | ||
|
||
class Dokuen::Remote | ||
|
||
attr_reader :user, :server_name, :path | ||
|
||
def initialize(spec) | ||
@remote_spec = spec | ||
|
||
@server_name, @path = spec.split(/:/, 2) | ||
|
||
@user, rest = @server_name.split(/@/, 2) | ||
|
||
@cap = Capistrano::Configuration.new | ||
@cap.logger.level = Capistrano::Logger::TRACE | ||
@cap.server(@server_name, :dokuen) | ||
end | ||
|
||
def setup! | ||
@cap.run("hostname") | ||
def prepare! | ||
mkdirs | ||
install_foreman | ||
end | ||
|
||
def run(*args) | ||
@cap.run(*args) | ||
end | ||
|
||
def sudo(*args) | ||
@cap.sudo(*args) | ||
end | ||
|
||
def mkdirs | ||
dirs = [ | ||
'apps', | ||
'env', | ||
'nginx', | ||
'buildpacks', | ||
] | ||
|
||
dirs.each do |dir| | ||
full_path = File.join(path, dir) | ||
sudo("mkdir -p #{full_path}") | ||
sudo("chown #{user} #{full_path}") | ||
end | ||
end | ||
|
||
def install_foreman | ||
sudo("apt-get -y install ruby1.9.1") | ||
sudo("gem install foreman -v 0.55.0") | ||
end | ||
|
||
def clone_buildpack(url) | ||
run("cd #{path}/buildpacks && git clone #{url}") | ||
end | ||
|
||
def remove_buildpack(name) | ||
run("rm -rf #{path}/buildpacks/#{name}") | ||
end | ||
|
||
def application_exists?(name) | ||
@cap.capture("([ -d #{path}/apps/#{name} ] && echo #{name}) || echo '' ") != "" | ||
end | ||
|
||
def create_user(name) | ||
sudo("useradd --home #{path}/apps/#{name} --shell /usr/bin/false #{name}") | ||
end | ||
|
||
end |