From 3e74e5528f4ae9d0052963aba83e1c9599b58b82 Mon Sep 17 00:00:00 2001 From: Saket Chaudhary Date: Thu, 23 May 2024 14:11:37 +0530 Subject: [PATCH] update ruby workflow --- .github/workflows/publish-ruby.yml | 16 ++-- ruby/publish-ecr-images.sh | 125 ----------------------------- ruby/publish-layers.sh | 10 ++- 3 files changed, 13 insertions(+), 138 deletions(-) delete mode 100755 ruby/publish-ecr-images.sh diff --git a/.github/workflows/publish-ruby.yml b/.github/workflows/publish-ruby.yml index d53d753..f776e78 100644 --- a/.github/workflows/publish-ruby.yml +++ b/.github/workflows/publish-ruby.yml @@ -23,6 +23,9 @@ jobs: if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+(\.[0-9]+)*_ruby$ ]]; then echo "match=true" >> $GITHUB_OUTPUT fi + - name: Clean the workspace + run: ./bin/clean + working-directory: ruby - name: Install Ruby Dependencies run: bundle working-directory: ruby @@ -32,17 +35,10 @@ jobs: echo "::set-output name=VERSION::$( echo ${{ matrix.ruby-version }} | sed 's/\.//' )" - - name: Publish layer + - name: Build and Publish layer if: steps.ruby-check-tag.outputs.match == 'true' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - run: make publish-ruby${{ steps.ruby-version-without-dot.outputs.VERSION }}-ci - - name: Publish ECR image for ruby ${{ matrix.ruby-version }} - if: steps.ruby-check-tag.outputs.match == 'true' - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - run: | - cd ruby - ./publish-ecr-images.sh ruby${{ matrix.ruby-version }} + run: ./publish-layers.sh ruby${{ matrix.ruby-version }} + working-directory: ruby diff --git a/ruby/publish-ecr-images.sh b/ruby/publish-ecr-images.sh deleted file mode 100755 index e3b8a77..0000000 --- a/ruby/publish-ecr-images.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env bash - -set -Eeuo pipefail - -# This script creates an AWS Lambda Ruby layer .zip file for each supported -# architecture. The Ruby content does not change between architectures, but -# the included Go based AWS Lambda extension does. The .zip files are written -# to dist/ and from there they are uploaded to AWS via ../libBuild.sh -# functionality. -# -# Each .zip file is structured like so for Ruby: -# ruby/gems/.0 -- AWS sets this as GEM_PATH. It's where the agent lives -# ruby/lib -- AWS sets this as RUBYLIB. It's where the wrapper script lives -# extensions/ -- Where the NR Go based extension content lives -# preview-extensions-* -- Extensions preview file - -RUBY_DIR=ruby -DIST_DIR=dist -WRAPPER_FILE=newrelic_lambda_wrapper.rb -# Set this to a path to a clone of newrelic-lambda-extension to build -# an extension from scratch instead of downloading one. Set the path to '' -# to simply download a prebuilt one. -# EXTENSION_CLONE_PATH='../../newrelic-lambda-extension_fallwith' -EXTENSION_CLONE_PATH='' - -source ../libBuild.sh - -function usage { - echo "./publish-ecr-images.sh [ruby3.2|ruby3.3]" -} - -RUBY33_DIST_ARM64=$DIST_DIR/ruby33.arm64.zip -RUBY32_DIST_ARM64=$DIST_DIR/ruby32.arm64.zip - -RUBY33_DIST_X86_64=$DIST_DIR/ruby33.x86_64.zip -RUBY32_DIST_X86_64=$DIST_DIR/ruby32.x86_64.zip - - -function build_and_publish_ruby_for_arch { - local dist_file=$1 - local ruby_version=$2 - local arch=$3 - echo "Building New Relic layer for ruby v$ruby_version ($arch)" - - - rm -rf $RUBY_DIR $dist_file - mkdir -p $DIST_DIR - - bundle config set --local without development - bundle config set --local path . # Bundler will create a 'ruby' dir beneath here - bundle install - - local base_dir="$RUBY_DIR/gems/$ruby_version.0" - - # Bundler will have created ./ruby//gems - # AWS wants ./ruby/gems/ - # So we need to flip the directory structure around and also use the right - # Ruby version. For building, we insist on the same major Ruby version but - # are relaxed on the minor version. - mkdir $RUBY_DIR/gems - - # allow Ruby versions other than the target version to bundle - # so if Bundler used Ruby v3.3 and the target is v3.2, the '3.3.0' dir - # gets renamed to '3.2.0' - mv $RUBY_DIR/${ruby_version:0:1}* $base_dir - - for sub_dir in 'bin' 'build_info' 'cache' 'doc' 'extensions' 'plugins'; do - rm -rf $base_dir/$sub_dir - done - - mkdir -p $RUBY_DIR/lib - cp $WRAPPER_FILE $RUBY_DIR/lib - - # if Gemfile points Bundler to GitHub for the agent, discard extraneous repo - # content and repackage the vendored gem content as if it were sourced - # from RubyGems.org - if [[ -e "$base_dir/bundler" ]]; then - local phony_version=$(date +'%s') - mkdir -p $base_dir/gems # dir will exist if non-agent, non-dev gems are in Gemfile - local nr_dir=$base_dir/gems/newrelic_rpm-$phony_version - mv $base_dir/bundler/gems/newrelic-ruby-agent* $nr_dir - rm -rf $base_dir/bundler - mkdir $base_dir/specifications - echo -e "Gem::Specification.new {|s| s.name = 'newrelic_rpm'; s.version = '$phony_version'}" > $base_dir/specifications/newrelic_rpm-$phony_version.gemspec - for sub_dir in '.git' '.github' '.gitignore' '.rubocop.yml' '.rubocop_todo.yml' '.simplecov' '.snyk' '.yardopts' 'Brewfile' 'config' 'CONTRIBUTING.md' 'docker-compose.yml' 'DOCKER.md' 'Dockerfile' 'Gemfile' 'Guardfile' 'infinite_tracing' 'init.rb' 'install.rb' 'lefthook.yml' 'newrelic.yml' 'README.md' 'test' 'THIRD_PARTY_NOTICES.md' 'Thorfile' 'recipes' '.build_ignore'; do - rm -rf "$nr_dir/$sub_dir" - done fi - - if [ "$EXTENSION_CLONE_PATH" == "" ]; then - echo "Downloading prebuilt extension..." - download_extension $arch - else - echo "Building an extension from a local clone..." - here=$PWD - cd "$EXTENSION_CLONE_PATH" - make "dist-$arch" - mv "$EXTENSION_DIST_DIR" "$here/$EXTENSION_DIST_DIR" - mv "$EXTENSION_DIST_PREVIEW_FILE" "$here/$EXTENSION_DIST_PREVIEW_FILE" - cd $here - fi - - zip -rq $dist_file $RUBY_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE - rm -rf $RUBY_DIR $EXTENSION_DIST_DIR $EXTENSION_DIST_PREVIEW_FILE - echo "Build complete: ${dist_file}" -} - -set +u # permit $1 to be unbound so that '*' matches it when no args are present -case "$1" in - "ruby3.3") - build_and_publish_ruby_for_arch $RUBY33_DIST_X86_64 '3.3' 'x86_64' - publish_docker_ecr $RUBY33_DIST_X86_64 ruby3.3 x86_64 - build_and_publish_ruby_for_arch $RUBY33_DIST_ARM64 '3.3' 'arm64' - publish_docker_ecr $RUBY33_DIST_ARM64 ruby3.3 arm64 - - ;; - "ruby3.2") - build_and_publish_ruby_for_arch $RUBY32_DIST_X86_64 '3.2' 'x86_64' - publish_docker_ecr $RUBY32_DIST_X86_64 ruby3.2 x86_64 - build_and_publish_ruby_for_arch $RUBY32_DIST_ARM64 '3.2' 'arm64' - publish_docker_ecr $RUBY32_DIST_ARM64 ruby3.2 arm64 - ;; - *) - usage - ;; -esac diff --git a/ruby/publish-layers.sh b/ruby/publish-layers.sh index eb07462..ec8f31b 100755 --- a/ruby/publish-layers.sh +++ b/ruby/publish-layers.sh @@ -28,8 +28,8 @@ RB32_DIST_ARM64=$DIST_DIR/ruby32.arm64.zip RB33_DIST_ARM64=$DIST_DIR/ruby33.arm64.zip # Distribution paths for X86_64 -RB32_DIST_X64_64=$DIST_DIR/ruby32.x86_64.zip -RB33_DIST_X64_64=$DIST_DIR/ruby33.x86_64.zip +RB32_DIST_X86_64=$DIST_DIR/ruby32.x86_64.zip +RB33_DIST_X86_64=$DIST_DIR/ruby33.x86_64.zip source ../libBuild.sh @@ -46,7 +46,7 @@ function build-ruby33-arm64 { } function build-ruby32-x86 { - build_ruby_for_arch 3.2 'x86_64' $RB32_DIST_X64_64 + build_ruby_for_arch 3.2 'x86_64' $RB32_DIST_X86_64 } function build-ruby33-x86 { @@ -156,14 +156,18 @@ case "$1" in "ruby3.3") build-ruby33-arm64 publish-ruby33-arm64 + publish_docker_ecr $RB33_DIST_ARM64 ruby3.3 arm64 build-ruby33-x86 publish-ruby33-x86 + publish_docker_ecr $RB33_DIST_X86_64 ruby3.3 x86_64 ;; "ruby3.2") build-ruby32-arm64 publish-ruby32-arm64 + publish_docker_ecr $RB32_DIST_ARM64 ruby3.2 arm64 build-ruby32-x86 publish-ruby32-x86 + publish_docker_ecr $RB32_DIST_X86_64 ruby3.2 x86_64 ;; *) usage