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
84 changes: 84 additions & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env groovy
@Library('apm@current') _

pipeline {
agent { label 'linux && immutable' }
environment {
REPO = 'ecs-logging-ruby'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
DOCKER_REGISTRY = 'docker.elastic.co'
DOCKER_SECRET = 'secret/apm-team/ci/docker-registry/prod'
PIPELINE_LOG_LEVEL = 'INFO'
NOTIFY_TO = credentials('notify-to')
JOB_GCS_BUCKET = credentials('gcs-bucket')
VERSION = '2.7.2'
HOME = "${WORKSPACE}"
PATH = "${WORKSPACE}/.rbenv/bin:${WORKSPACE}/.rbenv/versions/${VERSION}/bin:${PATH}"
}
options {
timeout(time: 2, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
stages {
stage('Checkout') {
options { skipDefaultCheckout() }
steps {
pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ])
deleteDir()
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
stage('Tests') {
failFast false
matrix {
agent { label 'linux && docker && ubuntu-18.04 && immutable' }
options { skipDefaultCheckout() }
axes {
axis {
name 'RUBY_VERSION'
values 'ruby:2.7', 'ruby:2.6', 'ruby:2.5', 'ruby:2.4', 'ruby:2.3', 'jruby:9.2', 'jruby:9.1'
Comment on lines +48 to +49
Copy link
Member Author

Choose a reason for hiding this comment

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

List of supported ruby versions to be tested:

}
axis {
name 'FRAMEWORK'
values 'rails-6.0', 'rails-5.2', 'rails-5.1', 'sinatra-2.0'
}
}
stages {
stage('Tests') {
steps {
withGithubNotify(context: "Tests-${RUBY_VERSION}-${FRAMEWORK}") {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
dockerLogin(secret: "${DOCKER_SECRET}", registry: "${DOCKER_REGISTRY}")
sh(label: 'install rbenv', script: '.ci/install-rbenv.sh "${VERSION}"')
sh("bin/dev -i${RUBY_VERSION} -f${FRAMEWORK}")
}
}
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/spec/junit-reports/**/*-junit.xml")
}
}
}
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}
7 changes: 7 additions & 0 deletions .ci/install-rbenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
VERSION=${1:-"2.7.2"}
export PATH="$HOME/.rbenv/bin:$PATH"
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
git clone git@github.com:rbenv/ruby-build.git ~/.rbenv/plugins/ruby-buildCloning
eval "$(rbenv init -)"
rbenv install "${VERSION}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
# rspec failure tracking
.rspec_status
/vendor

# junit reports folder
spec/junit-reports
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
ENV PATH=/app/bin:$BUNDLE_BIN:$PATH

ENV FRAMEWORKS $FRAMEWORKS
ENV RUBY_IMAGE $RUBY_IMAGE
Copy link
Member Author

Choose a reason for hiding this comment

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

This will help to generate junit files with the ruby_image value in their names


RUN mkdir -p $VENDOR_PATH \
&& chown -R $USER_ID_GROUP $VENDOR_PATH

# Copy cached folder to speed up docker containers
COPY vendor /vendor
RUN chown -R $USER_ID_GROUP /vendor
Comment on lines +27 to +29
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required to use the cached artifacts if required, otherwise the docker build uses the VENDOR_PATH but the docker run overrides it, as a consequence it fails in the CI.

When building a docker image there is now way to mount volumes but using the COPY, this will help to reuse the existing local cache artifacts.

USER $USER_ID_GROUP

# Upgrade RubyGems and install required Bundler version
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gemspec

gem "rake"
gem "rspec"
gem 'yarjuf'

gem "rack-test", require: nil
gem "sinatra", require: nil
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
builder (3.2.4)
diff-lcs (1.4.4)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
Expand Down Expand Up @@ -35,6 +36,9 @@ GEM
rack-protection (= 2.1.0)
tilt (~> 2.0)
tilt (2.0.10)
yarjuf (2.0.0)
builder
rspec (~> 3)

PLATFORMS
ruby
Expand All @@ -45,6 +49,7 @@ DEPENDENCIES
rake
rspec
sinatra
yarjuf

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Jenkins](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-ruby/ecs-logging-ruby-mbp/master)](https://apm-ci.elastic.co/job/apm-agent-ruby/job/ecs-logging-ruby-mbp/job/master/)
# ecs-logging-ruby

This set of libraries allows you to transform your application logs to structured logs that comply with the [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html).
Expand Down
4 changes: 2 additions & 2 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ IMAGE_NAME = "apm-agent-ruby:#{IMAGE_PATH_SAFE}"
VENDOR_PATH = "/vendor/#{IMAGE_PATH_SAFE}"

def run(cmd)
"IMAGE_NAME=#{IMAGE_NAME} #{cmd}".tap do |str|
"IMAGE_NAME=#{IMAGE_NAME} USER_ID_GROUP=#{USER_ID_GROUP} #{cmd}".tap do |str|
puts str
system str
end
Expand All @@ -49,7 +49,7 @@ unless options[:skip_build]
end

run 'docker-compose run' \
" -u #{USER_ID_GROUP}" \
' --rm' \
" specs #{ARGV.join}"

exit $?.exitstatus unless $?.success?
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ services:
tty: true
volumes:
- .:/app:cached
- ./vendor:/vendor
tmpfs:
- /tmp:exec,mode=1777
user: ${USER_ID}
user: ${USER_ID_GROUP}

ruby_rspec:
image: apm-agent-ruby:${RUBY_VERSION}
user: ${USER_ID}
user: ${USER_ID_GROUP}

volumes:
vendor:
Expand Down
22 changes: 20 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
#!/bin/bash
set -x

runRspec(){
Copy link
Member Author

Choose a reason for hiding this comment

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

Delegate the how to the function then junit reporting are generated with a different name

local case=${1:-""}
local bn=${case}

if [ -n "${case}" ]; then
bn="$(basename "${case}")/"
fi
if [ -n "${RUBY_VERSION}" ]; then
bn="$RUBY_VERSION-$bn"
fi
if [ -n "${FRAMEWORKS}" ]; then
bn="$FRAMEWORKS-$bn"
fi
bundle exec rspec \
-f progress \
-r yarjuf -f JUnit -o "spec/junit-reports/${bn}ruby-agent-junit.xml" ${case}
}

bundle check || (rm Gemfile.lock && bundle)

# If first arg is a spec path, run spec(s)
if [[ $1 == spec/* ]]; then
bundle exec rspec $@
runRspec $@
exit $?
fi

# If no arguments, run all specs
if [[ $# == 0 ]]; then
bundle exec rspec
runRspec
exit $?
fi

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Bundler.require :default, :test

require "ecs_logging"
require 'yarjuf'

RSpec.configure do |config|
config.example_status_persistence_file_path = ".rspec_status"
Expand Down
Empty file added vendor/.gitkeep
Empty file.