forked from opensearch-project/dashboards-maps
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding jenkinsfile and docker build scripts for maps (opensearch-proj…
…ect#30) Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
- Loading branch information
1 parent
1aef822
commit 91b59ce
Showing
3 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
lib = library(identifier: 'jenkins@1.0.0', retriever: modernSCM([ | ||
$class: 'GitSCMSource', | ||
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git', | ||
])) | ||
|
||
pipeline { | ||
options { | ||
timeout(time: 30, unit: 'MINUTES') | ||
throttleJobProperty( | ||
categories: [], | ||
limitOneJobWithMatchingParams: false, | ||
maxConcurrentPerNode: 0, | ||
maxConcurrentTotal: 1, | ||
paramsToUseForLimit: '', | ||
throttleEnabled: true, | ||
throttleOption: 'project', | ||
) | ||
} | ||
agent { | ||
docker { | ||
label 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host' | ||
image 'opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v2' | ||
args '-e JAVA_HOME=/opt/java/openjdk-11' | ||
alwaysPull true | ||
} | ||
} | ||
parameters { | ||
string( | ||
name: 'GIT_REFERENCE', | ||
description: 'Git branch, tag, commitid for reference to checkout commit of OpenSearch core before running the gradle check.', | ||
defaultValue: 'main', | ||
trim: true | ||
) | ||
} | ||
triggers { | ||
GenericTrigger( | ||
genericVariables: [ | ||
[key: 'ref', value: '$.ref'], | ||
], | ||
tokenCredentialId: 'jenkins-opensearch-maps-server-generic-webhook-token', | ||
causeString: 'A commit was pushed on opensearch-project/maps repository main branch causing this workflow to run', | ||
printContributedVariables: false, | ||
printPostContent: false, | ||
regexpFilterText: '$ref', | ||
regexpFilterExpression: '^(maps-server-release)-[0-9]+$' | ||
) | ||
} | ||
environment { | ||
REPO_URL="https://github.com/opensearch-project/maps" | ||
USER_BUILD_CAUSE = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') | ||
TIMER_BUILD_CAUSE = currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause') | ||
} | ||
stages { | ||
stage('Verifications and Descriptions') { | ||
steps { | ||
script { | ||
def ref_final = "${GIT_REFERENCE}" | ||
def ref_url = "${REPO_URL}/commit/${GIT_REFERENCE}" | ||
if (env.USER_BUILD_CAUSE.equals('[]') && env.TIMER_BUILD_CAUSE.equals('[]')) { | ||
ref_final = ${ref} | ||
ref_url = "${REPO_URL}/releases/tag/${ref}" | ||
println("Triggered by GitHub: ${ref_url}") | ||
|
||
currentBuild.description = """GitHub: <a href="${ref_url}">${ref_url}</a>""" | ||
} | ||
else { | ||
println("Triggered by User/Timer: ${ref_url}") | ||
currentBuild.description = """User/Timer: <a href="${ref_url}">${ref_url}</a>""" | ||
} | ||
|
||
def MAPS_PRODUCT = "opensearch-maps-server" | ||
def MAPS_VERSION = sh ( | ||
script: "cat ${MAPS_PRODUCT}/package.json | grep version | cut -d: -f2 | grep -Eo '[0-9.]+'", | ||
returnStdout: true | ||
).trim() | ||
|
||
echo("${MAPS_PRODUCT}: ${MAPS_VERSION}") | ||
|
||
dockerBuild: { | ||
build job: 'docker-build', | ||
parameters: [ | ||
string(name: 'DOCKER_BUILD_GIT_REPOSITORY', value: "${REPO_URL}"), | ||
string(name: 'DOCKER_BUILD_GIT_REPOSITORY_REFERENCE', value: "${ref_final}"), | ||
string(name: 'DOCKER_BUILD_SCRIPT_WITH_COMMANDS', value: [ | ||
'id', | ||
'pwd', | ||
"cd ${MAPS_PRODUCT}/", | ||
'ls -l', | ||
[ | ||
'bash', | ||
'build-image-single-arch.sh', | ||
"-v ${MAPS_VERSION}", | ||
"-a x64", | ||
"-f ./Dockerfile", | ||
"-p ${MAPS_PRODUCT}" | ||
].join(' ') | ||
].join(' && ')), | ||
] | ||
} | ||
dockerCopy: { | ||
build job: 'docker-copy', | ||
parameters: [ | ||
string(name: 'SOURCE_IMAGE_REGISTRY', value: 'opensearchstaging'), | ||
string(name: 'SOURCE_IMAGE', value: "${MAPS_PRODUCT}:${MAPS_VERSION}"), | ||
string(name: 'DESTINATION_IMAGE_REGISTRY', value: 'opensearchproject'), | ||
string(name: 'DESTINATION_IMAGE', value: "${MAPS_PRODUCT}:${MAPS_VERSION}") | ||
] | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
cleanWs disableDeferredWipeout: true, deleteDirs: true | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
# Copyright OpenSearch Contributors | ||
# 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. | ||
|
||
# This script is to automate the docker image creation process of OpenSearch and OpenSearch-Dashboards | ||
|
||
set -e | ||
|
||
function usage() { | ||
echo "" | ||
echo "This script is used to build the OpenSearch Docker image with single architecture (x64 or arm64). It prepares the files required by the Dockerfile in a temporary directory, then builds and tags the Docker image." | ||
echo "--------------------------------------------------------------------------" | ||
echo "Usage: $0 [args]" | ||
echo "" | ||
echo "Required arguments:" | ||
echo -e "-v VERSION\tSpecify the OpenSearch version number that you are building, e.g. '1.0.0' or '1.0.0-beta1'. This will be used to label the Docker image. If you do not use the '-o' option then this tool will download a public OPENSEARCH release matching this version." | ||
echo -e "-f DOCKERFILE\tSpecify the dockerfile full path, e.g. dockerfile/opensearch.al2.dockerfile." | ||
echo -e "-p PRODUCT\tSpecify the product, e.g. opensearch or opensearch-dashboards, make sure this is the name of your config folder and the name of your .tgz defined in dockerfile." | ||
echo -e "-a ARCHITECTURE\tSpecify one and only one architecture, e.g. x64 or arm64." | ||
echo "" | ||
echo "Optional arguments:" | ||
echo -e "-h\t\tPrint this message." | ||
echo "--------------------------------------------------------------------------" | ||
} | ||
|
||
while getopts ":hv:f:p:a:" arg; do | ||
case $arg in | ||
h) | ||
usage | ||
exit 1 | ||
;; | ||
v) | ||
VERSION=$OPTARG | ||
;; | ||
f) | ||
DOCKERFILE=$OPTARG | ||
;; | ||
p) | ||
PRODUCT=$OPTARG | ||
;; | ||
a) | ||
ARCHITECTURE=$OPTARG | ||
;; | ||
:) | ||
echo "-${OPTARG} requires an argument" | ||
usage | ||
exit 1 | ||
;; | ||
?) | ||
echo "Invalid option: -${OPTARG}" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Validate the required parameters to present | ||
if [ -z "$VERSION" ] || [ -z "$DOCKERFILE" ] || [ -z "$PRODUCT" ] || [ -z "$ARCHITECTURE" ]; then | ||
echo "You must specify '-v VERSION', '-f DOCKERFILE', '-p PRODUCT', '-a ARCHITECTURE'" | ||
usage | ||
exit 1 | ||
else | ||
echo $VERSION $DOCKERFILE $PRODUCT $ARCHITECTURE | ||
fi | ||
|
||
if [ "$PRODUCT" != "opensearch-maps-server" ] | ||
then | ||
echo "Enter either 'opensearch-maps-server' as product name for -p parameter" | ||
exit 1 | ||
else | ||
PRODUCT_ALT=`echo $PRODUCT | sed 's@-@_@g'` | ||
echo $PRODUCT $PRODUCT_ALT.yml | ||
fi | ||
|
||
if [ "$ARCHITECTURE" != "x64" ] && [ "$ARCHITECTURE" != "arm64" ] | ||
then | ||
echo "We only support 'x64' and 'arm64' as architecture name for -a parameter" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$NOTES" ] | ||
then | ||
NOTES="None" | ||
fi | ||
|
||
|
||
|
||
# Docker build | ||
docker build --build-arg VERSION=$VERSION --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` --build-arg PRODUCT=$PRODUCT -f $DOCKERFILE ./ -t opensearchstaging/$PRODUCT:$VERSION | ||
docker tag opensearchstaging/$PRODUCT:$VERSION opensearchstaging/$PRODUCT:latest | ||
docker push opensearchstaging/$PRODUCT:$VERSION | ||
docker push opensearchstaging/$PRODUCT:latest |