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

Support snapshot uploading to s3 for every build #1472

Merged
merged 21 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
37 changes: 36 additions & 1 deletion jenkins/opensearch/distribution-build.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pipeline {
}
stage('build') {
parallel {
stage('build-snapshot') {
stage('build-snapshot-x64') {
environment {
SNAPSHOT_REPO_URL = "https://aws.oss.sonatype.org/content/repositories/snapshots/"
}
Expand All @@ -52,6 +52,41 @@ pipeline {
} else {
echo "Skipping publishing snapshots, builds/opensearch/maven does not exist."
}


if (fileExists("$WORKSPACE/builds/opensearch/dist")){
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
uploadMinSnapshotsToS3()
} else {
echo "Dist folder not found, skipping snapshots upload to s3"
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
post {
always {
postCleanup()
}
}
}
stage('build-snapshot-arm64') {
agent {
docker {
label 'Jenkins-Agent-al2-arm64-c6g4xlarge-Docker-Host'
image dockerAgent.image
args dockerAgent.args
alwaysPull true
}
}
steps {
script {
git url: 'https://github.com/opensearch-project/opensearch-build.git', branch: 'main'
buildManifest(
snapshot: true
)
if (fileExists("$WORKSPACE/builds/opensearch/dist")){
uploadMinSnapshotsToS3()
} else {
echo "Dist folder not found, skipping snapshots upload to s3"
}
}
}
post {
Expand Down
50 changes: 50 additions & 0 deletions tests/jenkins/UploadMinSnapshotsToS3.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package jenkins.tests

import org.junit.*
import java.util.*
import java.nio.file.*

class UploadMinSnapshotsToS3 extends BuildPipelineTest {
private Path target;

@Before
void setUp() {
super.setUp()

binding.setVariable('WORKSPACE', 'workspace')

binding.setVariable('ARTIFACT_PROMOTION_ROLE_NAME', 'dummy_role')
binding.setVariable('AWS_ACCOUNT_ARTIFACT', '1234')
binding.setVariable('ARTIFACT_PRODUCTION_BUCKET_NAME', 'dummy_bucket')

Path source = Path.of("tests/data/opensearch-build-1.1.0.yml");
target = Path.of("workspace/builds/opensearch/manifest.yml");
Files.createDirectories(target.getParent());
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
Copy link
Member

Choose a reason for hiding this comment

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

Can we have this setup pre-built since this is a test inside tests/data ahead of time? In which case cleanup isn't required either.

Copy link
Member Author

@gaiksaya gaiksaya Jan 14, 2022

Choose a reason for hiding this comment

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

Not sure what you mean by pre-build. Can you elaborate? It is already a part of setUp()

Copy link
Member

Choose a reason for hiding this comment

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

I'll try to explain better. This code creates a folder and copies a file when setUp is run. I would just copy the file and commit it and remove this code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. Removed this code. And edited the workplace variable so that it fetched from write manifest.
Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

@dblock Can you review it once before I merge?
Thanks!


helper.registerAllowedMethod("s3Upload", [Map])
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
}
@Test
public void test() {
super.testPipeline("tests/jenkins/jobs/uploadSnapshotsToS3_Jenkinsfile")
}

@After
void after() {
super.setUp()
Files.delete(target) // Test file needs to be cleaned up
}
}

14 changes: 14 additions & 0 deletions tests/jenkins/jobs/uploadSnapshotsToS3_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pipeline {
agent none
stages {
stage('uploadMinSnapshotsToS3') {
steps {
script {
uploadMinSnapshotsToS3(
manifest: "tests/jenkins/data/opensearch-1.3.0.yml"
)
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
14 changes: 14 additions & 0 deletions tests/jenkins/jobs/uploadSnapshotsToS3_Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uploadSnapshotsToS3_Jenkinsfile.run()
uploadSnapshotsToS3_Jenkinsfile.pipeline(groovy.lang.Closure)
uploadSnapshotsToS3_Jenkinsfile.echo(Executing on agent [label:none])
uploadSnapshotsToS3_Jenkinsfile.stage(uploadMinSnapshotsToS3, groovy.lang.Closure)
uploadSnapshotsToS3_Jenkinsfile.script(groovy.lang.Closure)
uploadSnapshotsToS3_Jenkinsfile.uploadMinSnapshotsToS3({manifest=tests/jenkins/data/opensearch-1.3.0.yml})
uploadMinSnapshotsToS3.legacySCM(groovy.lang.Closure)
uploadMinSnapshotsToS3.library({identifier=jenkins@20211123, retriever=null})
uploadMinSnapshotsToS3.readYaml({file=tests/jenkins/data/opensearch-1.3.0.yml})
InputManifest.asBoolean()
uploadMinSnapshotsToS3.readYaml({file=workspace/builds/opensearch/manifest.yml})
BuildManifest.asBoolean()
uploadMinSnapshotsToS3.withAWS({role=dummy_role, roleAccount=1234, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadMinSnapshotsToS3.s3Upload({file=workspace/builds/opensearch/dist/, bucket=dummy_bucket, path=snapshots/core/opensearch/1.1.0/opensearch-min-1.1.0-linux-x64-latest.tar.gz})
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions vars/uploadMinSnapshotsToS3.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void call(Map args = [:]) {
def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))
String manifest = args.manifest ?: "manifests/${INPUT_MANIFEST}"

def inputManifest = lib.jenkins.InputManifest.new(readYaml(file: manifest))
def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: "$WORKSPACE/builds/${inputManifest.build.getFilename()}/manifest.yml"))
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
version = buildManifest.build.version
architecture = buildManifest.build.architecture
platform = buildManifest.build.platform
minArtifactName = "opensearch-min-${version}-${platform}-${architecture}-latest.tar.gz"

gaiksaya marked this conversation as resolved.
Show resolved Hide resolved

withAWS(role: "${ARTIFACT_PROMOTION_ROLE_NAME}", roleAccount: "${AWS_ACCOUNT_ARTIFACT}", duration: 900, roleSessionName: 'jenkins-session') {
s3Upload(file: "$WORKSPACE/builds/opensearch/dist/", bucket: "${ARTIFACT_PRODUCTION_BUCKET_NAME}", path: "snapshots/core/opensearch/${version}/${minArtifactName}")
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
}
gaiksaya marked this conversation as resolved.
Show resolved Hide resolved
}