diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1b274c4..f1930c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -45,6 +51,9 @@ generator: build: stage: build trigger: + forward: + pipeline_variables: true + yaml_variables: true include: - artifact: .gitlab/build-pipeline.yaml job: generator diff --git a/.gitlab/scripts/build_layer.sh b/.gitlab/scripts/build_layer.sh index 5b09b9d..c8505a9 100755 --- a/.gitlab/scripts/build_layer.sh +++ b/.gitlab/scripts/build_layer.sh @@ -37,6 +37,7 @@ 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. @@ -44,6 +45,7 @@ function docker_build_zip { 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 @@ -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/_" diff --git a/.gitlab/template.yaml.tpl b/.gitlab/template.yaml.tpl index 1c91ae5..2074a0e 100644 --- a/.gitlab/template.yaml.tpl +++ b/.gitlab/template.yaml.tpl @@ -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 .. diff --git a/Dockerfile b/Dockerfile index d03eec0..432cc5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"; \ + fi WORKDIR /opt # Remove native extension debase-ruby_core_source (25MB) runtimes below Ruby 2.6 diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index a8c0f3d..c0d005c 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -33,6 +33,7 @@ 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. @@ -40,6 +41,7 @@ function docker_build_zip { 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 @@ -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