Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Feb 16, 2023
1 parent d559785 commit 55ee18f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/lib-injection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
9 changes: 9 additions & 0 deletions lib-injection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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~<DD_TRACE_SHA_TO_BE_REPLACED>~${DDTRACE_RUBY_SHA}~g" /datadog-init/auto_inject.rb
RUN sed -i "s~<DD_TRACE_VERSION_TO_BE_REPLACED>~${DDTRACE_RUBY_VERSION}~g" /datadog-init/auto_inject.rb

ADD copy-lib.sh /datadog-init/copy-lib.sh
14 changes: 12 additions & 2 deletions lib-injection/auto_inject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
puts 'ddtrace already installed... skipping auto-injection'
else
version = "<DD_TRACE_VERSION_TO_BE_REPLACED>"
puts "ddtrace is not installed... Perform auto-injection... for dd-trace-rb:#{version}"
sha = "<DD_TRACE_SHA_TO_BE_REPLACED>"

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...'
Expand Down

0 comments on commit 55ee18f

Please sign in to comment.