Skip to content

Commit 16c85cc

Browse files
authored
update ruby/publish-layers.sh to be more granular (#232)
By matching the granularity of the Python script, consumers of the scripts can build without publishing and also easily get at the filenames of the built layer .zip files. see: newrelic/newrelic-ruby-agent#2638
1 parent ec1d33f commit 16c85cc

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

ruby/publish-layers.sh

+61-14
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
set -Eeuo pipefail
44

5-
# This script creates an AWS Lambda Ruby layer .zip file for each supported
6-
# architecture. The Ruby content does not change between architectures, but
7-
# the included Go based AWS Lambda extension does. The .zip files are written
8-
# to dist/ and from there they are uploaded to AWS via ../libBuild.sh
9-
# functionality.
5+
# This script creates and publishes an AWS Lambda Ruby layer .zip file for each
6+
# supported architecture. The Ruby content does not change between
7+
# architectures or targeted Ruby versions, but the included Go based AWS Lambda
8+
# extension does. The .zip files are written to dist/ and from there they are
9+
# uploaded to AWS via functionality defined in the ../libBuild.sh script.
1010
#
1111
# Each .zip file is structured like so for Ruby:
1212
# ruby/gems/<RUBY MAJOR><RUBY MINOR>.0 -- AWS sets this as GEM_PATH. It's where the agent lives
@@ -23,26 +23,61 @@ WRAPPER_FILE=newrelic_lambda_wrapper.rb
2323
# EXTENSION_CLONE_PATH='../../newrelic-lambda-extension_fallwith'
2424
EXTENSION_CLONE_PATH=''
2525

26+
# Distribution paths for ARM64
27+
RB32_DIST_ARM64=$DIST_DIR/ruby32.arm64.zip
28+
RB33_DIST_ARM64=$DIST_DIR/ruby33.arm64.zip
29+
30+
# Distribution paths for X86_64
31+
RB32_DIST_X64_64=$DIST_DIR/ruby32.x86_64.zip
32+
RB33_DIST_X64_64=$DIST_DIR/ruby33.x86_64.zip
33+
2634
source ../libBuild.sh
2735

2836
function usage {
2937
echo "./publish-layers.sh [ruby3.2|ruby3.3]"
3038
}
3139

32-
function build_and_publish_ruby {
33-
local ruby_version=$1
34-
build_and_publish_ruby_for_arch $ruby_version 'x86_64'
35-
build_and_publish_ruby_for_arch $ruby_version 'arm64'
40+
function build-ruby32-arm64 {
41+
build_ruby_for_arch 3.2 'arm64' $RB32_DIST_ARM64
42+
}
43+
44+
function build-ruby33-arm64 {
45+
build_ruby_for_arch 3.3 'arm64' $RB33_DIST_ARM64
46+
}
47+
48+
function build-ruby32-x86 {
49+
build_ruby_for_arch 3.2 'x86_64' $RB32_DIST_X64_64
50+
}
51+
52+
function build-ruby33-x86 {
53+
build_ruby_for_arch 3.3 'x86_64' $RB33_DIST_X86_64
54+
}
55+
56+
function publish-ruby32-arm64 {
57+
publish_ruby_for_arch 3.2 'arm64' $RB32_DIST_ARM64
3658
}
3759

38-
function build_and_publish_ruby_for_arch {
60+
function publish-ruby33-arm64 {
61+
publush_ruby_for_arch 3.3 'arm64' $RB33_DIST_ARM64
62+
}
63+
64+
function publish-ruby32-x86 {
65+
publish_ruby_for_arch 3.2 'x86_64' $RB32_DIST_X86_64
66+
}
67+
68+
function publish-ruby33-x86 {
69+
publish_ruby_for_arch 3.3 'x86_64' $RB33_DIST_X86_64
70+
}
71+
72+
function build_ruby_for_arch {
3973
local ruby_version=$1
4074
local arch=$2
75+
# dynamic filenames are harder to grab for other consumers of this script
76+
# local dist_file="$DIST_DIR/ruby${ruby_version//./}.$arch.zip"
77+
local dist_file=$3
4178

4279
echo "Building New Relic layer for ruby v$ruby_version ($arch)"
4380

44-
local dist_file="$DIST_DIR/ruby${ruby_version//./}.$arch.zip"
45-
4681
rm -rf $RUBY_DIR $dist_file
4782
mkdir -p $DIST_DIR
4883

@@ -102,6 +137,12 @@ function build_and_publish_ruby_for_arch {
102137
zip -rq $dist_file $RUBY_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
103138
rm -rf $RUBY_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE
104139
echo "Build complete: ${dist_file}"
140+
}
141+
142+
function publish_ruby_for_arch {
143+
local ruby_version=$1
144+
local arch=$2
145+
local dist_file=$3
105146

106147
for region in "${REGIONS_X86[@]}"; do
107148
echo "Publishing $dist_file for region=$region, ruby=$ruby_version, arch=$arch"
@@ -113,10 +154,16 @@ function build_and_publish_ruby_for_arch {
113154
set +u # permit $1 to be unbound so that '*' matches it when no args are present
114155
case "$1" in
115156
"ruby3.3")
116-
build_and_publish_ruby '3.3'
157+
build-ruby33-arm64
158+
publish-ruby33-arm64
159+
build-ruby33-x86
160+
publish-ruby33-x86
117161
;;
118162
"ruby3.2")
119-
build_and_publish_ruby '3.2'
163+
build-ruby32-arm64
164+
publish-ruby32-arm64
165+
build-ruby32-x86
166+
publish-ruby32-x86
120167
;;
121168
*)
122169
usage

0 commit comments

Comments
 (0)