awes_cli 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 77e5eefdce88cb9bf280df1c12b03072a83c0e435383410e1a41b1074caacc94
4
+ data.tar.gz: 63a84f12bdf2874d0fa5a9ab5b8a205a3f04208284d9c918ecea658354526732
5
+ SHA512:
6
+ metadata.gz: 28699c477813def96fef6259122461590ebea3786b9fecfa41561b7cccc8a13263fdb6edb395b8710a79661a71073ccf1484b21414d85da1ffd9fcb34ca731ea
7
+ data.tar.gz: c1b67ca8631e92766835a395e76c50163b7394115cebaf6e89b8a0b1bf4ad971e64e84861a4ff8cc5e3c7c154c594bd0dd3e22567f9e8bc55df3313d140965a8
data/bin/ather ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'build_app_image'
3
+
4
+ build = BuildAppImage.new
5
+ build.main
data/lib/awes_cli.rb ADDED
@@ -0,0 +1,5 @@
1
+ class AwesCli
2
+ def self.hi
3
+ puts "Hello world!"
4
+ end
5
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ class BuildAppImage
5
+ def main
6
+ options = get_options
7
+
8
+ gcr_url = "gcr.io/#{options[:project_id]}/#{options[:app_name]}"
9
+
10
+ image_url = build_image(gcr_url, options)
11
+ end
12
+
13
+ private
14
+ def get_options
15
+ options = {}
16
+
17
+ require_options_keys = [:project_id, :app_name]
18
+
19
+ opt_parser = OptionParser.new do |opts|
20
+ opts.banner = "Usage: ./deploy/build.rb [options]"
21
+
22
+ opts.on("--project-id PROJECT_ID", "GCP project id [required or set env var PROJECT_ID]") do |val|
23
+ options[:project_id] = val
24
+ end
25
+
26
+ opts.on("--app-name APP_NAME", "K8s app name [required or set env var APP_NAME]") do |val|
27
+ options[:app_name] = val
28
+ end
29
+
30
+ opts.on("-h", "--help", "Prints this help") do
31
+ puts opts
32
+ exit
33
+ end
34
+ end
35
+
36
+ opt_parser.parse!
37
+
38
+ require_options_keys.each do |key|
39
+ options[key] ||= ENV[key.to_s.upcase]
40
+ if options[key].nil?
41
+ puts "ERROR: Required option --#{key.to_s.gsub('_', '-')} or set env var #{key.to_s.upcase} \n"
42
+ opt_parser.parse! %w[--help]
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ options
48
+ end
49
+
50
+ def shell_cmd(cmd)
51
+ puts "EXECUTING : \e[32m\e[1m#{cmd}\e[22m\e[0m"
52
+ op = system(cmd)
53
+ if !op
54
+ puts "FAILED : \e[31m\e[1m#{cmd}\e[22m\e[0m"
55
+ exit 1
56
+ end
57
+ puts "SUCCESS : \e[32m\e[1m#{cmd}\e[22m\e[0m"
58
+ end
59
+
60
+ def build_image(gcr_url, options)
61
+ commit_image_tag = ENV['CI_COMMIT_SHORT_SHA'] || `git rev-parse --short HEAD`
62
+ time_image_tag=`TZ=IST-5:30 date +'%Y.%m.%d.%HH.%MM.%SS'`
63
+ image_url = "#{gcr_url}:#{commit_image_tag}".strip
64
+ project_id = options[:project_id]
65
+
66
+ shell_cmd("gcloud builds submit --project #{project_id} --timeout=20m --tag #{image_url} || true")
67
+
68
+ shell_cmd("gcloud container images add-tag --quiet #{image_url} #{gcr_url}:#{time_image_tag}")
69
+
70
+ image_url
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awes_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Umar Siddiqui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ather cli tool
14
+ email: umar.siddiqui@atherenergy.com
15
+ executables:
16
+ - ather
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/ather
21
+ - lib/awes_cli.rb
22
+ - lib/build_app_image.rb
23
+ homepage: https://rubygems.org/gems/awes_cli
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.1.4
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Ather cli tool
46
+ test_files: []