Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
variables:
DOCKER_TARGET_IMAGE: registry.ddbuild.io/ci/datadog-lambda-rb
DOCKER_TARGET_VERSION: latest
GIT_REF:
description: branch/ref of dd-trace-rb to build the layer from. leave empty to use the latest release
value: ""
UPDATE_SNAPSHOTS:
description: whether or not to create new snapshots
value: ""

stages:
- pre
Expand Down Expand Up @@ -45,6 +51,9 @@ generator:
build:
stage: build
trigger:
forward:
pipeline_variables: true
yaml_variables: true
include:
- artifact: .gitlab/build-pipeline.yaml
job: generator
Expand Down
4 changes: 3 additions & 1 deletion .gitlab/scripts/build_layer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ function docker_build_zip {

destination=$(make_path_absolute $2)
arch=$3
ref=$4

# Install datadog ruby in a docker container to avoid the mess from switching
# between different ruby runtimes.
temp_dir=$(mktemp -d)
docker buildx build -t datadog-lambda-ruby-${arch}:$1 . --no-cache \
--build-arg "image=ruby:${1}" \
--build-arg "runtime=${1}.0" \
--build-arg "git_ref=${ref}" \
--platform linux/${arch} \
--progress=plain \
-o $temp_dir
Expand All @@ -59,7 +61,7 @@ rm -rf $LAYER_DIR
mkdir $LAYER_DIR

echo "Building layer for Ruby $RUBY_VERSION with architecture $ARCH"
docker_build_zip $RUBY_VERSION $LAYER_DIR/${LAYER_FILES_PREFIX}-${ARCH}-${RUBY_VERSION}.zip $ARCH
docker_build_zip $RUBY_VERSION $LAYER_DIR/${LAYER_FILES_PREFIX}-${ARCH}-${RUBY_VERSION}.zip $ARCH $GIT_REF

echo "Done creating layers:"
ls $LAYER_DIR | xargs -I _ echo "$LAYER_DIR/_"
8 changes: 7 additions & 1 deletion .gitlab/template.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ integration test ({{ $runtime.ruby_version }}, {{ $runtime.arch }}):
stage: test
tags: ["arch:amd64"]
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
needs:
needs:
- build layer ({{ $runtime.ruby_version }}, {{ $runtime.arch }})
dependencies:
- build layer ({{ $runtime.ruby_version }}, {{ $runtime.arch }})
cache: &{{ $runtime.name }}-{{ $runtime.arch }}-cache
artifacts:
when: always
expire_in: 1 week
name: snapshots-{{ $runtime.ruby_version }}-{{ $runtime.arch }}-${CI_JOB_ID}
paths:
- integration_tests/snapshots/
before_script:
- EXTERNAL_ID_NAME=integration-test-externalid ROLE_TO_ASSUME=sandbox-integration-test-deployer AWS_ACCOUNT=425362996713 source .gitlab/scripts/get_secrets.sh
- cd integration_tests && yarn install && cd ..
Expand Down
15 changes: 13 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG image
FROM $image AS builder
ARG git_ref
ARG runtime
RUN echo "git_ref: $git_ref"
# Install dev dependencies
COPY . /var/task/datadog-lambda-rb
WORKDIR /var/task/datadog-lambda-rb
Expand All @@ -12,8 +14,17 @@ RUN gem build datadog-lambda

# Install ddtrace gem
RUN gem install datadog-lambda --install-dir "/opt/ruby/gems/$runtime"
# NOTE: datadog gem must be >= 2.24 to install on Ruby 4.0.x.
RUN gem install datadog -v 2.30 --install-dir "/opt/ruby/gems/$runtime"
RUN set -eux; \
if [ -z "${git_ref:-}" ]; then \
# NOTE: datadog gem must be >= 2.24 to install on Ruby 4.0.x.
gem install datadog -v 2.30 --install-dir "/opt/ruby/gems/$runtime"; \
else \
echo "building tracer from ref: $git_ref\n"; \
git clone https://github.com/DataDog/dd-trace-rb.git --depth 1 --single-branch -b $git_ref /tmp/dd-trace-rb; \
cd /tmp/dd-trace-rb; \
gem build datadog.gemspec; \
gem install ./datadog-*.gem --install-dir "/opt/ruby/gems/$runtime"; \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not a way to install using the remote git ref? So you don't have to clone the repo? Cloning a repo in gitlab requires a whole set of permissions that would need to be updated to our gitlab projects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to clone it in this gitlab job

fi

WORKDIR /opt
# Remove native extension debase-ruby_core_source (25MB) runtimes below Ruby 2.6
Expand Down
6 changes: 4 additions & 2 deletions scripts/build_layers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ function docker_build_zip {

destination=$(make_path_absolute $2)
arch=$3
ref=$4

# Install datadog ruby in a docker container to avoid the mess from switching
# between different ruby runtimes.
temp_dir=$(mktemp -d)
docker buildx build -t datadog-lambda-ruby-${arch}:$1 . --no-cache \
--build-arg "image=ruby:${1}" \
--build-arg "runtime=${1}.0" \
--build-arg "git_ref=${ref}" \
--platform linux/${arch} \
--progress=plain \
-o $temp_dir
Expand All @@ -57,10 +59,10 @@ mkdir $LAYER_DIR
for ruby_version in "${RUBY_VERSIONS[@]}"
do
echo "Building layer for Ruby ${ruby_version} arch=arm64"
docker_build_zip ${ruby_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-arm64-${ruby_version}.zip arm64
docker_build_zip ${ruby_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-arm64-${ruby_version}.zip arm64 $GIT_REF

echo "Building layer for Ruby ${ruby_version} arch=amd64"
docker_build_zip ${ruby_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-amd64-${ruby_version}.zip amd64
docker_build_zip ${ruby_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-amd64-${ruby_version}.zip amd64 $GIT_REF
done


Expand Down