belt 0.2.16 → 0.2.17

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: 1dc14fd7c99d9f85c8e3d47cfdec53775ca3b433e1cc25d755793d4ab7ef4a39
4
- data.tar.gz: '06921a570cc8fc02263861e2be72808ed56af36dda1f1613668bbc186d63712a'
3
+ metadata.gz: 4e1813b72986b167b9449f438b18331cc2e9be46cffa58bd059c403f3c35703e
4
+ data.tar.gz: 26c3aae3c049bbebff471d6a8a514114a26f8b2d0fdf4671cb154ae9a056798f
5
5
  SHA512:
6
- metadata.gz: df18566c9678966e994a92564d8500c64b95abc6f33af4272004be45a9cd7490b41a43b2f67d6c069c872c14c7ce077e42ce3be153ef4694ccb154511ebb8fb3
7
- data.tar.gz: 18983f0ed77e920a59d03367a083918eef9eae1a596e3aea9e2f3cf7a986af0e1c89dec3ca9f205e39fcd7442a867ca490e51588b7aea364847fe8881f1c8fb9
6
+ metadata.gz: 23bbf9977c0cd765c7a1630e7a74ed480db6d62ee07c22e95e6a491a3a9c04d824b8463b0ef63ae4c4b343e13e96ff26c9edb5c86c8005fce7f0a167b6894c64
7
+ data.tar.gz: e7f625fe93dcb125289530e2a3bdb9dee8c37938eeea41bc9154a31aca6b47675a6336e39c986f3a801719f4cf22052bad40968ff6e1b9a82936140f74432f4a
@@ -14,6 +14,7 @@ require_relative 'path_gem_materializer'
14
14
  module Belt
15
15
  module CLI
16
16
  class DeployCommand
17
+ DEFAULT_DOCKER_BUILD_IMAGE = 'public.ecr.aws/sam/build-ruby3.4:latest-x86_64'
17
18
  def self.run(args)
18
19
  # Handle `belt deploy frontend <env>` as before
19
20
  if args.first == 'frontend'
@@ -514,12 +515,14 @@ module Belt
514
515
  uid = Process.uid
515
516
  gid = Process.gid
516
517
 
518
+ image = detect_docker_build_image
519
+
517
520
  docker_cmd = [
518
521
  'docker', 'run', '--rm',
519
522
  '--platform', 'linux/amd64',
520
523
  '-v', "#{build_dir}:/var/task",
521
524
  '-w', '/var/task',
522
- 'public.ecr.aws/sam/build-ruby3.4:latest-x86_64',
525
+ image,
523
526
  '/bin/bash', '-c',
524
527
  "bundle config set --local path 'vendor/bundle' && " \
525
528
  "bundle config set --local without 'development test' && " \
@@ -540,6 +543,37 @@ module Belt
540
543
  puts ' ✅ Gems installed'
541
544
  end
542
545
 
546
+ # Reads docker_build_image from the conveyor_belt Terraform resource state.
547
+ # Falls back to DEFAULT_DOCKER_BUILD_IMAGE if state is unavailable or attribute not set.
548
+ def detect_docker_build_image
549
+ env_dir = File.join(@infra_dir, @env)
550
+ return DEFAULT_DOCKER_BUILD_IMAGE unless Dir.exist?(File.join(env_dir, '.terraform'))
551
+
552
+ Dir.chdir(env_dir) do
553
+ output, status = Open3.capture2('terraform', 'state', 'show', 'conveyor_belt.main')
554
+ if status.success?
555
+ # Prefer explicit docker_build_image if set
556
+ image_match = output.match(/docker_build_image\s*=\s*"([^"]+)"/)
557
+ if image_match
558
+ image = image_match[1]
559
+ puts " 📦 Using custom build image: #{image}"
560
+ return image
561
+ end
562
+
563
+ # Otherwise derive from ruby_version
564
+ version_match = output.match(/ruby_version\s*=\s*"([^"]+)"/)
565
+ if version_match
566
+ version = version_match[1]
567
+ image = "public.ecr.aws/sam/build-ruby#{version}:latest-x86_64"
568
+ puts " 📦 Using build image for Ruby #{version}: #{image}"
569
+ return image
570
+ end
571
+ end
572
+ end
573
+
574
+ DEFAULT_DOCKER_BUILD_IMAGE
575
+ end
576
+
543
577
  def strip_vendor_fat(build_dir)
544
578
  vendor_dir = File.join(build_dir, 'vendor')
545
579
  return unless Dir.exist?(vendor_dir)
@@ -84,6 +84,12 @@ module Belt
84
84
  # Extract indexes() declaration
85
85
  indexes = extract_indexes(content)
86
86
 
87
+ # Extract belongs_to associations and generate convention indexes
88
+ indexes += extract_belongs_to_indexes(content)
89
+
90
+ # Deduplicate by index name
91
+ indexes.uniq! { |idx| idx[:name] }
92
+
87
93
  { name: model_name, indexes: indexes }
88
94
  end
89
95
 
@@ -109,6 +115,24 @@ module Belt
109
115
  indexes
110
116
  end
111
117
 
118
+ # Extract belongs_to declarations and generate convention-based GSI indexes.
119
+ # belongs_to :conversation → ConversationIndex with partition_key: 'conversationId'
120
+ def extract_belongs_to_indexes(content)
121
+ indexes = []
122
+
123
+ # Skip commented-out belongs_to lines
124
+ content.lines.reject { |line| line.strip.start_with?('#') }.join
125
+ .scan(/belongs_to\s+:(\w+)/) do |match|
126
+ association_name = match[0]
127
+ index_name = "#{Belt::Inflector.classify(association_name)}Index"
128
+ partition_key = "#{association_name}Id"
129
+
130
+ indexes << { name: index_name, partition_key: partition_key, sort_key: nil }
131
+ end
132
+
133
+ indexes
134
+ end
135
+
112
136
  def generate_dynamodb_tf(models)
113
137
  dest = File.join(MODULE_DIR, 'dynamodb.tf')
114
138
  existing_content = File.exist?(dest) ? File.read(dest) : nil
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.2.16'
4
+ VERSION = '0.2.17'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla