Skip to content

Commit

Permalink
Migrate job to build test docker images to beats repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed May 27, 2020
1 parent cdc7e07 commit 9f6ba83
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
103 changes: 103 additions & 0 deletions .ci/build-docker-images.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env groovy

@Library('apm@current') _

pipeline {
agent { label 'linux && immutable' }
environment {
REPO = 'beats'
BASE_DIR = "src/github.com/elastic/beats"
DOCKER_REGISTRY = 'docker.elastic.co'
DOCKER_REGISTRY_SECRET = 'secret/observability-team/ci/docker-registry/prod'
GOPATH = "${env.WORKSPACE}"
HOME = "${env.WORKSPACE}"
NOTIFY_TO = credentials('notify-to')
PATH = "${env.GOPATH}/bin:${env.PATH}"
PIPELINE_LOG_LEVEL='INFO'
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
cron '@daily'
}
parameters {
booleanParam(name: "RELEASE_TEST_IMAGES", defaultValue: "true", description: "If it's needed to build & push Beats' test images")
}
stages {
stage('Checkout') {
steps {
dir("${BASE_DIR}"){
git("https://github.com/elastic/beats.git")
}
script {
dir("${BASE_DIR}"){
env.GO_VERSION = readFile(".go-version").trim()
}
}
}
}
stage('Install dependencies') {
when {
expression { return params.RELEASE_TEST_IMAGES }
}
steps {
sh(label: 'Install virtualenv', script: 'pip install --user virtualenv')
}
}
stage('Metricbeat Test Docker images'){
options {
warnError('Metricbeat Test Docker images failed')
}
when {
expression { return params.RELEASE_TEST_IMAGES }
}
steps {
dockerLogin(secret: "${env.DOCKER_REGISTRY_SECRET}", registry: "${env.DOCKER_REGISTRY}")
retry(3){
sh(label: 'Build ', script: ".ci/scripts/build-beats-integrations-test-images.sh '${GO_VERSION}' '${HOME}/${BASE_DIR}/metricbeat'")
}
}
}
stage('Metricbeat x-pack Test Docker images'){
options {
warnError('Metricbeat x-pack Docker images failed')
}
when {
expression { return params.RELEASE_TEST_IMAGES }
}
steps {
dockerLogin(secret: "${env.DOCKER_REGISTRY_SECRET}", registry: "${env.DOCKER_REGISTRY}")
retry(3){
sh(label: 'Build ', script: ".ci/scripts/build-beats-integrations-test-images.sh '${GO_VERSION}' '${HOME}/${BASE_DIR}/x-pack/metricbeat'")
}
}
}
stage('Filebeat x-pack Test Docker images'){
options {
warnError('Filebeat x-pack Test Docker images failed')
}
when {
expression { return params.RELEASE_TEST_IMAGES }
}
steps {
dockerLogin(secret: "${env.DOCKER_REGISTRY_SECRET}", registry: "${env.DOCKER_REGISTRY}")
retry(3){
sh(label: 'Build ', script: ".ci/scripts/build-beats-integrations-test-images.sh '${GO_VERSION}' '${HOME}/${BASE_DIR}/x-pack/filebeat'")
}
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}
52 changes: 52 additions & 0 deletions .ci/scripts/build-beats-integrations-test-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -exo pipefail

#
# Install the given go version using the gimme script.
#
# Parameters:
# - GO_VERSION - that's the version which will be installed and enabled.
# - BEAT_BASE_DIR - that's the base directory of the Beat.
#

readonly GO_VERSION="${1?Please define the Go version to be used}"
readonly BEAT_BASE_DIR="${2?Please define the location of the Beat directory}"

function build_test_images() {
local baseDir="${1}"

cd "${baseDir}"
mage compose:buildSupportedVersions
}

function install_go() {
local goVersion="${1}"

# Install Go using the same travis approach
echo "Installing ${goVersion} with gimme."
eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=${goVersion} bash)"
}

function install_mage() {
local baseDir="${1}"

cd "${baseDir}"
make mage
}

function push_test_images() {
local baseDir="${1}"

cd "${baseDir}"
mage compose:pushSupportedVersions
}

function main() {
install_go "${GO_VERSION}"
install_mage "${BEAT_BASE_DIR}"

build_test_images "${BEAT_BASE_DIR}"
push_test_images "${BEAT_BASE_DIR}"
}

main "$@"

0 comments on commit 9f6ba83

Please sign in to comment.