s3arch 0.1.1 → 0.1.3

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: 89f4fce79a53db6b2890bf9034c5702e556ce27a1f399e8d4c605b8953fcd033
4
- data.tar.gz: 13b9092d968a9aa1a44dcacbe9bd9ede1304e8a9e67623219245e0f601a9d467
3
+ metadata.gz: 86ab9ff26fb027515006bee668f41d7d5f264fc301110d57f6ac4d365b426588
4
+ data.tar.gz: bb2a513c4f7252620668c7292357d0e314a60d9efae70738c5ffd127f386d4b2
5
5
  SHA512:
6
- metadata.gz: 1c2093cac0b0e12bc0a9fe679d218fa13aa6b1dfeb35b1bd69bef03dbf1699eaba32084931330e3322993981d541787966e270803e566716ea4b61de9edaddfe
7
- data.tar.gz: c6d81a49d383c03c03638a0d6548acc7df697b3fa3f1dc6bc26f8347bf03bb6f29a63707af68baa8920f45dceea74f3fe886533a4914c3af281149271f0b00e1
6
+ metadata.gz: 6def4b186fc609041e90c7246d1a9fb0453aeb01ae7c880040d9c8154a94eb514505adeab291191094c8e5e755e9fb753ccf699dd04cabccc672b0c7f74ad4cc
7
+ data.tar.gz: d1e054232f1d30443340ddd06f2a264458166b030a69b823327f82a61025f4065c000fadba2bbfc82d45949ee69b00e25d5be350d12a09309e4efab133d49503
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- s���%�1Ro[h��bIo��
2
- }�S�̭�� Y錣�E�����I�1�$|,lư�ˇ��O?��\���Vm���!���ov����e�:�r,�JO*��70�������<��!�G�BAA��� ��Ý5��4?\$ߴD{ܭw��G��ǧK�U���M����q�E��>�l�����I�(%@С8KϷ�T(
1
+ j��YC�����㯬`�Q����[��M~��Ҫ�q\Tr���Ih/4Z�]~�Қ�p�X�|;s��B��nP����R����X��Ꙁ�V -S6EvX�!ͦo���W9Y6�H$�04�6q[�4�E�P�(��HÊ���+$��[ ��L�~��!T~��A���
2
+ N����ʽ˛[�O�C�k����*���Q��
data/README.md CHANGED
@@ -26,7 +26,7 @@ Each owner (user, tenant, account) gets their own SQLite database. The indexer r
26
26
  gem 's3arch'
27
27
  ```
28
28
 
29
- Requires the `sqlite3` native extension available at runtime. On Lambda, use a layer that provides it (e.g., [stowzilla-sqlite3-ruby](https://github.com/stowzilla/stowzilla-sqlite3-ruby)).
29
+ Requires the `sqlite3` native extension available at runtime. On Lambda, build the layer with `rake lambda:build_layer` (see [Building the Lambda Layer](#building-the-lambda-layer)).
30
30
 
31
31
  ## Usage
32
32
 
@@ -139,6 +139,51 @@ Outputs include `indexer_env_vars`, `searcher_env_vars`, `indexer_permissions`,
139
139
  5. Apply metadata filters, sort by rank, return record IDs
140
140
  6. LRU eviction when `/tmp` fills up
141
141
 
142
+ ## Building the Lambda Layer
143
+
144
+ S3arch requires the `sqlite3` native extension at runtime. A Rake task is included to build and publish the Lambda layer:
145
+
146
+ ```bash
147
+ # Build the layer zip (outputs to pkg/sqlite-layer.zip)
148
+ rake s3arch:layer:build
149
+
150
+ # Build and publish in one step
151
+ rake s3arch:layer:publish PROFILE=devzilla
152
+
153
+ # Customize the build
154
+ rake s3arch:layer:build RUBY_VERSION=3.4 ARCHITECTURE=x86_64
155
+
156
+ # Publish to a specific region/account
157
+ rake s3arch:layer:publish PROFILE=production REGION=us-west-2 LAYER_NAME=stowzilla-sqlite3-ruby
158
+ ```
159
+
160
+ | Environment Variable | Default | Description |
161
+ |---------------------|---------|-------------|
162
+ | `RUBY_VERSION` | `3.4` | Ruby runtime version |
163
+ | `ARCHITECTURE` | `x86_64` | `x86_64` or `arm64` |
164
+ | `OUTPUT` | `pkg/sqlite-layer.zip` | Output path for the zip |
165
+ | `PROFILE` | (none) | AWS CLI profile for publishing |
166
+ | `REGION` | `us-east-1` | AWS region to publish to |
167
+ | `LAYER_NAME` | `stowzilla-sqlite3-ruby` | Layer name in AWS |
168
+ | `S3ARCH_VERSION` | `~> current minor` | Version constraint for s3arch in the layer |
169
+
170
+ Requires Docker to be running (uses the official AWS SAM build images).
171
+
172
+ ## Rake Tasks
173
+
174
+ ```bash
175
+ rake s3arch:layer:build # Build the Lambda layer zip
176
+ rake s3arch:layer:publish # Build and publish to AWS
177
+ rake s3arch:rebuild # Rebuild index for an owner (OWNER_ID=xxx)
178
+ rake s3arch:info # Show config and version info
179
+ ```
180
+
181
+ To make these tasks available in your app, add to your Rakefile:
182
+
183
+ ```ruby
184
+ require 's3arch/tasks'
185
+ ```
186
+
142
187
  ## Requirements
143
188
 
144
189
  - Ruby >= 3.2
@@ -146,6 +191,7 @@ Outputs include `indexer_env_vars`, `searcher_env_vars`, `indexer_permissions`,
146
191
  - SQLite3 native extension (via Lambda layer)
147
192
  - DynamoDB table with streams enabled
148
193
  - S3 bucket for index storage
194
+ - Docker (for building the Lambda layer)
149
195
 
150
196
  ## License
151
197
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load s3arch Rake tasks into the consuming application.
4
+ #
5
+ # Usage (in your Rakefile):
6
+ # require 's3arch/tasks'
7
+ #
8
+ # Or let your framework (e.g., belt) auto-require this.
9
+
10
+ Dir.glob(File.join(__dir__, '../../tasks/**/*.rake')).each { |r| load r }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module S3arch
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../s3arch/version'
4
+
5
+ namespace :s3arch do
6
+ namespace :layer do
7
+ desc 'Build the Lambda layer zip (defaults: RUBY_VERSION=3.4, ARCHITECTURE=x86_64)'
8
+ task :build do
9
+ require 'tmpdir'
10
+ require 'fileutils'
11
+
12
+ ruby_version = ENV.fetch('RUBY_VERSION', '3.4')
13
+ architecture = ENV.fetch('ARCHITECTURE', 'x86_64')
14
+ output_file = File.expand_path(ENV.fetch('OUTPUT', 'pkg/sqlite-layer.zip'))
15
+ s3arch_version = ENV.fetch('S3ARCH_VERSION', "~> #{S3arch::VERSION.sub(/\.\d+$/, '.0')}")
16
+
17
+ FileUtils.mkdir_p(File.dirname(output_file))
18
+
19
+ puts "🔨 Building Lambda layer (Ruby #{ruby_version} / #{architecture}, s3arch #{s3arch_version})..."
20
+
21
+ tmpdir = Dir.mktmpdir('s3arch-layer')
22
+ begin
23
+ File.write("#{tmpdir}/Gemfile", <<~GEMFILE)
24
+ source 'https://rubygems.org'
25
+ gem 'sqlite3', '~> 2.0'
26
+ gem 's3arch', '#{s3arch_version}'
27
+ GEMFILE
28
+
29
+ docker_image = "public.ecr.aws/sam/build-ruby#{ruby_version}:latest-#{architecture}"
30
+ platform = architecture == 'x86_64' ? 'linux/amd64' : 'linux/arm64'
31
+
32
+ build_script = <<~BASH
33
+ yum install -y sqlite-devel 2>/dev/null || dnf install -y sqlite-devel 2>/dev/null
34
+ bundle config set --local path /build/layer/ruby/gems/#{ruby_version}.0
35
+ bundle config set --local without "development test"
36
+ bundle config set --local deployment false
37
+ bundle install
38
+ NESTED="/build/layer/ruby/gems/#{ruby_version}.0/ruby/#{ruby_version}.0"
39
+ if [ -d "$NESTED" ]; then
40
+ mkdir -p /build/layer-final/ruby/gems/#{ruby_version}.0
41
+ cp -a "$NESTED"/* /build/layer-final/ruby/gems/#{ruby_version}.0/
42
+ rm -rf /build/layer
43
+ mv /build/layer-final /build/layer
44
+ fi
45
+ BASH
46
+
47
+ docker_cmd = [
48
+ 'docker', 'run', '--rm',
49
+ '--platform', platform,
50
+ '-v', "#{tmpdir}:/build",
51
+ '-w', '/build',
52
+ docker_image,
53
+ '/bin/bash', '-c', build_script
54
+ ]
55
+
56
+ puts "🐳 Building in Docker (#{docker_image})..."
57
+ abort '❌ Docker build failed' unless system(*docker_cmd)
58
+
59
+ layer_dir = "#{tmpdir}/layer"
60
+
61
+ puts '🧹 Stripping layer...'
62
+ Dir.glob("#{layer_dir}/ruby/gems/*/gems/*/").each do |gem_dir|
63
+ %w[spec test tests doc docs examples benchmarks].each do |fat_dir|
64
+ FileUtils.rm_rf("#{gem_dir}#{fat_dir}")
65
+ end
66
+ end
67
+
68
+ junk_patterns = %w[
69
+ *.md *.rdoc *.txt *.c *.h *.o Makefile *.log
70
+ CHANGELOG* HISTORY* LICENSE* README* .gitignore Rakefile
71
+ ]
72
+ junk_patterns.each do |pattern|
73
+ Dir.glob("#{layer_dir}/**/#{pattern}").each { |f| FileUtils.rm_f(f) }
74
+ end
75
+
76
+ Dir.glob("#{layer_dir}/**/*.so").each do |so|
77
+ system('strip', '--strip-debug', so, err: File::NULL)
78
+ end
79
+
80
+ sqlite_so = Dir.glob("#{layer_dir}/**/sqlite3_native.so") +
81
+ Dir.glob("#{layer_dir}/**/sqlite3.so")
82
+ abort '❌ sqlite3 native extension NOT found in layer' if sqlite_so.empty?
83
+ puts '✅ sqlite3 native extension included'
84
+
85
+ s3arch_lib = Dir.glob("#{layer_dir}/**/gems/s3arch-*/lib/s3arch.rb")
86
+ abort '❌ s3arch gem NOT found in layer' if s3arch_lib.empty?
87
+ puts '✅ s3arch gem included'
88
+
89
+ FileUtils.rm_f(output_file)
90
+ abort '❌ Failed to create zip' unless system('zip', '-qr', output_file, 'ruby/', chdir: layer_dir)
91
+
92
+ size = `du -h #{output_file}`.split("\t").first
93
+ puts "✅ Layer built: #{output_file} (#{size})"
94
+ ensure
95
+ system('sudo', 'rm', '-rf', tmpdir) || FileUtils.rm_rf(tmpdir)
96
+ end
97
+ end
98
+
99
+ desc 'Build and publish the Lambda layer (set AWS_PROFILE, LAYER_NAME=stowzilla-sqlite3-ruby)'
100
+ task publish: :build do
101
+ layer_name = ENV.fetch('LAYER_NAME', 'stowzilla-sqlite3-ruby')
102
+ ruby_version = ENV.fetch('RUBY_VERSION', '3.4')
103
+ architecture = ENV.fetch('ARCHITECTURE', 'x86_64')
104
+ output_file = File.expand_path(ENV.fetch('OUTPUT', 'pkg/sqlite-layer.zip'))
105
+
106
+ abort "❌ Layer zip not found at #{output_file}" unless File.exist?(output_file)
107
+
108
+ cmd = %w[aws lambda publish-layer-version]
109
+ cmd += ['--layer-name', layer_name]
110
+ cmd += ['--zip-file', "fileb://#{output_file}"]
111
+ cmd += ['--compatible-runtimes', "ruby#{ruby_version}"]
112
+ cmd += ['--compatible-architectures', architecture]
113
+
114
+ puts "📤 Publishing layer '#{layer_name}'..."
115
+ puts " #{cmd.join(' ')}"
116
+
117
+ abort '❌ Failed to publish layer' unless system(*cmd)
118
+
119
+ puts '✅ Layer published successfully'
120
+ end
121
+ end
122
+
123
+ desc 'Rebuild the search index for a given owner: rake s3arch:rebuild[owner-123]'
124
+ task :rebuild, [:owner_id] do |_t, args|
125
+ require 's3arch'
126
+
127
+ owner_id = args.owner_id || ENV.fetch('OWNER_ID', nil)
128
+ abort '❌ Usage: rake s3arch:rebuild[OWNER_ID]' unless owner_id
129
+
130
+ S3arch.configure { |c| c.from_env! }
131
+
132
+ puts "🔄 Rebuilding index for #{owner_id}..."
133
+ S3arch::Indexer.new.rebuild(owner_id)
134
+ puts '✅ Done'
135
+ end
136
+
137
+ desc 'Show current s3arch configuration and version info'
138
+ task :info do
139
+ require 's3arch'
140
+
141
+ puts "s3arch #{S3arch::VERSION}"
142
+ puts ''
143
+ puts 'Environment:'
144
+ %w[S3ARCH_SOURCE_TABLE S3ARCH_SOURCE_INDEX S3ARCH_INDEX_BUCKET S3ARCH_VERSION_TABLE].each do |var|
145
+ puts " #{var}=#{ENV.fetch(var, '(not set)')}"
146
+ end
147
+ end
148
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3arch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Dalton
@@ -130,9 +130,11 @@ files:
130
130
  - lib/s3arch/routes.rb
131
131
  - lib/s3arch/searcher.rb
132
132
  - lib/s3arch/store.rb
133
+ - lib/s3arch/tasks.rb
133
134
  - lib/s3arch/tokenizer.rb
134
135
  - lib/s3arch/version.rb
135
136
  - lib/s3arch/web.rb
137
+ - lib/tasks/s3arch.rake
136
138
  homepage: https://github.com/stowzilla/s3arch
137
139
  licenses:
138
140
  - MIT
metadata.gz.sig CHANGED
Binary file