firespring_dev_commands 1.3.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +83 -0
- data/lib/firespring_dev_commands/audit/report/item.rb +33 -0
- data/lib/firespring_dev_commands/audit/report/levels.rb +36 -0
- data/lib/firespring_dev_commands/audit/report.rb +49 -0
- data/lib/firespring_dev_commands/aws/account/info.rb +15 -0
- data/lib/firespring_dev_commands/aws/account.rb +164 -0
- data/lib/firespring_dev_commands/aws/cloudformation/parameters.rb +26 -0
- data/lib/firespring_dev_commands/aws/cloudformation.rb +188 -0
- data/lib/firespring_dev_commands/aws/codepipeline.rb +96 -0
- data/lib/firespring_dev_commands/aws/credentials.rb +136 -0
- data/lib/firespring_dev_commands/aws/login.rb +131 -0
- data/lib/firespring_dev_commands/aws/parameter.rb +32 -0
- data/lib/firespring_dev_commands/aws/profile.rb +55 -0
- data/lib/firespring_dev_commands/aws/s3.rb +42 -0
- data/lib/firespring_dev_commands/aws.rb +10 -0
- data/lib/firespring_dev_commands/boolean.rb +7 -0
- data/lib/firespring_dev_commands/common.rb +112 -0
- data/lib/firespring_dev_commands/daterange.rb +171 -0
- data/lib/firespring_dev_commands/docker/compose.rb +271 -0
- data/lib/firespring_dev_commands/docker/status.rb +38 -0
- data/lib/firespring_dev_commands/docker.rb +276 -0
- data/lib/firespring_dev_commands/dotenv.rb +6 -0
- data/lib/firespring_dev_commands/env.rb +38 -0
- data/lib/firespring_dev_commands/eol/product_version.rb +86 -0
- data/lib/firespring_dev_commands/eol.rb +58 -0
- data/lib/firespring_dev_commands/git/info.rb +13 -0
- data/lib/firespring_dev_commands/git.rb +420 -0
- data/lib/firespring_dev_commands/jira/issue.rb +33 -0
- data/lib/firespring_dev_commands/jira/project.rb +13 -0
- data/lib/firespring_dev_commands/jira/user/type.rb +20 -0
- data/lib/firespring_dev_commands/jira/user.rb +31 -0
- data/lib/firespring_dev_commands/jira.rb +78 -0
- data/lib/firespring_dev_commands/logger.rb +8 -0
- data/lib/firespring_dev_commands/node/audit.rb +39 -0
- data/lib/firespring_dev_commands/node.rb +107 -0
- data/lib/firespring_dev_commands/php/audit.rb +71 -0
- data/lib/firespring_dev_commands/php.rb +109 -0
- data/lib/firespring_dev_commands/rake.rb +24 -0
- data/lib/firespring_dev_commands/ruby/audit.rb +30 -0
- data/lib/firespring_dev_commands/ruby.rb +113 -0
- data/lib/firespring_dev_commands/second.rb +22 -0
- data/lib/firespring_dev_commands/tar/pax_header.rb +49 -0
- data/lib/firespring_dev_commands/tar/type_flag.rb +49 -0
- data/lib/firespring_dev_commands/tar.rb +149 -0
- data/lib/firespring_dev_commands/templates/aws.rb +84 -0
- data/lib/firespring_dev_commands/templates/base_interface.rb +54 -0
- data/lib/firespring_dev_commands/templates/ci.rb +138 -0
- data/lib/firespring_dev_commands/templates/docker/application.rb +177 -0
- data/lib/firespring_dev_commands/templates/docker/default.rb +200 -0
- data/lib/firespring_dev_commands/templates/docker/node/application.rb +145 -0
- data/lib/firespring_dev_commands/templates/docker/php/application.rb +190 -0
- data/lib/firespring_dev_commands/templates/docker/ruby/application.rb +146 -0
- data/lib/firespring_dev_commands/templates/eol.rb +23 -0
- data/lib/firespring_dev_commands/templates/git.rb +147 -0
- data/lib/firespring_dev_commands/version.rb +11 -0
- data/lib/firespring_dev_commands.rb +21 -0
- metadata +436 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
# Class for natively un-tar'ing a file in ruby
|
5
|
+
class Tar
|
6
|
+
attr_accessor :data
|
7
|
+
|
8
|
+
def initialize(data = nil)
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
# Unpack all data in the given tar into the dest_path
|
13
|
+
def unpack(source_path, dest_path)
|
14
|
+
data.rewind
|
15
|
+
extended_headers = nil
|
16
|
+
::Gem::Package::TarReader.new(data).each do |entry|
|
17
|
+
# Using https://github.com/kr/tarutil/blob/master/untar.go as a template
|
18
|
+
# Also check out https://go.googlesource.com/go/+/master/src/archive/tar/reader.go?autodive=0%2F%2F%2F
|
19
|
+
case entry.header.typeflag
|
20
|
+
when TypeFlag::TYPE_DIR
|
21
|
+
merge_pax(entry, extended_headers)
|
22
|
+
dest_name = calc_dest_name(source_path, dest_path, entry)
|
23
|
+
create_directory(entry, dest_name)
|
24
|
+
|
25
|
+
when TypeFlag::TYPE_REG, TypeFlag::TYPE_REG_A
|
26
|
+
merge_pax(entry, extended_headers)
|
27
|
+
dest_name = calc_dest_name(source_path, dest_path, entry)
|
28
|
+
create_file(entry, dest_name)
|
29
|
+
|
30
|
+
when TypeFlag::TYPE_LINK
|
31
|
+
raise 'Unimplemented file type: Link'
|
32
|
+
|
33
|
+
when TypeFlag::TYPE_SYMLINK
|
34
|
+
merge_pax(entry, extended_headers)
|
35
|
+
dest_name = calc_dest_name(source_path, dest_path, entry)
|
36
|
+
create_symlink(entry, dest_name)
|
37
|
+
|
38
|
+
when TypeFlag::TYPE_X_HEADER
|
39
|
+
extended_headers = parse_pax(entry.read)
|
40
|
+
next
|
41
|
+
|
42
|
+
when TypeFlag::TYPE_CONT, TypeFlag::TYPE_X_GLOBAL_HEADER
|
43
|
+
raise 'Unimplemented file type Cont/XGlobalHeader'
|
44
|
+
|
45
|
+
when TypeFlag::TYPE_CHAR, TypeFlag::TYPE_BLOCK, TypeFlag::TYPE_FIFO
|
46
|
+
raise 'Unimplemented file type: Char/Block/Fifo'
|
47
|
+
|
48
|
+
else
|
49
|
+
raise 'Unrecognized file type'
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# If we got here we should be done with any extended headers
|
54
|
+
extended_headers = nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Extract headers and keep track as we extract the files using the given headers
|
59
|
+
private def parse_pax(content)
|
60
|
+
extended_headers = {}
|
61
|
+
key, value = parse_pax_record(content)
|
62
|
+
extended_headers[key] = value
|
63
|
+
extended_headers
|
64
|
+
end
|
65
|
+
|
66
|
+
# Parse the PAX record and return the results
|
67
|
+
private def parse_pax_record(content)
|
68
|
+
# Check https://golang.org/src/archive/tar/strconv.go
|
69
|
+
_size, keyvalue = content&.split(' ', 2)
|
70
|
+
key, value = keyvalue&.split('=', 2)
|
71
|
+
[key, value]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Calculate what the appropriate destination file name is
|
75
|
+
private def calc_dest_name(source_path, dest_path, entry)
|
76
|
+
if File.directory?(dest_path)
|
77
|
+
dest_path = File.dirname(dest_path) if File.basename(source_path) == File.basename(dest_path)
|
78
|
+
|
79
|
+
return "#{dest_path.chomp('/')}/#{entry.full_name}".strip if File.directory?(dest_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
old_name = File.basename(source_path)
|
83
|
+
entry.full_name.sub(/^#{old_name}/, dest_path).to_s.strip
|
84
|
+
end
|
85
|
+
|
86
|
+
# Create the directory and leading directories
|
87
|
+
private def create_directory(_entry, dest_name)
|
88
|
+
FileUtils.mkdir_p(dest_name)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Write the file contents to the destination
|
92
|
+
private def create_file(entry, dest_name)
|
93
|
+
FileUtils.mkdir_p(File.dirname(dest_name))
|
94
|
+
File.write(dest_name, entry.read)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Create a symlink to the destination
|
98
|
+
private def create_symlink(entry, dest_name)
|
99
|
+
FileUtils.cd(File.dirname(dest_name)) do
|
100
|
+
FileUtils.mkdir_p(File.dirname(entry.header.linkname))
|
101
|
+
FileUtils.symlink(entry.header.linkname, File.basename(dest_name), force: true)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Merge pax records
|
106
|
+
private def merge_pax(entry, extended_headers)
|
107
|
+
# Reference: https://go.googlesource.com/go/+/master/src/archive/tar/reader.go?autodive=0%2F%2F%2F
|
108
|
+
return unless extended_headers
|
109
|
+
|
110
|
+
extended_headers.each do |k, v|
|
111
|
+
case k
|
112
|
+
when PaxHeader::PAX_PATH
|
113
|
+
entry.header.instance_variable_set(:@name, v)
|
114
|
+
|
115
|
+
when PaxHeader::PAX_LINKPATH
|
116
|
+
entry.header.instance_variable_set(:@linkname, v)
|
117
|
+
|
118
|
+
when PaxHeader::PAX_UNAME
|
119
|
+
entry.header.instance_variable_set(:@uname, v)
|
120
|
+
|
121
|
+
when PaxHeader::PAX_GNAME
|
122
|
+
entry.header.instance_variable_set(:@gname, v)
|
123
|
+
|
124
|
+
when PaxHeader::PAX_UID
|
125
|
+
entry.header.instance_variable_set(:@uid, v)
|
126
|
+
|
127
|
+
when PaxHeader::PAX_GID
|
128
|
+
entry.header.instance_variable_set(:@gid, v)
|
129
|
+
|
130
|
+
when PaxHeader::PAX_ATIME
|
131
|
+
entry.header.instance_variable_set(:@atime, v)
|
132
|
+
|
133
|
+
when PaxHeader::PAX_MTIME
|
134
|
+
entry.header.instance_variable_set(:@mtime, v)
|
135
|
+
|
136
|
+
when PaxHeader::PAX_CTIME
|
137
|
+
entry.header.instance_variable_set(:@ctime, v)
|
138
|
+
|
139
|
+
when PaxHeader::PAX_SIZE
|
140
|
+
entry.header.instance_variable_set(:@size, v)
|
141
|
+
|
142
|
+
else
|
143
|
+
raise "unsupported header #{k}"
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative './base_interface'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
module Template
|
5
|
+
# Class contains rake templates for managing your AWS settings and logging in
|
6
|
+
class Aws < Dev::Template::BaseInterface
|
7
|
+
# Create the rake task which ensures active credentials are present
|
8
|
+
def create_ensure_credentials_task!
|
9
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
10
|
+
exclude = @exclude
|
11
|
+
|
12
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
13
|
+
return if exclude.include?(:ensure_aws_credentials)
|
14
|
+
|
15
|
+
task ensure_aws_credentials: %w(init) do
|
16
|
+
raise 'AWS Credentials not found / expired' unless Dev::Aws::Credentials.new.active?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Create the rake task for the aws profile method
|
22
|
+
def create_profile_task!
|
23
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
24
|
+
exclude = @exclude
|
25
|
+
|
26
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
27
|
+
namespace :aws do
|
28
|
+
return if exclude.include?(:profile)
|
29
|
+
|
30
|
+
desc 'Show the current profile/aws account you are configured to use'
|
31
|
+
task profile: %w(init) do
|
32
|
+
Dev::Aws::Profile.new.info
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# rubocop:disable Metrics/MethodLength
|
39
|
+
# Create the rake task for the aws credentials setup and login method
|
40
|
+
def create_login_task!
|
41
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
42
|
+
exclude = @exclude
|
43
|
+
|
44
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
45
|
+
namespace :aws do
|
46
|
+
return if exclude.include?(:login)
|
47
|
+
|
48
|
+
namespace :configure do
|
49
|
+
desc 'Configure the default AWS login settings'
|
50
|
+
task default: %w(init default:credentials default:config) do
|
51
|
+
puts
|
52
|
+
end
|
53
|
+
|
54
|
+
namespace :default do
|
55
|
+
desc 'Configure the default AWS login credentials' \
|
56
|
+
"\n\t(primarily used for rotating access keys)"
|
57
|
+
task credentials: %w(init) do
|
58
|
+
Dev::Aws::Credentials.new.base_setup!
|
59
|
+
end
|
60
|
+
|
61
|
+
task config: %w(init) do
|
62
|
+
Dev::Aws::Account.new.base_setup!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Dev::Aws::Account.new.children.each do |account|
|
67
|
+
desc "Configure the #{account.name} account login settings"
|
68
|
+
task account.id => %w(init) do
|
69
|
+
Dev::Aws::Account.new.setup!(account.id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Select the account you wish to log in to'
|
75
|
+
task login: %w(init) do
|
76
|
+
Dev::Aws::Login.new.login!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# rubocop:enable Metrics/MethodLength
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rake/dsl_definition'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
# Module containing all available rake template
|
5
|
+
module Template
|
6
|
+
# Base interface template takes a custom arg for the initializer and requires the user to implement the create_tasks! method
|
7
|
+
class BaseInterface
|
8
|
+
include ::Rake::DSL
|
9
|
+
|
10
|
+
def initialize(exclude: [])
|
11
|
+
@exclude = Array(exclude).map(&:to_sym)
|
12
|
+
create_tasks!
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method executes all instance methods which match "create_.*_task!"
|
16
|
+
# This way a user can easily add new methods to the default template simply by defining new create methods
|
17
|
+
# on the class which follow the naming convention
|
18
|
+
def create_tasks!
|
19
|
+
self.class.instance_methods(false).sort.each do |method|
|
20
|
+
next unless /create_.*_task!/.match?(method)
|
21
|
+
|
22
|
+
send(method)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Dev
|
30
|
+
module Template
|
31
|
+
# Base interface template customized for applications which require a name to be passed in to the constructor
|
32
|
+
class ApplicationInterface < Dev::Template::BaseInterface
|
33
|
+
include ::Rake::DSL
|
34
|
+
|
35
|
+
def initialize(name, exclude: [])
|
36
|
+
@name = name
|
37
|
+
super(exclude: exclude)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create the base init command
|
44
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
45
|
+
task :init do
|
46
|
+
LOG.debug 'In base init'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
51
|
+
task init_docker: %w(init) do
|
52
|
+
LOG.debug 'In base init docker'
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require_relative './base_interface'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
module Template
|
5
|
+
class Aws
|
6
|
+
# Class contains rake templates for managing your ci/cd resources
|
7
|
+
class Ci < Dev::Template::BaseInterface
|
8
|
+
# Base interface template customized for codepipelines which require a pipeline pattern which will match the pipeline name
|
9
|
+
def initialize(cloudformation, exclude: [])
|
10
|
+
@cloudformations = Array(cloudformation).sort_by(&:name)
|
11
|
+
raise 'must specify an arry of cloudformation objects' unless @cloudformations.all?(Dev::Aws::Cloudformation)
|
12
|
+
|
13
|
+
super(exclude: exclude)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create the rake task for creating the codepipeline
|
17
|
+
def create_create_task!
|
18
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
19
|
+
exclude = @exclude
|
20
|
+
cloudformations = @cloudformations
|
21
|
+
return if exclude.include?(:status)
|
22
|
+
|
23
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
24
|
+
namespace :ci do
|
25
|
+
desc 'Create the ci cloudformation stack in aws'
|
26
|
+
task create: %w(init ensure_aws_credentials) do
|
27
|
+
LOG.info
|
28
|
+
next if cloudformations.empty?
|
29
|
+
|
30
|
+
# Start create on all stacks without waiting so they are created in parallel
|
31
|
+
cloudformations.each do |cloudformation|
|
32
|
+
cloudformation.create(should_wait: false)
|
33
|
+
end
|
34
|
+
LOG.info 'Waiting for all stacks to finish create'
|
35
|
+
|
36
|
+
# Wait until all stacks have finished creating
|
37
|
+
cloudformations.each(&:create_wait)
|
38
|
+
LOG.info "Stack create finished at #{Time.now.to_s.light_yellow}"
|
39
|
+
LOG.info
|
40
|
+
|
41
|
+
raise 'Some stacks failed to create' if cloudformations.any?(&:failed?)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Create the rake task for updating the codepipeline
|
48
|
+
def create_update_task!
|
49
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
50
|
+
exclude = @exclude
|
51
|
+
cloudformations = @cloudformations
|
52
|
+
return if exclude.include?(:status)
|
53
|
+
|
54
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
55
|
+
namespace :ci do
|
56
|
+
desc 'Update the ci cloudformation stack in aws'
|
57
|
+
task update: %w(init ensure_aws_credentials) do
|
58
|
+
LOG.info
|
59
|
+
next if cloudformations.empty?
|
60
|
+
|
61
|
+
# Start update on all stacks without waiting so they are updated in parallel
|
62
|
+
cloudformations.each do |cloudformation|
|
63
|
+
cloudformation.update(should_wait: false)
|
64
|
+
end
|
65
|
+
LOG.info 'Waiting for all stacks to finish update'
|
66
|
+
|
67
|
+
# Wait until all stacks have finished creating
|
68
|
+
cloudformations.each(&:update_wait)
|
69
|
+
LOG.info "Stack update finished at #{Time.now.to_s.light_yellow}"
|
70
|
+
LOG.info
|
71
|
+
|
72
|
+
raise 'Some stacks failed to update' if cloudformations.any?(&:failed?)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create the rake task for deleting the codepipeline
|
79
|
+
def create_delete_task!
|
80
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
81
|
+
exclude = @exclude
|
82
|
+
cloudformations = @cloudformations
|
83
|
+
return if exclude.include?(:status)
|
84
|
+
|
85
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
86
|
+
namespace :ci do
|
87
|
+
desc 'Delete the ci cloudformation stack in aws'
|
88
|
+
task delete: %w(init ensure_aws_credentials) do
|
89
|
+
LOG.info
|
90
|
+
next if cloudformations.empty?
|
91
|
+
|
92
|
+
# Start delete on all stacks without waiting so they are deleted in parallel
|
93
|
+
cloudformations.each do |cloudformation|
|
94
|
+
cloudformation.delete(should_wait: false)
|
95
|
+
end
|
96
|
+
LOG.info 'Waiting for all stacks to finish delete'
|
97
|
+
|
98
|
+
# Wait until all stacks have finished creating
|
99
|
+
cloudformations.each(&:delete_wait)
|
100
|
+
LOG.info "Stack delete finished at #{Time.now.to_s.light_yellow}"
|
101
|
+
LOG.info
|
102
|
+
|
103
|
+
raise 'Some stacks failed to update' if cloudformations.any?(&:failed?)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Create the rake task for the aws codepipeline status method
|
110
|
+
def create_status_task!
|
111
|
+
# Have to set a local variable to be accessible inside of the instance_eval block
|
112
|
+
exclude = @exclude
|
113
|
+
cloudformations = @cloudformations
|
114
|
+
return if exclude.include?(:status)
|
115
|
+
|
116
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
117
|
+
namespace :ci do
|
118
|
+
desc 'Show the current status of the pipelines associated with your branch'
|
119
|
+
task status: %w(init ensure_aws_credentials) do
|
120
|
+
LOG.info
|
121
|
+
next if cloudformations.empty?
|
122
|
+
|
123
|
+
pattern = /#{cloudformations.map(&:name).join('|')}/
|
124
|
+
pipelines = Dev::Aws::CodePipeline.new.pipelines(pattern).sort_by(&:name)
|
125
|
+
LOG.info "No pipelines found matching #{pattern.source.gsub('|', ' OR ')}" if pipelines.empty?
|
126
|
+
pipelines.each do |pipeline|
|
127
|
+
Dev::Aws::CodePipeline.new.status(pipeline.name)
|
128
|
+
LOG.info
|
129
|
+
end
|
130
|
+
LOG.info
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require_relative '../base_interface'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
module Template
|
5
|
+
module Docker
|
6
|
+
# Contains all default rake tasks for a docker application
|
7
|
+
class Application < Dev::Template::ApplicationInterface
|
8
|
+
# Create the rake task which runs a docker compose build for the application name
|
9
|
+
def create_build_task!
|
10
|
+
application = @name
|
11
|
+
exclude = @exclude
|
12
|
+
|
13
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
14
|
+
namespace application do
|
15
|
+
return if exclude.include?(:build)
|
16
|
+
|
17
|
+
desc "Builds the #{application} container"
|
18
|
+
task build: %w(init_docker) do
|
19
|
+
LOG.debug "In #{application} build"
|
20
|
+
Dev::Docker::Compose.new(services: [application]).build
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create the rake task which runs a docker compose up for the application name
|
27
|
+
def create_up_task!
|
28
|
+
application = @name
|
29
|
+
exclude = @exclude
|
30
|
+
|
31
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
32
|
+
namespace application do
|
33
|
+
return if exclude.include?(:up)
|
34
|
+
|
35
|
+
desc "Starts up the #{application} container and it's dependencies"
|
36
|
+
task up: %w(init_docker) do
|
37
|
+
LOG.debug "In #{application} up"
|
38
|
+
Dev::Docker::Compose.new(services: [application]).up
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create the rake task which runs a docker compose up --no-deps for the application name
|
45
|
+
def create_up_no_deps_task!
|
46
|
+
application = @name
|
47
|
+
exclude = @exclude
|
48
|
+
|
49
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
50
|
+
namespace application do
|
51
|
+
return if exclude.include?(:up_no_deps)
|
52
|
+
|
53
|
+
desc "Starts up the #{application} container but no dependencies"
|
54
|
+
task up_no_deps: %w(init_docker) do
|
55
|
+
LOG.debug "In #{application} up_no_deps"
|
56
|
+
Dev::Docker::Compose.new(services: [application], options: ['--no-deps']).up
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Create the rake task which runs a docker compose exec bash for the application name
|
63
|
+
def create_sh_task!
|
64
|
+
application = @name
|
65
|
+
exclude = @exclude
|
66
|
+
|
67
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
68
|
+
namespace application do
|
69
|
+
return if exclude.include?(:sh)
|
70
|
+
|
71
|
+
desc "Open a shell into a running #{application} container"
|
72
|
+
task sh: %W(init_docker #{application}:up) do
|
73
|
+
Dev::Docker::Compose.new(services: [application]).sh
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Create the rake task which runs a docker compose logs for the application name
|
80
|
+
def create_logs_task!
|
81
|
+
application = @name
|
82
|
+
exclude = @exclude
|
83
|
+
|
84
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
85
|
+
namespace application do
|
86
|
+
return if exclude.include?(:logs)
|
87
|
+
|
88
|
+
desc "Shows logs for the #{application} container"
|
89
|
+
task logs: %w(init_docker) do
|
90
|
+
LOG.debug "In #{application} logs"
|
91
|
+
Dev::Docker::Compose.new(services: [application]).logs
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Create the rake task which runs a docker compose down for the application name
|
98
|
+
def create_down_task!
|
99
|
+
application = @name
|
100
|
+
exclude = @exclude
|
101
|
+
|
102
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
103
|
+
namespace application do
|
104
|
+
return if exclude.include?(:down)
|
105
|
+
|
106
|
+
desc "Stops the #{application} container"
|
107
|
+
task down: %w(init_docker) do
|
108
|
+
LOG.debug "In #{application} down"
|
109
|
+
|
110
|
+
# docker-copmose down shuts down everything (you can't only specify a single service)
|
111
|
+
# therefore, stop the service manually and prune ununsed resources (just like a down would)
|
112
|
+
Dev::Docker::Compose.new(services: [application]).stop
|
113
|
+
Dev::Docker.new.prune_containers
|
114
|
+
Dev::Docker.new.prune_networks
|
115
|
+
Dev::Docker.new.prune_volumes if ENV['REMOVE_VOLUMES'].to_s.strip == 'true'
|
116
|
+
Dev::Docker.new.prune_images
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Create the rake task which stops, cleans, and starts the application
|
123
|
+
def create_reload_task!
|
124
|
+
application = @name
|
125
|
+
exclude = @exclude
|
126
|
+
|
127
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
128
|
+
namespace application do
|
129
|
+
return if exclude.include?(:reload)
|
130
|
+
|
131
|
+
desc "Reloads the #{application} container"
|
132
|
+
task reload: %w(init_docker down up) do
|
133
|
+
# Run the down and then the up commands
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Create the rake task which runs a docker compose push for the application name
|
140
|
+
def create_push_task!
|
141
|
+
application = @name
|
142
|
+
exclude = @exclude
|
143
|
+
|
144
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
145
|
+
namespace application do
|
146
|
+
return if exclude.include?(:push)
|
147
|
+
|
148
|
+
desc "Push the #{application} container to the configured image repository"
|
149
|
+
task push: %w(init_docker) do
|
150
|
+
LOG.debug "In #{application} push"
|
151
|
+
Dev::Docker::Compose.new(services: [application]).push
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Create the rake task which runs a docker compose pull for the application name
|
158
|
+
def create_pull_task!
|
159
|
+
application = @name
|
160
|
+
exclude = @exclude
|
161
|
+
|
162
|
+
DEV_COMMANDS_TOP_LEVEL.instance_eval do
|
163
|
+
namespace application do
|
164
|
+
return if exclude.include?(:pull)
|
165
|
+
|
166
|
+
desc "Pull the #{application} container from the configured image repository"
|
167
|
+
task pull: %w(init_docker) do
|
168
|
+
LOG.debug "In #{application} pull"
|
169
|
+
Dev::Docker::Compose.new(services: [application]).pull
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|