potamus 1.0.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/bin/potamus +24 -0
- data/cli/build.rb +51 -0
- data/cli/help.rb +21 -0
- data/lib/potamus.rb +2 -0
- data/lib/potamus/config.rb +133 -0
- data/lib/potamus/error.rb +4 -0
- data/lib/potamus/version.rb +5 -0
- metadata +93 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef774d096cdfa91670f06115c3c0233c7ad5296f28d23eee290976f9793d3f63
|
4
|
+
data.tar.gz: dcef9e958a1a7b024e759048589ab28942f3bc34368d5fed483b7bd4a3c92b5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d768688ba3aa593c9a178302c6fcbd541b3c24640748caabe62eb3ef3d403cc8db521d7523c99353730ce3e9b3b23a7120b079f71fbce961ca1e46f7a340b258
|
7
|
+
data.tar.gz: 71217294b89051ae7f80205cb983d1e364491fc1cb8687cf01add351c3ab41e709dfb2a057c6fabf86210bfd14ae120e3450c1eb9b4b890413115a773d856d3f
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/bin/potamus
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
|
+
|
6
|
+
require 'potamus'
|
7
|
+
require 'potamus/error'
|
8
|
+
require 'potamus/version'
|
9
|
+
require 'swamp/cli'
|
10
|
+
|
11
|
+
begin
|
12
|
+
cli = Swamp::CLI.new(:potamus, version: Potamus::VERSION)
|
13
|
+
cli.load_from_directory(File.expand_path('../cli', __dir__))
|
14
|
+
if ARGV.empty?
|
15
|
+
cli.dispatch(['help'])
|
16
|
+
else
|
17
|
+
cli.dispatch(ARGV)
|
18
|
+
end
|
19
|
+
rescue Swamp::Error, Potamus::Error => e
|
20
|
+
warn "\e[31mError: #{e.message}\e[0m"
|
21
|
+
exit 2
|
22
|
+
rescue Interrupt
|
23
|
+
exit 3
|
24
|
+
end
|
data/cli/build.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
command :build do
|
4
|
+
desc 'Build the current version of the app'
|
5
|
+
|
6
|
+
option '-p', '--push', 'Push to registry after build' do |value, options|
|
7
|
+
options[:push] = true
|
8
|
+
end
|
9
|
+
|
10
|
+
option '--test', 'Run in test mode' do |value, options|
|
11
|
+
options[:test] = true
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
action do |context|
|
16
|
+
require 'potamus/config'
|
17
|
+
require 'fileutils'
|
18
|
+
config = Potamus::Config.new(FileUtils.pwd)
|
19
|
+
if context.options[:test]
|
20
|
+
puts "\e[33mRunning in test mode...\e[0m"
|
21
|
+
config.test_mode!
|
22
|
+
end
|
23
|
+
|
24
|
+
unless context.options[:test]
|
25
|
+
unless config.git?
|
26
|
+
raise Error, "This directory containing your PotamusFile doesn't seem to be a git repository"
|
27
|
+
end
|
28
|
+
|
29
|
+
if config.dirty?
|
30
|
+
raise Error, "Working copy is dirty. Commit all changes before building."
|
31
|
+
end
|
32
|
+
|
33
|
+
unless config.pushed?
|
34
|
+
raise Error, "Your local commit does not match the commit on your remote repository. Have you pushed?"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
system(config.build_command) || raise(Error, "Failed to build image")
|
39
|
+
|
40
|
+
config.tag_commands.each do |tag, command|
|
41
|
+
system(command) || raise(Error, "Could not create tag for #{tag}")
|
42
|
+
puts "Created tag for #{config.image_name}:#{tag}"
|
43
|
+
end
|
44
|
+
|
45
|
+
if context.options[:push]
|
46
|
+
config.push_commands.each do |tag, command|
|
47
|
+
system(command) || raise(Error, "Failed to push #{tag} to registry")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/cli/help.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
command :help do
|
4
|
+
desc 'Display this help text'
|
5
|
+
action do |context|
|
6
|
+
puts "\e[35mWelcome to Potatmus v#{Potamus::VERSION}\e[0m"
|
7
|
+
puts 'For documentation see https://adam.ac/potamus.'
|
8
|
+
puts
|
9
|
+
|
10
|
+
puts 'The following commands are supported:'
|
11
|
+
puts
|
12
|
+
context.cli.commands.sort_by { |k, _v| k.to_s }.each do |_, command|
|
13
|
+
if command.description
|
14
|
+
puts " \e[36m#{command.name.to_s.ljust(18, ' ')}\e[0m #{command.description}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
puts 'For details for the options available for each command, use the --help option.'
|
19
|
+
puts "For example 'potamus build --help'."
|
20
|
+
end
|
21
|
+
end
|
data/lib/potamus.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Potamus
|
5
|
+
class Config
|
6
|
+
|
7
|
+
def initialize(root)
|
8
|
+
@root = File.expand_path(root)
|
9
|
+
|
10
|
+
potamus_file_path = File.join(@root, 'PotamusFile')
|
11
|
+
if File.file?(potamus_file_path)
|
12
|
+
@options = YAML.load_file(potamus_file_path)
|
13
|
+
else
|
14
|
+
raise Error, "No Potamus file found at #{potamus_file_path}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def remote_name
|
19
|
+
@options['remote_name'] || 'origin'
|
20
|
+
end
|
21
|
+
|
22
|
+
def branch_for_latest
|
23
|
+
@options['branch_for_latest'] || 'master'
|
24
|
+
end
|
25
|
+
|
26
|
+
def image_name
|
27
|
+
@options['image_name'] || raise(Error, "image_name is required in the PotomusFile")
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_name_with_commit
|
31
|
+
if @test_mode
|
32
|
+
"#{image_name}:test"
|
33
|
+
else
|
34
|
+
"#{image_name}:#{commit}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def git?
|
39
|
+
File.directory?(File.join(@root, '.git'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def dirty?
|
43
|
+
stdout, stderr, status = Open3.capture3("cd #{@root} && git status --short")
|
44
|
+
unless status.success?
|
45
|
+
raise Error, "Could not determine git status using `git status` (#{stderr})"
|
46
|
+
end
|
47
|
+
|
48
|
+
!stdout.strip.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def commit
|
52
|
+
get_commit_ref(branch)
|
53
|
+
end
|
54
|
+
|
55
|
+
def remote_commit
|
56
|
+
get_commit_ref("#{remote_name}/#{branch}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def pushed?
|
60
|
+
commit == remote_commit
|
61
|
+
end
|
62
|
+
|
63
|
+
def branch
|
64
|
+
stdout, stderr, status = Open3.capture3("cd #{@root} && git symbolic-ref HEAD")
|
65
|
+
unless status.success?
|
66
|
+
raise Error, "Could not get current commit (#{stderr})"
|
67
|
+
end
|
68
|
+
|
69
|
+
stdout.strip.sub('refs/heads/', '')
|
70
|
+
end
|
71
|
+
|
72
|
+
def build_command
|
73
|
+
[
|
74
|
+
"cd #{@root}",
|
75
|
+
'&&',
|
76
|
+
'docker', 'build', '.', '-t', image_name_with_commit,
|
77
|
+
'--build-arg', 'commit_ref=' + commit,
|
78
|
+
'--build-arg', 'branch=' + branch
|
79
|
+
].join(' ')
|
80
|
+
end
|
81
|
+
|
82
|
+
def tags
|
83
|
+
return [] if @test_mode
|
84
|
+
|
85
|
+
array = []
|
86
|
+
array << branch
|
87
|
+
array << 'latest' if branch == branch_for_latest
|
88
|
+
array
|
89
|
+
end
|
90
|
+
|
91
|
+
def tag_commands
|
92
|
+
tags.each_with_object({}) do |tag, hash|
|
93
|
+
hash[tag] = tag_command(tag)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def push_commands
|
98
|
+
if @test_mode
|
99
|
+
return { 'test' => push_command('test') }
|
100
|
+
end
|
101
|
+
|
102
|
+
hash = {}
|
103
|
+
hash[commit] = push_command(commit)
|
104
|
+
tags.each do |tag|
|
105
|
+
hash[tag] = push_command(tag)
|
106
|
+
end
|
107
|
+
hash
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_mode!
|
111
|
+
@test_mode = true
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def tag_command(tag)
|
117
|
+
['docker', 'tag', image_name_with_commit, "#{image_name}:#{tag}"].join(' ')
|
118
|
+
end
|
119
|
+
|
120
|
+
def push_command(tag)
|
121
|
+
['docker', 'push', "#{image_name}:#{tag}"].join(' ')
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_commit_ref(branch)
|
125
|
+
stdout, stderr, status = Open3.capture3("cd #{@root} && git log #{branch} -n 1 --pretty='%H'")
|
126
|
+
unless status.success?
|
127
|
+
raise Error, "Could not get commit for #{branch} (#{stderr})"
|
128
|
+
end
|
129
|
+
|
130
|
+
stdout.strip
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: potamus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQDDAJtZTEZ
|
14
|
+
MBcGCgmSJomT8ixkARkWCWFkYW1jb29rZTESMBAGCgmSJomT8ixkARkWAmlvMB4X
|
15
|
+
DTE5MDUxNDEzNTIxM1oXDTIwMDUxMzE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TqmjkTSTfdGvZCM63C6bGdN5CAyMokGOOatGqyCMAONolWnfC
|
31
|
+
gm3t2GWWrxY=
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: swamp-cli
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.0'
|
42
|
+
- - "<"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '1.0'
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: A utility tool for building Docker images
|
56
|
+
email:
|
57
|
+
- me@adamcooke.io
|
58
|
+
executables:
|
59
|
+
- potamus
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- bin/potamus
|
64
|
+
- cli/build.rb
|
65
|
+
- cli/help.rb
|
66
|
+
- lib/potamus.rb
|
67
|
+
- lib/potamus/config.rb
|
68
|
+
- lib/potamus/error.rb
|
69
|
+
- lib/potamus/version.rb
|
70
|
+
homepage: https://github.com/adamcooke/potamus
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.0.3
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A utility tool for building Docker images
|
93
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|