belt 0.5.2 → 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 +4 -4
- data/CHANGELOG.md +36 -0
- data/lib/belt/cli/deploy_command.rb +48 -25
- data/lib/belt/cli/environment_command.rb +1 -0
- data/lib/belt/cli/new_command.rb +1 -0
- data/lib/belt/docs/deployment.md +14 -1
- data/lib/belt/docs/lambda_handler.md +0 -1
- data/lib/belt/version.rb +5 -1
- data/lib/templates/environment/main.tf.erb +5 -1
- data/lib/templates/module/main.tf.erb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62b1b84b58bb017a4a127a871136dfc32b02217314bf5fc5f2b1baceb599063b
|
|
4
|
+
data.tar.gz: 2bd29c90f7380f4efa4014cc079fefacef86ed9407b19f71fb06fc0ead217bff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be2982d7fc1cc0bbac0a61369029801e2c95ccbb3539ca2effaa649f506cbda151d0e1b4f55284534a30d13331e36c7c215236eef5f5417c288bf282757d0afb
|
|
7
|
+
data.tar.gz: ab198a8c848feb617046b1dbe73d5887252253617da7420ecd5935a56925bd18473430dbf2f54b5f9302e7c9bee777f21416b19ea28ac37d8bdc377aa6730222
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
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
|
+
|
|
27
|
+
## 0.5.3
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- **New apps now package `lambda/config/` into every Lambda.** The generated
|
|
32
|
+
`infrastructure/modules/app/main.tf` listed `lambda_shared_dirs` without `config`, so
|
|
33
|
+
`lambda/config/environment.rb` never reached `/var/task`. Handlers generated by
|
|
34
|
+
belt-pay (`pay_webhooks.rb`) and belt-messaging (`messaging_events.rb`) start with
|
|
35
|
+
`require_relative 'config/environment'`, so they crashed on init with
|
|
36
|
+
`cannot load such file -- /var/task/config/environment`. Existing apps: add `"config"`
|
|
37
|
+
to `lambda_shared_dirs` in `infrastructure/modules/app/main.tf` and redeploy.
|
|
38
|
+
|
|
3
39
|
## 0.5.2
|
|
4
40
|
|
|
5
41
|
### Added
|
|
@@ -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
|
-
#
|
|
610
|
-
#
|
|
611
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
660
|
+
File.read(main_tf)[/^\s*ruby_version\s*=\s*"([^"]+)"/, 1]
|
|
638
661
|
end
|
|
639
662
|
|
|
640
663
|
def strip_vendor_fat(build_dir)
|
data/lib/belt/cli/new_command.rb
CHANGED
data/lib/belt/docs/deployment.md
CHANGED
|
@@ -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:
|
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.
|
|
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.
|
|
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.
|
|
16
|
+
version = "~> 0.0.16"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -25,7 +25,9 @@ resource "conveyor_belt" "main" {
|
|
|
25
25
|
source = "${path.module}/../../../config/routes.rb"
|
|
26
26
|
app_name = var.app_name
|
|
27
27
|
lambda_source_dir = "${path.module}/../../../lambda"
|
|
28
|
-
|
|
28
|
+
# "config" ships lambda/config/environment.rb, which the belt-pay and belt-messaging
|
|
29
|
+
# handlers require_relative at boot.
|
|
30
|
+
lambda_shared_dirs = ["config", "controllers", "helpers", "lib", "models", "views"]
|
|
29
31
|
<% if @frontend -%>
|
|
30
32
|
# CloudFront first so SPA→API CORS works out of the box (tutorial footgun fixed).
|
|
31
33
|
# localhost stays via env frontend_urls for local `belt server` dev.
|