bmc-tools 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -0
  3. data/Rakefile +18 -0
  4. data/bin/dockerize +109 -0
  5. data/bmc-tools.gemspec +28 -0
  6. metadata +90 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 508f144fc6be415e5303f6be7eee4a8edd5a7582
4
+ data.tar.gz: 028d6116c92f181dda903b6d373111eb69787454
5
+ SHA512:
6
+ metadata.gz: 62b277ae93a897f74c35ff9298ef7fdb07a196505030091d0d1b2abf880f890d2891d9450cbe577eb7ed4075b1edfb3f534d10caa057720163cddd221213e29b
7
+ data.tar.gz: 10bc2e6316e762131c2375cc96c4b5c476062c22dd4dae51104d1618aefe98b555221907edbff70dad6b800c59a3dd37890abd29d63a77c5d82de7d75aaa989d
@@ -0,0 +1,2 @@
1
+ bmc-tools
2
+ ====================================================================================
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+ require "rubygems"
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ task.fail_on_error = false
11
+ end
12
+
13
+ # Load my own tasks
14
+ Dir.glob('lib/tasks/*.rake').each { |r| import r }
15
+
16
+ # Run specs by default
17
+ desc "Run all tests"
18
+ task default: [:spec, :rubocop]
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ DOCKER_REPO = "bmconseil/dummy"
4
+
5
+ # Try to load external libs, helpers and constants
6
+ begin
7
+ require "rubygems"
8
+ require "optparse"
9
+ require 'tempfile'
10
+ rescue LoadError => e
11
+ raise "EXITING: some basic libs were not found (#{e.message})"
12
+ end
13
+
14
+
15
+ # Some helpers
16
+ def git_check_tag tag
17
+ system("git tag -l #{tag}")
18
+ end
19
+ def run_cmd command, title
20
+ puts "* #{title}"
21
+ puts command
22
+ system command
23
+ puts
24
+ end
25
+
26
+
27
+ # Handle configuration
28
+ begin
29
+ # Defaults
30
+ opt_tag = nil
31
+ opt_latest = false
32
+ opt_push = false
33
+
34
+ # Parse options and check compliance
35
+ parser = OptionParser.new do |opts|
36
+ opts.banner = "Usage: #{File.basename $PROGRAM_NAME} [options] start|stop"
37
+ opts.on("-t", "--tag VERSION") { |value| opt_tag = value.to_s }
38
+ opts.on("-l", "--latest", "Tag build with :latest") { |value| opt_latest = true }
39
+ opts.on("-p", "--push", "Push the build(s)") { |value| opt_push = true }
40
+ opts.on_tail("-h", "--help", "Show this message") do
41
+ puts opts
42
+ exit
43
+ end
44
+
45
+ end
46
+ parser.order!(ARGV)
47
+
48
+ rescue OptionParser::InvalidOption => e
49
+ abort "EXITING: InvalidOption: #{e.message}"
50
+ rescue StandardError => e
51
+ abort "EXITING: StandardError: #{e.message}"
52
+ end
53
+
54
+
55
+ # Check context
56
+ unless opt_tag
57
+ puts "EXITING: params: missing tag"
58
+ exit 1
59
+ end
60
+
61
+ # Check tag in git
62
+ unless git_check_tag(opt_tag)
63
+ puts "EXITING: tag [#{opt_tag}] not found in git"
64
+ exit 1
65
+ end
66
+
67
+ # Prepare some context vars
68
+ temp_archive = "dockerize-archive-#{opt_tag}.tar"
69
+ release_name = "#{DOCKER_REPO}:#{opt_tag}"
70
+ release_latest = "#{DOCKER_REPO}:latest"
71
+
72
+ # Prepare commands
73
+ cmd_build = "docker build -f Dockerfile --build-arg CODE_ARCHIVE=\"#{temp_archive}\" . -t \"#{release_name}\""
74
+ cmd_tag = "docker tag \"#{release_name}\" \"#{release_latest}\""
75
+ opt_push = "docker push \"#{release_name}\""
76
+ opt_push_latest = "docker push \"#{release_latest}\""
77
+
78
+ # Config summary
79
+ puts "--- DOCKERIZE CONFIG"
80
+ puts "Git tag #{opt_tag}"
81
+ puts "Use latest tag #{opt_latest}"
82
+ puts "Code archive #{temp_archive}"
83
+ puts
84
+
85
+
86
+ # Checkout tag code in temp archive
87
+ run_cmd(
88
+ "Creating code archive",
89
+ "git archive --format=tar -o \"#{temp_archive}\" --prefix=/ #{opt_tag}"
90
+ )
91
+ archive_size = File.size(temp_archive)
92
+ puts "> archive size: #{archive_size}"
93
+
94
+ # Build docker image from that archive
95
+ run_cmd cmd_build, "Building docker image"
96
+
97
+ # Tag latest if required
98
+ if opt_latest
99
+ run_cmd cmd_tag, "Updating tag [#{release_latest}] to point to [#{release_name}]"
100
+ opt_push += " && #{opt_push_latest}" if opt_latest
101
+ end
102
+
103
+ # Push releases
104
+ run_cmd opt_push, "Pushing releases" if opt_push
105
+
106
+
107
+ # $?.exitstatus
108
+ puts "* We're all set !"
109
+ exit 0
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ # Project version
4
+ spec.version = "0.1"
5
+
6
+ # Project description
7
+ spec.name = "bmc-tools"
8
+ spec.authors = ["Bruno MEDICI"]
9
+ spec.email = "opensource@bmconseil.com"
10
+ spec.description = ""
11
+ spec.summary = spec.description
12
+ spec.homepage = "http://github.com/bmedici/bmc-tools"
13
+ spec.licenses = ["MIT"]
14
+ spec.date = Time.now.strftime("%Y-%m-%d")
15
+
16
+ # List files and executables
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 2.2"
21
+
22
+ # Development dependencies
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ # Runtime dependencies
28
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bmc-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Bruno MEDICI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email: opensource@bmconseil.com
57
+ executables:
58
+ - dockerize
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - Rakefile
64
+ - bin/dockerize
65
+ - bmc-tools.gemspec
66
+ homepage: http://github.com/bmedici/bmc-tools
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '2.2'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: ''
90
+ test_files: []