dply 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6a7c74b1b9d89269d2b64c1a023c52a01d6f69a
4
- data.tar.gz: a4cd0427ab1c9609a03e628e880d9877fd80bc9f
3
+ metadata.gz: 00c0a659093842815a148f5e1f69f929d955ea02
4
+ data.tar.gz: 001bc30e98a5fbd634264f2f357bfaf309e09209
5
5
  SHA512:
6
- metadata.gz: bfd678b1482e99e440dfa89edbcde8d533b3f3883f190e05a63f29d5e61f5be3f571f495924b59856e9d4c6c52a670f22c48a3ef5a78d648911960e620f73f5a
7
- data.tar.gz: dcfdee4e48b8b322b0dec930765a1f4be090cec5ef7b8e1714ac8de995a6203db1ed8c91fe25db68d3aec8bd7e43ac5b2df3aabb9e2aa4bf4399efbfae47ed16
6
+ metadata.gz: 869a5296dae63e5ac42020b59a3899f9ec07cf4982a6fa5ee64a17d497f3293d0f8041838bb3d0a32929117903343a42b87cbcbdf91cb8c256d41383956baebd
7
+ data.tar.gz: 4afb2ab78fed6e8a0cef4153aebf85826fd51d6c07dc4a9361d5d22a1dddef5822deb4c8a100e21cdf5d1017a0ba378466ea27b2231ba5a1dbb805ad6892dad3
data/bin/drake CHANGED
@@ -12,30 +12,25 @@ require 'dply/config'
12
12
  require 'pathname'
13
13
 
14
14
  logger = ::Dply::Logger.logger
15
- options = {
16
- read_config: true
17
- }
18
15
 
16
+ options = {}
19
17
  opts_parser = OptionParser.new do |opts|
20
18
 
21
19
  banner = []
22
- banner << "Usage: dply [global options] command [options] args"
23
- banner << "Commands:"
24
- banner << " deploy"
25
- banner << " switch"
26
- banner << " rollback"
20
+ banner << "Usage: drake [global options] command [options] args"
21
+ banner << "Commands: deploy reload task"
27
22
 
28
23
  banner << "Options: "
29
24
  opts.banner = banner.join("\n")
30
25
 
31
- opts.on("-d", "--deploy-dir [DEPLOY DIR]" , "Set deploy dir") do |d|
26
+ opts.on("-d", "--dir [DEPLOY DIR]" , "Set dir") do |d|
32
27
  path = Pathname.new(d)
33
- raise ::Dply::Error, "deploy_dir path must be absolute" if path.relative?
34
- options[:deploy_dir] = path
28
+ raise ::Dply::Error, "dir path must be absolute" if path.relative?
29
+ options[:dir] = path
35
30
  end
36
31
 
37
- opts.on("--no-config", "Do not read config file") do
38
- options[:read_config] = false
32
+ opts.on("--remote" , "Set remote mode") do
33
+ logger.remote_mode = true
39
34
  end
40
35
 
41
36
  opts.on("-v", "--version", "Show version") do |v|
@@ -52,6 +47,7 @@ opts_parser = OptionParser.new do |opts|
52
47
  options[:debug] = true
53
48
  options[:trace] = true
54
49
  logger.level = ::Logger::DEBUG
50
+ logger.trace_mode = true
55
51
  end
56
52
 
57
53
  opts.on_tail("-h", "--help", "Show this message") do
@@ -60,22 +56,24 @@ opts_parser = OptionParser.new do |opts|
60
56
  end
61
57
  end
62
58
 
59
+ def run_cli(command, argv)
60
+ require "dply/cli/#{command}"
61
+ const = "::Dply::Cli::#{command.capitalize}"
62
+ klass = Module.const_get const
63
+ cli = klass.new(argv)
64
+ cli.run
65
+ end
66
+
63
67
  begin
64
68
  opts_parser.order!(ARGV)
65
- deploy_dir = options[:deploy_dir] || Dir.pwd
66
- Dir.chdir deploy_dir
67
- config = Dply::Config.new(deploy_dir, read_config: options[:read_config]).to_struct
69
+ Dir.chdir options[:dir] if options[:dir]
68
70
 
69
71
  command = (ARGV.shift || "").to_sym
70
72
  case command
71
- when :deploy
72
- require 'dply/cli/deploy'
73
- cli = Dply::Cli::Deploy.new(deploy_dir, config, ARGV)
74
- cli.run
75
- when :reload
76
- require 'dply/cli/reload'
77
- cli = Dply::Cli::Reload.new(deploy_dir, config, ARGV)
78
- cli.run
73
+ when :deploy, :reload, :task, :build
74
+ run_cli command, ARGV
75
+ when /[a-zA-Z_\-0-9]+[:][a-zA-Z_\-0-9]+/
76
+ require 'dply/task_runner'
79
77
  when :''
80
78
  puts opts_parser
81
79
  else
@@ -0,0 +1,81 @@
1
+ require 'dply/helper'
2
+ require 'uri'
3
+ module Dply
4
+ class Archive
5
+
6
+ include Helper
7
+
8
+ def initialize(url, verify_checksum: true)
9
+ @url = url
10
+ @verify_checksum = verify_checksum
11
+ end
12
+
13
+ def extract_to(extraction_path)
14
+ download_file if not @downloaded
15
+ FileUtils.rm_rf extraction_path if File.exists? extraction_path
16
+ FileUtils.mkdir_p extraction_path
17
+ cmd "tar xf #{path} -C #{extraction_path}", display: true
18
+ end
19
+
20
+ def clean
21
+ logger.trace "cleaning cache"
22
+ files = [ "tmp/cache/#{name}", "tmp/cache/#{name}.md5" ]
23
+ files.each { |f| FileUtils.rm f if File.exists? f }
24
+ end
25
+ private
26
+
27
+ def download_file
28
+ if File.exists? path
29
+ download if not verify_checksum
30
+ else
31
+ download(uri, path)
32
+ end
33
+ raise if not verify_checksum
34
+ @downloaded = true
35
+ end
36
+
37
+ def uri
38
+ @uri ||= URI.parse(@url)
39
+ end
40
+
41
+ def name
42
+ @name ||= File.basename(uri.path)
43
+ end
44
+
45
+ def path
46
+ @path = "tmp/cache/#{name}"
47
+ end
48
+
49
+ def checksum
50
+ @checksum ||= load_checksum
51
+ end
52
+
53
+ def load_checksum
54
+ file = "tmp/cache/#{name}.md5"
55
+ if File.exists? file
56
+ checksum = File.read(file).chomp
57
+ return checksum if checksum.size == 32
58
+ end
59
+ download("#{uri}.md5", file)
60
+ checksum = File.read(file).chomp
61
+ raise if checksum.size != 32
62
+ return checksum
63
+ end
64
+
65
+ def verify_checksum
66
+ return true if not @verify_checksum
67
+ require 'digest'
68
+ computed_checksum = Digest::MD5.file path
69
+ computed_checksum == checksum
70
+ end
71
+
72
+ def download(url, outfile)
73
+ logger.bullet "downloading #{url} to #{outfile}"
74
+ http_status = `curl -w "%{http_code}" -f -s -o '#{outfile}' '#{url}' `
75
+ if http_status != "200"
76
+ error "failed to download #{outfile}, http status #{http_status}"
77
+ end
78
+ end
79
+
80
+ end
81
+ end
data/lib/dply/build.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'dply/helper'
2
+ require 'dply/setup'
3
+ require 'dply/linker'
4
+ require 'dply/config_downloader'
5
+ require 'dply/yum'
6
+ require 'dply/tasks'
7
+ require 'forwardable'
8
+
9
+ module Dply
10
+ class Build
11
+
12
+ extend Forwardable
13
+ include Helper
14
+
15
+ def_delegators :config, :target, :branch, :config_download_url,
16
+ :config_map, :dir_map, :config_skip_download
17
+
18
+ attr_reader :config
19
+
20
+ def initialize(config)
21
+ @config = config
22
+ end
23
+
24
+ def run
25
+ setup
26
+ download_configs if config_download_url
27
+ Dir.chdir repo_dir do
28
+ git_step
29
+ git.clean
30
+ link_dirs
31
+ link_config
32
+ yum_install
33
+ clean_build_dir
34
+ link_build_dir
35
+ tasks.build config.task
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def setup
42
+ setup = Setup.new(@config)
43
+ setup.build
44
+ end
45
+
46
+ def download_configs
47
+ files = config_map.values.uniq
48
+ downloader = ConfigDownloader.new(files, config_download_url)
49
+ downloader.skip_download = config_skip_download
50
+ downloader.download_all
51
+ end
52
+
53
+ def git_step
54
+ return unless config.git
55
+ if config.no_pull
56
+ git.checkout branch
57
+ else
58
+ git.pull branch
59
+ end
60
+ end
61
+
62
+ def link_dirs
63
+ return if not dir_map
64
+ logger.bullet "symlinking shared dirs"
65
+ source = "#{config.dir}/shared"
66
+ link source , dir_map
67
+ end
68
+
69
+ def link_config
70
+ return if not config_map
71
+ logger.bullet "symlinking config files"
72
+ source = "#{config.dir}/config"
73
+ link source, config_map
74
+ end
75
+
76
+ def yum_install
77
+ yum = Yum.new("pkgs.yml")
78
+ yum.install
79
+ end
80
+
81
+ def link(source, map)
82
+ dest = repo_dir
83
+ linker = Linker.new(source, dest, map: map)
84
+ linker.create_symlinks
85
+ end
86
+
87
+ def clean_build_dir
88
+ logger.debug "clearing build dir"
89
+ FileUtils.rm_rf build_dir if File.exists? build_dir
90
+ FileUtils.mkdir build_dir
91
+ end
92
+
93
+ def link_build_dir
94
+ build_artifacts = "tmp/build_artifacts"
95
+ FileUtils.rm_rf build_artifacts if File.exists? build_artifacts
96
+ symlink build_dir, build_artifacts
97
+ end
98
+
99
+ def repo_dir
100
+ @repo_dir ||= "#{config.dir}/repo"
101
+ end
102
+
103
+ def build_dir
104
+ @build_dir ||= "#{config.dir}/build"
105
+ end
106
+
107
+ def tasks
108
+ @tasks ||= Tasks.new
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,97 @@
1
+ require 'ostruct'
2
+ require 'dply/helper'
3
+
4
+ module Dply
5
+ class BuildConfig
6
+
7
+ include Helper
8
+
9
+ def initialize(dir: nil, read_config: true)
10
+ @read_config = read_config
11
+ @dir = (dir || Dir.pwd)
12
+ end
13
+
14
+ def config
15
+ return @config if @config
16
+ @config = {
17
+ dir: @dir,
18
+ task: "build:default",
19
+ branch: :master,
20
+ repo: nil,
21
+ git: true,
22
+ env: {},
23
+ config_map: nil,
24
+ dir_map: nil,
25
+ shared_dirs: [],
26
+ config_skip_download: [],
27
+ config_download_url: nil
28
+ }
29
+ read_from_file if @read_config
30
+ return @config
31
+ end
32
+
33
+ def branch(branch)
34
+ set :branch, branch
35
+ end
36
+
37
+ def repo(repo)
38
+ set :repo, repo
39
+ end
40
+
41
+ def config_map(map)
42
+ set :config_map, map
43
+ end
44
+
45
+ def config_skip_download(list)
46
+ set :config_skip_download, list
47
+ end
48
+
49
+ def config_download_url(url)
50
+ set :config_download_url, url
51
+ end
52
+
53
+ def dir_map(map)
54
+ set :dir_map, map
55
+ end
56
+
57
+ def set_env(key, value)
58
+ @config[:env].store key, value
59
+ end
60
+
61
+ def set(key, value)
62
+ @config.store key, value
63
+ end
64
+
65
+ def to_struct
66
+ OpenStruct.new(config)
67
+ end
68
+
69
+ def env(h)
70
+ raise if not h.is_a? Hash
71
+ @config[:env] = h
72
+ @config[:env].each do |k,v|
73
+ ENV[k.to_s] = v.to_s
74
+ end
75
+ end
76
+
77
+ def config_file
78
+ @config_file ||= "#{@dir}/build.rb"
79
+ end
80
+
81
+ def shared_dirs(dirs)
82
+ raise if not dirs.is_a? Array
83
+ @config[:shared_dirs] = dirs
84
+ end
85
+
86
+ def read_from_file
87
+ if not File.readable? config_file
88
+ error "build.rb not found in #{@dir}"
89
+ return
90
+ end
91
+ instance_eval(File.read(config_file), config_file)
92
+ rescue NoMethodError => e
93
+ error "invalid option used in config: #{e.name}"
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,78 @@
1
+ require 'dply/shell'
2
+ module Dply
3
+ class Bundle
4
+
5
+ include Shell
6
+
7
+ def initialize(deployment: true)
8
+ @deployment = deployment
9
+ end
10
+
11
+ def install
12
+ return if not gemfile_exists?
13
+ if @deployment
14
+ install_deployment
15
+ else
16
+ install_global
17
+ end
18
+ end
19
+
20
+ def rake(task, **args)
21
+ if gemfile_exists?
22
+ cmd "bundle exec rake -Nf dply/Rakefile -R dply #{task}", env: env
23
+ else
24
+ cmd "rake -Nf dply/Rakefile -R dply #{task}", env: env
25
+ end
26
+ end
27
+
28
+ def clean
29
+ cmd "bundle clean"
30
+ end
31
+
32
+ private
33
+
34
+ def install_global
35
+ exitstatus = system "bundle check > /dev/null"
36
+ return if exitstatus
37
+ cmd "bundle install"
38
+ end
39
+
40
+ def install_deployment
41
+ if deployment_config_present?
42
+ exitstatus = system "bundle check > /dev/null"
43
+ return if exitstatus
44
+ end
45
+ cmd "bundle install --deployment"
46
+ end
47
+
48
+ def deployment_config_present?
49
+ file = ".bundle/config"
50
+ if not File.readable? file
51
+ return false
52
+ end
53
+ config = YAML.load_file file
54
+ config["BUNDLE_FROZEN"] == "1" && config["BUNDLE_PATH"] == "vendor/bundle"
55
+ rescue
56
+ return false
57
+ end
58
+
59
+ def env
60
+ @env ||= env_from_yml
61
+ end
62
+
63
+ def env_from_yml
64
+ path = "config/env.yml"
65
+ if not File.readable? path
66
+ logger.debug "skipped loading env from #{path}"
67
+ return {}
68
+ end
69
+ require 'yaml'
70
+ YAML.load_file(path)
71
+ end
72
+
73
+ def gemfile_exists?
74
+ File.exists? "Gemfile"
75
+ end
76
+
77
+ end
78
+ end