Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Enable packaging with Pipeline 2.0 #23854

Merged
merged 50 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a38cd76
[CI] Enable packaging with Pipeline 2.0
v1v Feb 4, 2021
6e423ab
Support e2e approach
v1v Feb 4, 2021
f5bdbb6
Support packaging with pipeline 2.0
v1v Feb 4, 2021
6a0ea66
Fix command
v1v Feb 4, 2021
e015b8e
For testing purposes
v1v Feb 4, 2021
7f7b41e
[CI] for testing purposes
v1v Feb 4, 2021
8ad4707
fix wrong syntax with a - in the field
v1v Feb 4, 2021
121e52a
[CI] fix credentials issue
v1v Feb 4, 2021
5b61e05
Use default git step (to avoid any kind of new env variables generate…
v1v Feb 5, 2021
38b7a2e
Cosmetic changes: use the right variable and docs
v1v Feb 5, 2021
164830a
Force GO_VERSION for the e2e to work
v1v Feb 5, 2021
1268e77
Use dir for go
v1v Feb 5, 2021
0174527
Use checkout to skip clean folder with git
v1v Feb 5, 2021
b1f053f
Merge branch 'master' into feature/packaging-e2e-2.0
v1v Feb 5, 2021
644e341
Revert "Use checkout to skip clean folder with git"
v1v Feb 5, 2021
41a6407
Checkout in the folder
v1v Feb 5, 2021
d4e4cca
Return boolean
v1v Feb 6, 2021
ecfd31b
Use junit reporting
v1v Feb 7, 2021
3f79030
Test metricbeat script
v1v Feb 7, 2021
481c3cf
Delegate test preparation to the e2e scripts
v1v Feb 7, 2021
872bcba
Prepare Go version dynamically
v1v Feb 7, 2021
1222ca4
Use entrypoint
v1v Feb 8, 2021
0cd5c08
Publish packages
v1v Feb 8, 2021
2299757
Push CI docker images
v1v Feb 8, 2021
58e5bc5
Use e2e master branch
v1v Feb 8, 2021
5c9d7ea
Disable other pipelines
v1v Feb 9, 2021
85260d8
Add debug mode
v1v Feb 9, 2021
d0371d4
Rename LOG level variable
v1v Feb 9, 2021
96ff995
Avoid using the workdir
v1v Feb 9, 2021
1862d03
For debugging purposes
v1v Feb 9, 2021
3ac5cb2
Revert "For debugging purposes"
v1v Feb 9, 2021
3e073bf
Revert "Avoid using the workdir"
v1v Feb 9, 2021
05af27a
Throw error and archive docker logs
v1v Feb 9, 2021
6da223e
Use x-pack e2e
v1v Feb 9, 2021
c0b7130
Avoid using the workdir since the archive does not work with full paths
v1v Feb 9, 2021
0d819cd
Move away from try/catch
v1v Feb 9, 2021
92eea8f
Add e2e
v1v Feb 9, 2021
896703d
Rename env variable
v1v Feb 9, 2021
6380624
Disable e2e for oss metricbeats
v1v Feb 9, 2021
a70a380
Revert "[CI] for testing purposes"
v1v Feb 9, 2021
984f533
Rename env variable
v1v Feb 9, 2021
7522126
[chore] for testing purposes, disable linting
v1v Feb 9, 2021
09c12ab
Upload artifacts earlier
v1v Feb 9, 2021
97e7409
Force shebang
v1v Feb 9, 2021
6931b00
debugging purposes
v1v Feb 9, 2021
5ac1c01
Enable Snapshot
v1v Feb 10, 2021
5817b85
Revert "Disable other pipelines"
v1v Feb 10, 2021
7cad28a
Restore previous configuration
v1v Feb 10, 2021
9849464
Disable e2e for the time being
v1v Feb 10, 2021
024b732
Apply suggestions from code review
v1v Feb 10, 2021
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
211 changes: 204 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipeline {
AWS_REGION = "${params.awsRegion}"
REPO = 'beats'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
DOCKERELASTIC_SECRET = 'secret/observability-team/ci/docker-registry/prod'
DOCKER_ELASTIC_SECRET = 'secret/observability-team/ci/docker-registry/prod'
DOCKER_COMPOSE_VERSION = "1.21.0"
DOCKER_REGISTRY = 'docker.elastic.co'
JOB_GCS_BUCKET = 'beats-ci-temp'
Expand Down Expand Up @@ -66,6 +66,9 @@ pipeline {
}
stage('Lint'){
options { skipDefaultCheckout() }
when {
expression { return false }
}
v1v marked this conversation as resolved.
Show resolved Hide resolved
environment {
GOFLAGS = '-mod=readonly'
}
Expand Down Expand Up @@ -259,17 +262,203 @@ def k8sTest(Map args = [:]) {
}
}

/**
* This method runs the packaging
*/
def packagingLinux(Map args = [:]) {
def PLATFORMS = [ '+all',
'linux/amd64',
'linux/386',
'linux/arm64',
'linux/armv7',
// The platforms above are disabled temporarly as crossbuild images are
// not available. See: https://github.com/elastic/golang-crossbuild/issues/71
//'linux/ppc64le',
//'linux/mips64',
//'linux/s390x',
'windows/amd64',
'windows/386',
(params.macos ? '' : 'darwin/amd64'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Let's see what we do with this

].join(' ')
withEnv([
"PLATFORMS=${PLATFORMS}"
]) {
target(args)
}
}


/**
* Upload the packages to their snapshot or pull request buckets
* @param beatsFolder beats folder
*/
def publishPackages(beatsFolder){
def bucketUri = "gs://beats-ci-artifacts/snapshots"
if (isPR()) {
bucketUri = "gs://beats-ci-artifacts/pull-requests/pr-${env.CHANGE_ID}"
}
def beatsFolderName = getBeatsName(beatsFolder)
uploadPackages("${bucketUri}/${beatsFolderName}", beatsFolder)

// Copy those files to another location with the sha commit to test them
// afterward.
bucketUri = "gs://beats-ci-artifacts/commits/${env.GIT_BASE_COMMIT}"
uploadPackages("${bucketUri}/${beatsFolderName}", beatsFolder)
}

/**
* Upload the distribution files to google cloud.
* TODO: There is a known issue with Google Storage plugin.
* @param bucketUri the buckets URI.
* @param beatsFolder the beats folder.
*/
def uploadPackages(bucketUri, beatsFolder){
googleStorageUpload(bucket: bucketUri,
credentialsId: "${JOB_GCS_CREDENTIALS}",
pathPrefix: "${beatsFolder}/build/distributions/",
pattern: "${beatsFolder}/build/distributions/**/*",
sharedPublicly: true,
showInline: true
)
}

/**
* Push the docker images for the given beat.
* @param beatsFolder beats folder
*/
def pushCIDockerImages(beatsFolder){
catchError(buildResult: 'UNSTABLE', message: 'Unable to push Docker images', stageResult: 'FAILURE') {
if (beatsFolder.endsWith('auditbeat')) {
tagAndPush('auditbeat')
} else if (beatsFolder.endsWith('filebeat')) {
tagAndPush('filebeat')
} else if (beatsFolder.endsWith('heartbeat')) {
tagAndPush('heartbeat')
} else if ("${beatsFolder}" == "journalbeat"){
tagAndPush('journalbeat')
} else if (beatsFolder.endsWith('metricbeat')) {
tagAndPush('metricbeat')
} else if ("${beatsFolder}" == "packetbeat"){
tagAndPush('packetbeat')
} else if ("${beatsFolder}" == "x-pack/elastic-agent") {
tagAndPush('elastic-agent')
}
}
}

/**
* Tag and push all the docker images for the given beat.
* @param beatName name of the Beat
*/
def tagAndPush(beatName){
def libbetaVer = env.VERSION
def aliasVersion = libbetaVer.substring(0, libbetaVer.lastIndexOf(".")) // remove third number in version

libbetaVer += "-SNAPSHOT"
aliasVersion += "-SNAPSHOT"

def tagName = "${libbetaVer}"
if (isPR()) {
tagName = "pr-${env.CHANGE_ID}"
}

// supported image flavours
def variants = ["", "-oss", "-ubi8"]
variants.each { variant ->
doTagAndPush(beatName, variant, libbetaVer, tagName)
doTagAndPush(beatName, variant, libbetaVer, "${env.GIT_BASE_COMMIT}")

if (!isPR() && aliasVersion != "") {
doTagAndPush(beatName, variant, libbetaVer, aliasVersion)
}
}
}

/**
* Tag and push the given sourceTag docker image with the tag name targetTag.
* @param beatName name of the Beat
* @param variant name of the variant used to build the docker image name
* @param sourceTag tag to be used as source for the docker tag command, usually under the 'beats' namespace
* @param targetTag tag to be used as target for the docker tag command, usually under the 'observability-ci' namespace
*/
def doTagAndPush(beatName, variant, sourceTag, targetTag) {
def sourceName = "${DOCKER_REGISTRY}/beats/${beatName}${variant}:${sourceTag}"
def targetName = "${DOCKER_REGISTRY}/observability-ci/${beatName}${variant}:${targetTag}"

def iterations = 0
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
iterations++
def status = sh(label: "Change tag and push ${targetName}", script: """
if docker image inspect "${sourceName}" &> /dev/null ; then
docker tag ${sourceName} ${targetName}
docker push ${targetName}
else
echo 'docker image ${sourceName} does not exist'
fi
""", returnStatus: true)
if ( status > 0 && iterations < 3) {
error("tag and push failed for ${beatName}, retry")
} else if ( status > 0 ) {
log(level: 'WARN', text: "${beatName} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621")
}
}
}

/**
* There is a specific folder structure in https://staging.elastic.co/ and https://artifacts.elastic.co/downloads/
* therefore the storage bucket in GCP should follow the same folder structure.
* This is required by https://github.com/elastic/beats-tester
* e.g.
* baseDir=name -> return name
* baseDir=name1/name2/name3-> return name2
*/
def getBeatsName(baseDir) {
return baseDir.replace('x-pack/', '')
}

/**
* This method runs the end 2 end testing in the same worker where the packages have been
* generated, this should help to speed up the things
*/
def e2e(Map args = [:]) {
def enabled = args.e2e?.get('enabled', false)
def entrypoint = args.e2e?.get('entrypoint')
if (!enabled) { return }
dir("${env.WORKSPACE}/src/github.com/elastic/e2e-testing") {
// TBC with the target branch if running on a PR basis.
git(branch: 'master', credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken', url: 'https://github.com/elastic/e2e-testing.git')
try {
if(isDockerInstalled()) {
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
}
def goVersionForE2E = readFile('.go-version').trim()
withEnv(["GO_VERSION=${goVersionForE2E}",
"BEATS_LOCAL_PATH=${env.WORKSPACE}/${env.BASE_DIR}"]) {
filebeat(output: "docker_logs_${entrypoint}.log", workdir: "${env.WORKSPACE}"){
sh script: ".ci/scripts/${entrypoint}", label: "Run functional tests ${entrypoint}"
}
}
} catch(e) {
error(e.toString())
} finally {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "outputs/TEST-*.xml")
archiveArtifacts allowEmptyArchive: true, artifacts: "outputs/TEST-*.xml"
}
}
}

/**
* This method runs the given command supporting two kind of scenarios:
* - make -C <folder> then the dir(location) is not required, aka by disaling isMage: false
* - mage then the dir(location) is required, aka by enabling isMage: true.
*/
def target(Map args = [:]) {
def context = args.context
def command = args.command
def context = args.context
def directory = args.get('directory', '')
def withModule = args.get('withModule', false)
def isMage = args.get('isMage', false)
def isE2E = args.e2e?.get('enabled', false)
withNode(args.label) {
withGithubNotify(context: "${context}") {
withBeatsEnv(archive: true, withModule: withModule, directory: directory, id: args.id) {
Expand All @@ -279,6 +468,11 @@ def target(Map args = [:]) {
dir(isMage ? directory : '') {
cmd(label: "${args.id?.trim() ? args.id : env.STAGE_NAME} - ${command}", script: "${command}")
}
if(isE2E) {
e2e(args)
}
publishPackages("${directory}")
pushCIDockerImages("${directory}")
}
}
}
Expand Down Expand Up @@ -354,7 +548,7 @@ def withBeatsEnv(Map args = [:], Closure body) {
"USERPROFILE=${userProfile}"
]) {
if(isDockerInstalled()) {
dockerLogin(secret: "${DOCKERELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
}
dir("${env.BASE_DIR}") {
installTools(args)
Expand Down Expand Up @@ -675,7 +869,7 @@ def dumpVariables(){
def isDockerInstalled(){
if (isUnix()) {
// TODO: some issues with macosx if(isInstalled(tool: 'docker', flag: '--version')) {
return sh(label: 'check for Docker', script: 'command -v docker', returnStatus: true)
return sh(label: 'check for Docker', script: 'command -v docker', returnStatus: true) == 0
} else {
return false
}
Expand Down Expand Up @@ -708,18 +902,21 @@ class RunCommand extends co.elastic.beats.BeatsFunction {
}
public run(Map args = [:]){
def withModule = args.content.get('withModule', false)
if(args?.content?.containsKey('make')) {
/*if(args?.content?.containsKey('make')) {
steps.target(context: args.context, command: args.content.make, directory: args.project, label: args.label, withModule: withModule, isMage: false, id: args.id)
}
if(args?.content?.containsKey('mage')) {
steps.target(context: args.context, command: args.content.mage, directory: args.project, label: args.label, withModule: withModule, isMage: true, id: args.id)
}
}*/
if(args?.content?.containsKey('packaging-linux')) {
steps.packagingLinux(context: args.context, command: args.content.get('packaging-linux'), directory: args.project, label: args.label, isMage: true, id: args.id, e2e: args.content.get('e2e'))
}/*
if(args?.content?.containsKey('k8sTest')) {
steps.k8sTest(context: args.context, versions: args.content.k8sTest.split(','), label: args.label, id: args.id)
}
if(args?.content?.containsKey('cloud')) {
steps.cloud(context: args.context, command: args.content.cloud, directory: args.project, label: args.label, withModule: withModule, dirs: args.content.dirs, id: args.id)
}
} */
}
}

Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ projects:
- "x-pack/elastic-agent"
- "x-pack/filebeat"
- "x-pack/functionbeat"
- "x-pack/heartbeat"
- "x-pack/libbeat"
- "x-pack/metricbeat"
- "x-pack/packetbeat"
- "x-pack/winlogbeat"
- "dev-tools"
##- "x-pack/heartbeat" It's not yet in the 1.0 pipeline.
##- "x-pack/journalbeat" It's not yet in the 1.0 pipeline.
##- "x-pack/journalbeat" It is not yet in the 1.0 pipeline.

## Changeset macros that are defined here and used in each specific 2.0 pipeline.
changeset:
Expand Down
4 changes: 4 additions & 0 deletions auditbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ stages:
# - "windows-7"
# branches: true ## for all the branches
# tags: true ## for all the tags
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions heartbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions journalbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ stages:
tags: true ## for all the tags
unitTest:
mage: "mage build unitTest"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
5 changes: 5 additions & 0 deletions metricbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: true
entrypoint: 'metricbeat-test.sh'
v1v marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions packetbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions winlogbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions x-pack/auditbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions x-pack/dockerlogbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ stages:
build:
mage: "mage build test"
withModule: true ## run the ITs only if the changeset affects a specific module.
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions x-pack/elastic-agent/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ stages:
# - "windows-7-32"
# branches: true ## for all the branches
# tags: true ## for all the tags
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
v1v marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions x-pack/filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ stages:
# - "windows-7-32"
# branches: true ## for all the branches
# tags: true ## for all the tags
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
4 changes: 4 additions & 0 deletions x-pack/functionbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ stages:
mage: "mage build unitTest"
platforms: ## override default labels in this specific stage.
- "windows-7-32-bit"
packaging-linux:
packaging-linux: "mage package"
e2e:
enabled: false
Loading