bauble_core 0.4.0 → 0.5.1

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
  SHA256:
3
- metadata.gz: 55cf8f90f94a4eb4819828fc2614ebcfa0d0871f3a183bce61f140fecd05b293
4
- data.tar.gz: cf2fe310bafd807a51d70e8d4aae7981da0a269b342541bf0cbf876b49d24f93
3
+ metadata.gz: 4038e4ddfedbab693fec9a16352ab5b3d3bc4e82571f2347d0bb952f6119b9a2
4
+ data.tar.gz: 9e82f18102c93f287d3bd9426545228593ccb6a60ccf9245825705a179054a94
5
5
  SHA512:
6
- metadata.gz: b5048dc7d83fa734f9444bbe4a72a4dd329a374afd054ce66f1e0fbd087854c2a235b2e80799bd6f4a6a07fc9d5c792d18ccc6171d4db7cc0f0a43a0a54df4f7
7
- data.tar.gz: 3f1b8a7dfbbdabc23c7f012346015ae7467879d4af5ccde3f177285544c7e0d59754e36780ca27d6c6ec46dc101b6119fc4d9c83d6d4b8ec81a12e1d0c5bf2ed
6
+ metadata.gz: abe120d39d730f66ff2743d11860c5e9533409df7925a1bb4a9520566a74d3d04c88d02fadc04df27d5276ee30b620c611dd1e1d8b3fe16df37acdafd5d68bf3
7
+ data.tar.gz: 0c9f648605c6e0787fe4c2969b318b179c3c8395e54745ca43e8c15f7d5e84ed174f87daccfacc7c8d704c6b6fd4447d609533916295ce61dc26ba6361d633e4
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'httparty', '~> 0.22.0'
6
+
7
+ group :development do
8
+ gem 'bauble_core', '~> 0.4.0'
9
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ bauble_core (0.4.0)
5
+ colorize (~> 1.1.0)
6
+ thor (~> 1.3.2)
7
+ bigdecimal (3.1.8)
8
+ colorize (1.1.0)
9
+ csv (3.3.0)
10
+ httparty (0.22.0)
11
+ csv
12
+ mini_mime (>= 1.0.0)
13
+ multi_xml (>= 0.5.2)
14
+ mini_mime (1.1.5)
15
+ multi_xml (0.7.1)
16
+ bigdecimal (~> 3.1)
17
+ thor (1.3.2)
18
+
19
+ PLATFORMS
20
+ arm64-darwin-24
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bauble_core (~> 0.4.0)
25
+ httparty (~> 0.22.0)
26
+
27
+ BUNDLED WITH
28
+ 2.5.22
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ def handler(event:, context:) # rubocop:disable Lint/UnusedMethodArgument
6
+ response = HTTParty.get('https://api.chucknorris.io/jokes/random')
7
+ joke = JSON.parse(response.body)['value']
8
+ puts joke
9
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "entrypoint": "infra/app.rb"
3
+ }
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bauble'
4
+
5
+ app = Bauble::Application.new(
6
+ name: 'basic-bauble-app',
7
+ code_dir: 'app'
8
+ )
9
+
10
+ role = Bauble::Resources::LambdaRole.new(
11
+ app,
12
+ name: 'lambda-role'
13
+ )
14
+
15
+ Bauble::Resources::RubyFunction.new(
16
+ app,
17
+ role: role,
18
+ name: 'hello-world',
19
+ handler: 'app/hello_world.handler'
20
+ )
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'httparty', '~> 0.22.0'
6
+ gem 'pry', '~> 0.14.2'
7
+
8
+ group :development do
9
+ if ENV['BAUBLE_DEV_GEM_PATH']
10
+ gem 'bauble_core', path: ENV['BAUBLE_DEV_GEM_PATH']
11
+ else
12
+ gem 'bauble_core', path: '/var/task/bauble_core'
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: /Users/james/code/bauble
3
+ specs:
4
+ bauble_core (0.4.0)
5
+ colorize (~> 1.1.0)
6
+ thor (~> 1.3.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ bigdecimal (3.1.8)
12
+ coderay (1.1.3)
13
+ colorize (1.1.0)
14
+ csv (3.3.0)
15
+ httparty (0.22.0)
16
+ csv
17
+ mini_mime (>= 1.0.0)
18
+ multi_xml (>= 0.5.2)
19
+ method_source (1.1.0)
20
+ mini_mime (1.1.5)
21
+ multi_xml (0.7.1)
22
+ bigdecimal (~> 3.1)
23
+ pry (0.14.2)
24
+ coderay (~> 1.1)
25
+ method_source (~> 1.0)
26
+ thor (1.3.2)
27
+
28
+ PLATFORMS
29
+ arm64-darwin-24
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bauble_core!
34
+ httparty (~> 0.22.0)
35
+ pry (~> 0.14.2)
36
+
37
+ BUNDLED WITH
38
+ 2.5.22
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ def world(event:, context:) # rubocop:disable Lint/UnusedMethodArgument
4
+ puts 'hello world'
5
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "entrypoint": "infra/app.rb"
3
+ }
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bauble'
4
+ require 'pry'
5
+
6
+ Bauble::Application.new(
7
+ name: 'MyApp',
8
+ code_dir: 'app'
9
+ )
@@ -21,15 +21,17 @@ module Bauble
21
21
  :shared_code_dir,
22
22
  :shared_code_hash,
23
23
  :gem_layer_hash,
24
- :skip_gem_layer
24
+ :skip_gem_layer,
25
+ :s3_backend
25
26
  )
26
27
 
27
- def initialize(name:, code_dir:, stacks: [], skip_gem_layer: false)
28
+ def initialize(name:, code_dir:, stacks: [], skip_gem_layer: false, s3_backend: nil)
28
29
  # passed arguments
29
30
  @name = name
30
31
  @shared_code_dir = code_dir
31
32
  @stacks = []
32
33
  @skip_gem_layer = skip_gem_layer
34
+ @s3_backend = s3_backend
33
35
 
34
36
  # init others
35
37
  @resources = []
@@ -106,11 +108,13 @@ module Bauble
106
108
  end
107
109
 
108
110
  def base_template
109
- {
111
+ base_hash = {
110
112
  'name' => @name,
111
- 'runtime' => 'yaml',
112
- 'resources' => {}
113
+ 'runtime' => 'yaml'
113
114
  }
115
+ base_hash['backend'] = { 'url' => @s3_backend } if @s3_backend
116
+ base_hash['resources'] = {}
117
+ base_hash
114
118
  end
115
119
 
116
120
  def hash_of_dir(directory)
@@ -6,8 +6,10 @@ require 'json'
6
6
  require_relative 'commands/preview'
7
7
  require_relative 'commands/up'
8
8
  require_relative 'commands/destroy'
9
+ require_relative 'commands/new'
9
10
  require_relative 'pulumi'
10
11
  require_relative '../application'
12
+ require_relative 'logger'
11
13
 
12
14
  module Bauble
13
15
  module Cli
@@ -16,22 +18,28 @@ module Bauble
16
18
  include Commands::Preview
17
19
  include Commands::Up
18
20
  include Commands::Destroy
21
+ include Commands::New
19
22
 
20
23
  attr_accessor :app, :config
21
24
 
22
- def initialize(*args)
23
- super
24
- require_entrypoint
25
- @app = ObjectSpace.each_object(Bauble::Application).first
26
- raise 'No App instance found' unless @app
27
-
28
- build_config
29
- end
30
-
31
25
  def self.exit_on_failure?
32
26
  true
33
27
  end
34
28
 
29
+ no_commands do
30
+ def setup_app
31
+ require_entrypoint
32
+ @app = ObjectSpace.each_object(Bauble::Application).first
33
+
34
+ unless @app
35
+ Logger.error 'No Bauble::Application object found'
36
+ exit 1
37
+ end
38
+
39
+ build_config
40
+ end
41
+ end
42
+
35
43
  private
36
44
 
37
45
  def pulumi
@@ -42,6 +50,7 @@ module Bauble
42
50
  @config = Config.configure do |c|
43
51
  c.app_name = @app.name
44
52
  c.skip_gem_layer = @app.skip_gem_layer
53
+ c.s3_backend = @app.s3_backend
45
54
  end
46
55
  @app.config = @config
47
56
  end
@@ -57,10 +66,18 @@ module Bauble
57
66
  end
58
67
 
59
68
  def bauble_json
69
+ unless File.exist?('bauble.json')
70
+ Logger.error 'No bauble.json file found'
71
+ exit 1
72
+ end
60
73
  @bauble_json ||= JSON.parse(File.read('bauble.json'))
61
74
  end
62
75
 
63
76
  def require_entrypoint
77
+ unless bauble_json['entrypoint']
78
+ Logger.error 'No entrypoint found in bauble.json'
79
+ exit 1
80
+ end
64
81
  Kernel.require "#{Dir.pwd}/#{bauble_json['entrypoint']}"
65
82
  end
66
83
  end
@@ -30,7 +30,6 @@ module Bauble
30
30
  $CHILD_STATUS.success?
31
31
  end
32
32
 
33
- # TODO: Remove the need for this to install things from the sub dir
34
33
  def docker_build_gems_command(gem_path)
35
34
  command = DockerCommandBuilder
36
35
  .new
@@ -19,6 +19,8 @@ module Bauble
19
19
  Logger.logo
20
20
  Logger.nl
21
21
 
22
+ setup_app
23
+
22
24
  # check for any stacks
23
25
  raise 'No stacks found' if @app.stacks.empty?
24
26
 
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'pry'
5
+ require 'thor'
6
+ require_relative '../pulumi'
7
+ require_relative '../logger'
8
+
9
+ module Bauble
10
+ module Cli
11
+ module Commands
12
+ # Up command
13
+ module New
14
+ class << self
15
+ def included(thor) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
16
+ thor.class_eval do # rubocop:disable Metrics/BlockLength
17
+ desc 'new [DESTINATION]', 'Scaffolds a new app from a GitHub repository'
18
+ map 'new' => :new_app
19
+ option :template, type: :string, default: 'basic-app',
20
+ desc: 'The template to use for the new app'
21
+
22
+ def new_app(destination)
23
+ github_repo = 'jamesh38/bauble'
24
+ specific_dir = "examples/#{options[:template]}"
25
+ dest_dir = destination ? "#{Dir.pwd}/#{destination}" : Dir.pwd
26
+ begin
27
+ uri = URI("https://api.github.com/repos/#{github_repo}/contents/#{specific_dir}")
28
+ fetch_and_write_files(uri, dest_dir, specific_dir)
29
+ rescue StandardError => e
30
+ Logger.error e.message
31
+ return
32
+ end
33
+ Logger.block_log 'New app created successfully'
34
+ end
35
+
36
+ no_commands do
37
+ def fetch_and_write_files(uri, destination, specific_dir) # rubocop:disable Metrics
38
+ response = Net::HTTP.get_response(uri)
39
+
40
+ if response.is_a?(Net::HTTPSuccess)
41
+ files = JSON.parse(response.body)
42
+
43
+ files.each do |file|
44
+ if file['type'] == 'file'
45
+ next if file['name'] == 'Gemfile.lock'
46
+
47
+ file_uri = URI(file['download_url'])
48
+ file_content = Net::HTTP.get(file_uri)
49
+ target_path = File.join(destination, file['path'].sub(specific_dir, ''))
50
+ FileUtils.mkdir_p(File.dirname(target_path))
51
+ File.write(target_path, file_content)
52
+ elsif file['type'] == 'dir'
53
+ new_uri = URI(file['url'])
54
+ fetch_and_write_files(new_uri, destination, specific_dir)
55
+ end
56
+ end
57
+ elsif response.is_a?(Net::HTTPNotFound)
58
+ raise 'Failed to create new app: Unknown template'
59
+ else
60
+ raise "Failed to to create new app: #{response.message}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -18,6 +18,8 @@ module Bauble
18
18
  def preview
19
19
  Logger.logo
20
20
 
21
+ setup_app
22
+
21
23
  # check for any stacks
22
24
  raise 'No stacks found' if @app.stacks.empty?
23
25
 
@@ -18,6 +18,8 @@ module Bauble
18
18
  def up
19
19
  Logger.logo
20
20
 
21
+ setup_app
22
+
21
23
  # check for any stacks
22
24
  raise 'No stacks found' if @app.stacks.empty?
23
25
 
@@ -14,7 +14,8 @@ module Bauble
14
14
  :root_dir,
15
15
  :skip_gem_layer,
16
16
  :gem_layer_asset_dir,
17
- :shared_code_asset_dir
17
+ :shared_code_asset_dir,
18
+ :s3_backend
18
19
  )
19
20
 
20
21
  def initialize
@@ -27,6 +28,7 @@ module Bauble
27
28
  @app_stack_name = 'bauble'
28
29
  @debug = ENV['BAUBLE_DEBUG'] || false
29
30
  @skip_gem_layer = false
31
+ @s3_backend = nil
30
32
  set_pulumi_env_vars
31
33
  end
32
34
 
@@ -97,7 +97,9 @@ module Bauble
97
97
 
98
98
  def login
99
99
  Logger.debug 'Logging into pulumi locally...'
100
- run_command('login --local')
100
+ command = 'login'
101
+ command += ' --local' unless @config.s3_backend
102
+ run_command(command)
101
103
  end
102
104
 
103
105
  def pulumi_logged_in?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bauble
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bauble_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Hoegerl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-22 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -52,6 +52,16 @@ files:
52
52
  - CODE_OF_CONDUCT.md
53
53
  - LICENSE.txt
54
54
  - README.md
55
+ - examples/basic-app/Gemfile
56
+ - examples/basic-app/Gemfile.lock
57
+ - examples/basic-app/app/hello_world.rb
58
+ - examples/basic-app/bauble.json
59
+ - examples/basic-app/infra/app.rb
60
+ - examples/gem-dev-app/Gemfile
61
+ - examples/gem-dev-app/Gemfile.lock
62
+ - examples/gem-dev-app/app/hello.rb
63
+ - examples/gem-dev-app/bauble.json
64
+ - examples/gem-dev-app/infra/app.rb
55
65
  - exe/bauble
56
66
  - lib/bauble.rb
57
67
  - lib/bauble/application.rb
@@ -59,6 +69,7 @@ files:
59
69
  - lib/bauble/cli/cli.rb
60
70
  - lib/bauble/cli/code_bundler.rb
61
71
  - lib/bauble/cli/commands/destroy.rb
72
+ - lib/bauble/cli/commands/new.rb
62
73
  - lib/bauble/cli/commands/preview.rb
63
74
  - lib/bauble/cli/commands/up.rb
64
75
  - lib/bauble/cli/config.rb