From 55ee18f54c12e99360e01ba475f83096ddf885f4 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Thu, 16 Feb 2023 20:29:17 +0100 Subject: [PATCH] WIP --- .github/workflows/lib-injection.yml | 13 ++++++++++++- lib-injection/Dockerfile | 9 +++++++++ lib-injection/auto_inject.rb | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lib-injection.yml b/.github/workflows/lib-injection.yml index 32a272bae5a..e421291e361 100644 --- a/.github/workflows/lib-injection.yml +++ b/.github/workflows/lib-injection.yml @@ -3,13 +3,24 @@ on: # Build each branch for testing push: +jobs: + build-and-publish-release-image: + uses: ./.github/workflows/build-and-publish-image.yml + with: + tags: 'ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:${{ github.sha }}' + platforms: 'linux/amd64,linux/arm64/v8' + build-args: 'DDTRACE_RUBY_VERSION=${{input.version}}' + context: ./lib-injection + secrets: + token: ${{ secrets.GITHUB_TOKEN }} + jobs: build-and-publish-test-image: uses: ./.github/workflows/build-and-publish-image.yml with: tags: 'ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:${{ github.sha }}' platforms: 'linux/amd64,linux/arm64/v8' - build-args: 'DDTRACE_RUBY_VERSION=git+https://github.com/Datadog/dd-trace-rb@${{ github.sha }}' + build-args: 'DDTRACE_RUBY_SHA=${{ github.sha }}' context: ./lib-injection secrets: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/lib-injection/Dockerfile b/lib-injection/Dockerfile index 3f1359de791..50e3461bcb5 100644 --- a/lib-injection/Dockerfile +++ b/lib-injection/Dockerfile @@ -3,12 +3,21 @@ FROM busybox ARG UID=10000 + ARG DDTRACE_RUBY_VERSION ENV DDTRACE_RUBY_VERSION=$DDTRACE_RUBY_VERSION + +ARG DDTRACE_RUBY_SHA +ENV DDTRACE_RUBY_SHA=$DDTRACE_RUBY_SHA + RUN addgroup -g 10000 -S datadog && \ adduser -u ${UID} -S datadog -G datadog + USER ${UID} WORKDIR /datadog-init ADD auto_inject.rb /datadog-init/auto_inject.rb + +RUN sed -i "s~~${DDTRACE_RUBY_SHA}~g" /datadog-init/auto_inject.rb RUN sed -i "s~~${DDTRACE_RUBY_VERSION}~g" /datadog-init/auto_inject.rb + ADD copy-lib.sh /datadog-init/copy-lib.sh diff --git a/lib-injection/auto_inject.rb b/lib-injection/auto_inject.rb index 6c0e3391759..08e34e96cb5 100644 --- a/lib-injection/auto_inject.rb +++ b/lib-injection/auto_inject.rb @@ -4,9 +4,19 @@ puts 'ddtrace already installed... skipping auto-injection' else version = "" - puts "ddtrace is not installed... Perform auto-injection... for dd-trace-rb:#{version}" + sha = "" - if system "skip_autoinject=true bundle add ddtrace --version #{version} --require ddtrace/auto_instrument" + condition = if !version.empty? + "--version '#{version}'" + elsif !sha.empty? + "--github 'datadog/dd-trace-rb' --ref '#{sha}'" + else + puts "NO VERSION" + end + + puts "ddtrace is not installed... Perform auto-injection... for dd-trace-rb" + + if system "skip_autoinject=true bundle add ddtrace #{condition} --require ddtrace/auto_instrument" puts 'ddtrace added to bundle...' else puts 'Something went wrong when adding ddtrace to bundle...'