belt 0.5.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2267465d1ad5fcc7e7e8b7d7c6be91919275a8bd6bc541c82c9751ac2265ab27
4
- data.tar.gz: 12c71c5a5db0520f26ee6df68fbbbbd5403105cb9ab2c08da2719d6513a6269e
3
+ metadata.gz: 62b1b84b58bb017a4a127a871136dfc32b02217314bf5fc5f2b1baceb599063b
4
+ data.tar.gz: 2bd29c90f7380f4efa4014cc079fefacef86ed9407b19f71fb06fc0ead217bff
5
5
  SHA512:
6
- metadata.gz: 7716c4d8eebea928388accc998fb38f00ffedf9c5cd8585ef6e8540d2a524e5a139002d434b1a5644e3b656c394692438715b39e87d7e9682b05b948273a8213
7
- data.tar.gz: 7259396f97e7e750c9b6f19092535deb3552e98a2d9af927f01a0bfef09352b0164ad9febf1de4572ca132ad82686d60f101c5b640a32013d88019395e0dd70a
6
+ metadata.gz: be2982d7fc1cc0bbac0a61369029801e2c95ccbb3539ca2effaa649f506cbda151d0e1b4f55284534a30d13331e36c7c215236eef5f5417c288bf282757d0afb
7
+ data.tar.gz: ab198a8c848feb617046b1dbe73d5887252253617da7420ecd5935a56925bd18473430dbf2f54b5f9302e7c9bee777f21416b19ea28ac37d8bdc377aa6730222
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Added
6
+
7
+ - **Ruby 4.0.** New apps and environments now run on the `ruby4.0` Lambda runtime.
8
+ The generated `infrastructure/<env>/main.tf` sets `ruby_version = "4.0"` on the
9
+ conveyor-belt provider (one setting for runtime + gem build image), and both
10
+ generated `main.tf` files now pin conveyor-belt `~> 0.0.16`, the first release that
11
+ migrates already-deployed functions when `ruby_version` changes. Belt, activeitem,
12
+ lambda_loadout, belt-pay and belt-messaging all pass their suites on Ruby 4.0. CI now
13
+ tests 3.3, 3.4 and 4.0. Existing apps: see [UPGRADING.md](UPGRADING.md#ruby-34--40).
14
+
15
+ ### Fixed
16
+
17
+ - **`belt deploy <env> --rebuild` builds gems for the runtime the function actually
18
+ runs.** It used to look for `ruby_version` in `terraform state show conveyor_belt.main`,
19
+ but that's a provider setting and never appears in resource state, so `--rebuild`
20
+ always compiled in `build-ruby3.4`. On a `ruby4.0` function that ships a
21
+ `vendor/bundle/ruby/3.4.0` bundle Ruby 4 can't load. Image selection is now: resource
22
+ `docker_build_image` → the live function's runtime → `ruby_version` in the env's
23
+ `main.tf` → `build-ruby3.4`.
24
+ - Removed `runtime: ruby3.3` from the `config/lambda/*.yml` examples in the docs.
25
+ conveyor-belt ignores that key; the runtime comes from the provider's `ruby_version`.
26
+
3
27
  ## 0.5.3
4
28
 
5
29
  ### Fixed
@@ -490,7 +490,7 @@ module Belt
490
490
  begin
491
491
  puts ' 📦 Building Lambda package...'
492
492
  assemble_package(lambda_dir, build_dir)
493
- build_gems(build_dir)
493
+ build_gems(build_dir, function_name)
494
494
  zip_file = create_zip(build_dir)
495
495
 
496
496
  puts ' 🚀 Deploying to AWS...'
@@ -572,13 +572,13 @@ module Belt
572
572
  puts ''
573
573
  end
574
574
 
575
- def build_gems(build_dir)
575
+ def build_gems(build_dir, function_name)
576
576
  puts ' 🐳 Building gems in Docker (Lambda-compatible)...'
577
577
 
578
578
  uid = Process.uid
579
579
  gid = Process.gid
580
580
 
581
- image = detect_docker_build_image
581
+ image = detect_docker_build_image(function_name)
582
582
 
583
583
  docker_cmd = [
584
584
  'docker', 'run', '--rm',
@@ -606,35 +606,58 @@ module Belt
606
606
  puts ' ✅ Gems installed'
607
607
  end
608
608
 
609
- # Reads docker_build_image from the conveyor_belt Terraform resource state.
610
- # Falls back to DEFAULT_DOCKER_BUILD_IMAGE if state is unavailable or attribute not set.
611
- def detect_docker_build_image
609
+ # Picks the image gems are compiled in. Native extensions and the
610
+ # vendor/bundle/ruby/<abi> path must match the function's runtime, so:
611
+ # 1. docker_build_image on the conveyor_belt resource (fully custom)
612
+ # 2. the live function's runtime (ruby4.0 → build-ruby4.0)
613
+ # 3. ruby_version in the env's conveyor-belt provider block
614
+ # 4. DEFAULT_DOCKER_BUILD_IMAGE
615
+ def detect_docker_build_image(function_name)
612
616
  env_dir = File.join(@infra_dir, @env)
613
- return DEFAULT_DOCKER_BUILD_IMAGE unless Dir.exist?(File.join(env_dir, '.terraform'))
617
+
618
+ image = docker_build_image_from_state(env_dir)
619
+ if image
620
+ puts " 📦 Using custom build image: #{image}"
621
+ return image
622
+ end
623
+
624
+ version = ruby_version_from_lambda(function_name) || ruby_version_from_provider(env_dir)
625
+ return DEFAULT_DOCKER_BUILD_IMAGE unless version
626
+
627
+ image = "public.ecr.aws/sam/build-ruby#{version}:latest-x86_64"
628
+ puts " 📦 Using build image for Ruby #{version}: #{image}"
629
+ image
630
+ end
631
+
632
+ def docker_build_image_from_state(env_dir)
633
+ return nil unless Dir.exist?(File.join(env_dir, '.terraform'))
614
634
 
615
635
  Dir.chdir(env_dir) do
616
636
  output, status = Open3.capture2('terraform', 'state', 'show', 'conveyor_belt.main')
617
- if status.success?
618
- # Prefer explicit docker_build_image if set
619
- image_match = output.match(/docker_build_image\s*=\s*"([^"]+)"/)
620
- if image_match
621
- image = image_match[1]
622
- puts " 📦 Using custom build image: #{image}"
623
- return image
624
- end
637
+ return nil unless status.success?
625
638
 
626
- # Otherwise derive from ruby_version
627
- version_match = output.match(/ruby_version\s*=\s*"([^"]+)"/)
628
- if version_match
629
- version = version_match[1]
630
- image = "public.ecr.aws/sam/build-ruby#{version}:latest-x86_64"
631
- puts " 📦 Using build image for Ruby #{version}: #{image}"
632
- return image
633
- end
634
- end
639
+ output[/docker_build_image\s*=\s*"([^"]+)"/, 1]
635
640
  end
641
+ end
642
+
643
+ # "ruby4.0" → "4.0"
644
+ def ruby_version_from_lambda(function_name)
645
+ output, status = Open3.capture2(
646
+ 'aws', 'lambda', 'get-function-configuration',
647
+ '--function-name', function_name,
648
+ '--query', 'Runtime',
649
+ '--output', 'text'
650
+ )
651
+ return nil unless status.success?
652
+
653
+ output.strip[/\Aruby(\d+\.\d+)\z/, 1]
654
+ end
655
+
656
+ def ruby_version_from_provider(env_dir)
657
+ main_tf = File.join(env_dir, 'main.tf')
658
+ return nil unless File.exist?(main_tf)
636
659
 
637
- DEFAULT_DOCKER_BUILD_IMAGE
660
+ File.read(main_tf)[/^\s*ruby_version\s*=\s*"([^"]+)"/, 1]
638
661
  end
639
662
 
640
663
  def strip_vendor_fat(build_dir)
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
  require 'erb'
5
5
  require_relative 'app_detection'
6
6
  require_relative 'environment_config'
7
+ require_relative '../version'
7
8
  require_relative 'frontend_registry'
8
9
  require_relative 'frontend_setup_command'
9
10
 
@@ -5,6 +5,7 @@ require 'erb'
5
5
  require 'json'
6
6
  require 'open3'
7
7
  require_relative 'setup_command'
8
+ require_relative '../version'
8
9
 
9
10
  module Belt
10
11
  module CLI
@@ -67,13 +67,26 @@ The Lambda entry point is specified in `config/lambda/<name>.yml`:
67
67
 
68
68
  ```yaml
69
69
  handler: lambda/<name>.lambda_handler
70
- runtime: ruby3.3
71
70
  timeout: 30
72
71
  memory: 256
73
72
  environment:
74
73
  ENVIRONMENT: ${var.environment}
75
74
  ```
76
75
 
76
+ The Ruby version is set once per environment, on the conveyor-belt provider in
77
+ `infrastructure/<env>/main.tf` — it drives both the Lambda runtime and the image
78
+ gems are compiled in:
79
+
80
+ ```hcl
81
+ provider "conveyor-belt" {
82
+ environment = var.environment
83
+ aws_region = var.aws_region
84
+ ruby_version = "4.0" # → runtime ruby4.0, build image build-ruby4.0
85
+ }
86
+ ```
87
+
88
+ See [UPGRADING.md](../../../UPGRADING.md#ruby-34--40) to move an existing app.
89
+
77
90
  ## Route Manifests
78
91
 
79
92
  Before deploying, generate the route manifest used at runtime:
@@ -67,7 +67,6 @@ Configure via `config/lambda/<name>.yml`:
67
67
 
68
68
  ```yaml
69
69
  handler: lambda/api.lambda_handler
70
- runtime: ruby3.3
71
70
  timeout: 30
72
71
  memory: 256
73
72
  layers:
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.5.3'
4
+ VERSION = '0.6.0'
5
+
6
+ # Ruby version new apps run on in Lambda. Rendered into the conveyor-belt
7
+ # provider block (`ruby_version`) by `belt new` / `belt generate environment`.
8
+ LAMBDA_RUBY_VERSION = '4.0'
5
9
  end
@@ -10,7 +10,7 @@ terraform {
10
10
  }
11
11
  conveyor-belt = {
12
12
  source = "stowzilla/conveyor-belt"
13
- version = "~> 0.0.1"
13
+ version = "~> 0.0.16"
14
14
  }
15
15
  }
16
16
  }
@@ -30,6 +30,10 @@ provider "aws" {
30
30
  provider "conveyor-belt" {
31
31
  environment = var.environment
32
32
  aws_region = var.aws_region
33
+
34
+ # Lambda runtime (ruby<version>) and the Docker image gems are compiled in.
35
+ # Changing it on a deployed environment migrates every function on the next apply.
36
+ ruby_version = "<%= Belt::LAMBDA_RUBY_VERSION %>"
33
37
  }
34
38
 
35
39
  module "app" {
@@ -13,7 +13,7 @@ terraform {
13
13
  }
14
14
  conveyor-belt = {
15
15
  source = "stowzilla/conveyor-belt"
16
- version = "~> 0.0.2"
16
+ version = "~> 0.0.16"
17
17
  }
18
18
  }
19
19
  }
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.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla