version: 2.1 # Common variables, containers, jobs and steps. job_defaults: &job_defaults working_directory: /app shell: /bin/bash --login test_containers: - &container_base environment: - BUNDLE_GEMFILE=/app/Gemfile - &container_postgres image: postgres:9.6 environment: - POSTGRES_PASSWORD=postgres - POSTGRES_USER=postgres - POSTGRES_DB=postgres - &container_presto image: prestosql/presto - &container_mysql image: mysql:5.6 environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_PASSWORD=mysql - MYSQL_USER=mysql - &container_elasticsearch image: elasticsearch:2.4 - &container_redis image: redis:3.0 - &container_mongo image: mongo:3.5 - &container_memcached image: memcached:1.5-alpine - &container_agent image: datadog/docker-dd-agent environment: - DD_APM_ENABLED=true - DD_BIND_HOST=0.0.0.0 - DD_API_KEY=invalid_key_but_this_is_fine step_init_bundle_checksum: &step_init_bundle_checksum run: name: Initialize bundle cache key command: | touch .circleci/bundle_checksum step_bundle_install: &step_bundle_install run: name: Install gem dependencies command: bundle install step_rubocop: &step_rubocop run: name: Delint with Rubocop command: bundle exec rake rubocop step_appraisal_install: &step_appraisal_install run: name: Install Appraisal gems command: | bundle exec appraisal clean # Ensure we fetch the latest version of dependencies bundle exec appraisal install step_compute_bundle_checksum: &step_compute_bundle_checksum run: name: Compute bundle checksum command: | # JRuby: Ensure files exist when Appraisal generates no output mkdir gemfiles touch gemfiles/_.gemfile.lock cat Gemfile.lock gemfiles/*.gemfile.lock > .circleci/bundle_checksum step_run_all_tests: &step_run_all_tests run: name: Run tests command: bundle exec rake ci step_release_docs: &step_release_docs run: name: Upload release docs command: S3_DIR=trace bundle exec rake release:docs filters_all_branches_and_tags: &filters_all_branches_and_tags filters: tags: only: /.*/ filters_only_release_tags: &filters_only_release_tags filters: branches: ignore: /.*/ tags: only: /^v\d+(\.\d+){0,3}(\.(alpha|beta|rc)\d+)?$/ orbs: orb: jobs: checkout: <<: *job_defaults parameters: ruby_version: description: Ruby version type: string image: description: Docker image location type: string docker: - <<: *container_base image: <> steps: - checkout - save_cache: key: '{{ .Environment.CIRCLE_CACHE_VERSION }}-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' paths: - /app build: <<: *job_defaults parameters: ruby_version: description: Ruby version type: string image: description: Docker image location type: string docker: - <<: *container_base image: <> steps: - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundled-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' - '{{ .Environment.CIRCLE_CACHE_VERSION }}-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' - restore_cache: keys: - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "Appraisals" }}-{{ checksum "ddtrace.gemspec" }} - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}- - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<>-{{ checksum "lib/ddtrace/version.rb" }} - *step_init_bundle_checksum - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundle-<>-{{ checksum ".circleci/bundle_checksum" }}' - *step_bundle_install - *step_appraisal_install - *step_compute_bundle_checksum - save_cache: key: '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundled-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' paths: - /app - save_cache: key: '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundle-<>-{{ checksum ".circleci/bundle_checksum" }}' paths: - /usr/local/bundle - save_cache: key: bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "Appraisals" }}-{{ checksum "ddtrace.gemspec" }}-{{ checksum ".circleci/bundle_checksum" }}' paths: - /usr/local/bundle test: <<: *job_defaults parameters: ruby_version: description: Ruby version type: string image: description: Docker image location type: string docker: - <<: *container_base image: <> environment: - BUNDLE_GEMFILE: /app/Gemfile - TEST_DATADOG_INTEGRATION: 1 - *container_postgres - *container_presto - *container_mysql - *container_elasticsearch - *container_redis - *container_mongo - *container_memcached - *container_agent steps: - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundled-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundle-<>-{{ checksum ".circleci/bundle_checksum" }}' - *step_run_all_tests benchmark: <<: *job_defaults parameters: ruby_version: description: Ruby version type: string image: description: Docker image location type: string docker: - <<: *container_base image: <> environment: - BUNDLE_GEMFILE: /app/Gemfile - TEST_DATADOG_INTEGRATION: 1 - *container_postgres - *container_redis - *container_agent steps: - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundled-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundle-<>-{{ checksum ".circleci/bundle_checksum" }}' - run: name: Run Benchmark command: bundle exec appraisal rails5-postgres-sidekiq ruby benchmarks/sidekiq_test.rb 2>&1 1> /dev/null | tee benchmark_results.csv - run: name: Run Benchmark without ddtracer command: rm -f lib/ddtrace.rb && bundle exec appraisal rails5-postgres-sidekiq ruby benchmarks/sidekiq_test.rb 2>&1 1> /dev/null | tee benchmark_results.csv lint: <<: *job_defaults parameters: ruby_version: description: Ruby version type: string image: description: Docker image location type: string docker: - <<: *container_base image: <> environment: - BUNDLE_GEMFILE: /app/Gemfile steps: - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundled-repo-<>-{{ .Environment.CIRCLE_SHA1 }}' - restore_cache: keys: - '{{ .Environment.CIRCLE_CACHE_VERSION }}-bundle-<>-{{ checksum ".circleci/bundle_checksum" }}' - *step_rubocop commands: executors: jobs: "deploy release": <<: *job_defaults docker: - <<: *container_base image: marcotc/docker-library:ddtrace_rb_2_5_6 steps: - checkout - run: name: Install AWS CLI command: | apt-get -y -qq update apt-get -y -qq install awscli - *step_bundle_install - *step_release_docs - run: name: Upload release Gem and rebuild index command: S3_DIR=release bundle exec rake release:gem - store_artifacts: path: pkg/ destination: gem "deploy prerelease Gem": <<: *job_defaults docker: - <<: *container_base image: marcotc/docker-library:ddtrace_rb_2_5_6 steps: - run: name: Check if this commit author has publishing credentials command: | if [[ -z "${AWS_ACCESS_KEY_ID}" ]] then echo 'No AWS credentials, skipping publish of pre-release build.' circleci task halt fi - checkout - run: name: Install AWS CLI command: | apt-get -y -qq update apt-get -y -qq install awscli - *step_bundle_install - run: name: Rename to pre-release version based on branch name and build number command: | # create safe version string PRE=$(echo "${CIRCLE_BRANCH:-unknown}.${CIRCLE_BUILD_NUM:-R$RANDOM}" | sed -e 's/[^a-zA-Z0-9+]\{1,\}/./g') echo PRE=$PRE sed lib/ddtrace/version.rb -i -e "s/^\([\t ]*PRE\) *=*/\1 = \'${PRE}\' #/g" - run: name: Upload prereleas Gem and rebuild index command: S3_DIR=prerelease bundle exec rake release:gem - store_artifacts: path: pkg/ destination: gem job_configuration: # MRI - &config-2_0 <<: *filters_all_branches_and_tags ruby_version: '2.0' image: palazzem/docker-library:ddtrace_rb_2_0_0 - &config-2_1 <<: *filters_all_branches_and_tags ruby_version: '2.1' image: palazzem/docker-library:ddtrace_rb_2_1_10 - &config-2_2 <<: *filters_all_branches_and_tags ruby_version: '2.2' image: palazzem/docker-library:ddtrace_rb_2_2_10 - &config-2_3 <<: *filters_all_branches_and_tags ruby_version: '2.3' image: palazzem/docker-library:ddtrace_rb_2_3_8 - &config-2_4 <<: *filters_all_branches_and_tags ruby_version: '2.4' image: palazzem/docker-library:ddtrace_rb_2_4_6 - &config-2_5 <<: *filters_all_branches_and_tags ruby_version: '2.5' image: marcotc/docker-library:ddtrace_rb_2_5_6 - &config-2_6 <<: *filters_all_branches_and_tags ruby_version: '2.6' image: marcotc/docker-library:ddtrace_rb_2_6_4 - &config-2_7 <<: *filters_all_branches_and_tags ruby_version: '2.7' image: marcotc/docker-library:ddtrace_rb_2_7_0 # JRuby - &config-jruby-9_2 <<: *filters_all_branches_and_tags ruby_version: 'jruby-9.2' image: marcotc/docker-library:ddtrace_rb_jruby_9_2 workflows: version: 2 build-and-test: jobs: - orb/lint: <<: *config-2_6 name: lint requires: - build-2.6 # MRI - orb/checkout: <<: *config-2_0 name: checkout-2.0 - orb/build: <<: *config-2_0 name: build-2.0 requires: - checkout-2.0 - orb/test: <<: *config-2_0 name: test-2.0 requires: - build-2.0 - orb/checkout: <<: *config-2_1 name: checkout-2.1 - orb/build: <<: *config-2_1 name: build-2.1 requires: - checkout-2.1 - orb/test: <<: *config-2_1 name: test-2.1 requires: - build-2.1 - orb/checkout: <<: *config-2_2 name: checkout-2.2 - orb/build: <<: *config-2_2 name: build-2.2 requires: - checkout-2.2 - orb/test: <<: *config-2_2 name: test-2.2 requires: - build-2.2 - orb/checkout: <<: *config-2_3 name: checkout-2.3 - orb/build: <<: *config-2_3 name: build-2.3 requires: - checkout-2.3 - orb/test: <<: *config-2_3 name: test-2.3 requires: - build-2.3 - orb/benchmark: <<: *config-2_3 name: benchmark-2.3 requires: - build-2.3 - orb/checkout: <<: *config-2_4 name: checkout-2.4 - orb/build: <<: *config-2_4 name: build-2.4 requires: - checkout-2.4 - orb/test: <<: *config-2_4 name: test-2.4 requires: - build-2.4 - orb/checkout: <<: *config-2_5 name: checkout-2.5 - orb/build: <<: *config-2_5 name: build-2.5 requires: - checkout-2.5 - orb/test: <<: *config-2_5 name: test-2.5 requires: - build-2.5 - orb/checkout: <<: *config-2_6 name: checkout-2.6 - orb/build: <<: *config-2_6 name: build-2.6 requires: - checkout-2.6 - orb/test: <<: *config-2_6 name: test-2.6 requires: - build-2.6 - orb/checkout: <<: *config-2_7 name: checkout-2.7 - orb/build: <<: *config-2_7 name: build-2.7 requires: - checkout-2.7 - orb/test: <<: *config-2_7 name: test-2.7 requires: - build-2.7 # JRuby - orb/checkout: <<: *config-jruby-9_2 name: checkout-jruby-9.2 - orb/build: <<: *config-jruby-9_2 name: build-jruby-9.2 requires: - checkout-jruby-9.2 - orb/test: <<: *config-jruby-9_2 name: test-jruby-9.2 requires: - build-jruby-9.2 # Release jobs - "deploy prerelease Gem": <<: *filters_all_branches_and_tags requires: - lint - test-2.0 - test-2.1 - test-2.2 - test-2.3 - test-2.4 - test-2.5 - test-2.6 - test-2.7 - test-jruby-9.2 - "deploy release": <<: *filters_only_release_tags requires: - lint - test-2.0 - test-2.1 - test-2.2 - test-2.3 - test-2.4 - test-2.5 - test-2.6 - test-2.7 - test-jruby-9.2