Skip to content

Commit

Permalink
Merge pull request #49 from VirgilSecurity/jenkins_build
Browse files Browse the repository at this point in the history
Jenkins build
  • Loading branch information
AlexeyStolyarov authored May 20, 2020
2 parents a43a855 + 5c0932f commit 4944e5d
Showing 1 changed file with 162 additions and 0 deletions.
162 changes: 162 additions & 0 deletions jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@

pipeline {
agent none
environment {
CRYPTO_C_BASE_FOLDER = "virgil-crypto-c"
DOCKER_CNT_NAME = "ccrypto-builder"
DOCKER_CNT_NAME_LEGACY = "ccrypto-builder-legacy"
credentialsId = "1259d404-cffc-48d4-9961-26d5366d7247"
GIT_WORK_BRANCH = "crypto_library_updates_${new Date().format('yyyy-MM-dd')}"
}

stages {
stage('Grab SCM: virgil-sdk-go') {
agent { node { label "build-docker"} }
steps {
script {
cleanWs()
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${credentialsId}", url: 'https://github.com/VirgilSecurity/virgil-sdk-go']]])
sh "git branch -a | grep origin/${GIT_WORK_BRANCH} && git checkout ${GIT_WORK_BRANCH} || git checkout -b ${GIT_WORK_BRANCH}"
sh "git branch -a | grep origin/${GIT_WORK_BRANCH} && git pull && git merge origin/master || true"
}
}
}
stage('Grab SCM: virgil-crypto-c') {
agent { node { label "build-docker"} }
steps {
script {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${CRYPTO_C_BASE_FOLDER}"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${credentialsId}", url: 'https://github.com/VirgilSecurity/virgil-crypto-c/']]])
}
}
}
stage("Copy files from virgil-crypto-c") {
agent { node { label "build-docker"} }
steps {
script {
sh "rm -rf crypto/wrapper/{phe,foundation,pkg}"
sh "mkdir -p crypto/wrapper/pkg/{darwin_amd64,linux_amd64,linux_amd64__legacy_os,windows_amd64}"

sh "cp -r ${CRYPTO_C_BASE_FOLDER}/wrappers/go/{phe,foundation} crypto/wrapper/"
sh '''
for i in $(grep -R 'virgil/foundation' crypto/wrapper/{phe,foundation} | cut -d ':' -f 1); do
echo $i
sed -i 's|virgil/foundation|github.com/VirgilSecurity/virgil-sdk-go/v6/crypto/wrapper/foundation|g' $i
done;
'''
stash includes: "crypto/wrapper/**/*", name: 'myStash'
}
}
}
stage("Build Wind and MacOS") {
parallel {
stage("Build Windows"){
agent { node { label "build-win10"} }
steps {
cleanWs()
unstash "myStash"
dir("crypto/wrapper/build"){
bat 'powershell ./build_c_crypto.ps1'
}
stash includes: "crypto/wrapper/pkg/windows_amd64/**/*", name: 'myStash-windows'
}
}
stage("Build MacOS"){
agent { node { label "build-os-x"} }
steps {
cleanWs()
unstash "myStash"
sh "./crypto/wrapper/build/build_c_crypto.sh"
stash includes: "crypto/wrapper/pkg/darwin_amd64/**/*", name: 'myStash-macOS'
}
}
}
}
stage("copy to main host") {
agent { node { label "build-docker"} }
steps {
script {
unstash "myStash-macOS"
unstash "myStash-windows"
}
}
}
stage("Docker: build") {
agent { node { label "build-docker"} }
steps {
script {
dir('crypto/wrapper/build') {
sh "docker build -t ccrypto ."
}
}
}
}
stage("Docker: build libraries") {
agent { node { label "build-docker"} }
steps {
script {
sh "docker ps -a | grep ${DOCKER_CNT_NAME} && docker rm -f ${DOCKER_CNT_NAME} || true"
sh "chmod +x crypto/wrapper/build/build_c_crypto.sh"
sh "docker run -t --rm -v ${workspace}:/app --name ${DOCKER_CNT_NAME} ccrypto \
/app/crypto/wrapper/build/build_c_crypto.sh"
}
}
}
stage("Docker: build legacy") {
agent { node { label "build-docker"} }
steps {
script {
dir('crypto/wrapper/build') {
sh "docker build -t ccrypto-legacy -f Dockerfile_legacy ."
}
}
}
}
stage("Docker: build libraries legacy") {
agent { node { label "build-docker"} }
steps {
script {
sh "docker ps -a | grep ${DOCKER_CNT_NAME_LEGACY} && docker rm -f ${DOCKER_CNT_NAME_LEGACY} || true"
sh "chmod +x crypto/wrapper/build/build_c_crypto.sh"
sh "docker run -t --rm -v ${workspace}:/app --name ${DOCKER_CNT_NAME_LEGACY} ccrypto-legacy \
/app/crypto/wrapper/build/build_c_crypto.sh"
}
}
}
stage("Update git") {
agent { node { label "build-docker"} }
steps {
script {
sh '''
git add crypto/wrapper/{foundation,phe,pkg}
git commit -m "Crypto library update"
'''

withCredentials([usernamePassword(credentialsId: "${credentialsId}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/VirgilSecurity/virgil-sdk-go ${GIT_WORK_BRANCH}"
}
}
}
}
stage("Create PR") {
agent { node { label "build-docker"} }
steps {
script {
withCredentials([usernamePassword(credentialsId: "${credentialsId}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh """
curl -D- -u ${GIT_USERNAME}:${GIT_PASSWORD} https://api.github.com/repos/VirgilSecurity/virgil-sdk-go/pulls \
--header 'Content-Type: application/json' -X POST \
--data '{
"title": "Crypto library update from ${GIT_WORK_BRANCH}",
"body": "Please pull these awesome changes in!",
"head": "${GIT_WORK_BRANCH}",
"base": "master"
}'
"""
}
}
}
}
}

}

0 comments on commit 4944e5d

Please sign in to comment.