From c8ef0b4b0b2cd4a87432fd3a97eebd3017e51ca1 Mon Sep 17 00:00:00 2001 From: Iris Garcia Date: Tue, 10 Sep 2019 15:13:47 +0200 Subject: [PATCH 1/4] Adds Jenkinsfile_master pipeline. --- Jenkinsfile_master | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Jenkinsfile_master diff --git a/Jenkinsfile_master b/Jenkinsfile_master new file mode 100644 index 0000000..3fbe685 --- /dev/null +++ b/Jenkinsfile_master @@ -0,0 +1,101 @@ +pipeline { + agent none + + options { + timestamps() + disableConcurrentBuilds() + ansiColor('xterm') + skipDefaultCheckout() + } + + environment { + aws_access_id = credentials('aws-jenkins-access-id') + aws_access_key = credentials('aws-jenkins-access-key') + } + + stages { + stage('Generate lightchain binary') { + agent { + docker { + image 'techknowlogick/xgo:latest' + args '-u root:root --entrypoint=\'\'' + } + } + steps { + script { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/master']], + doGenerateSubmoduleConfigurations: false, + extensions: [], + submoduleCfg: [], + userRemoteConfigs: [[credentialsId: 'devops', url: 'git@github.com:lightstreams-network/lightchain.git']] + ]) + def repo_path = "/var/jenkins_home/workspace/lightchain.master" + def go_ls_path = "/go/src/github.com/lightstreams-network/lightchain" + def commands = [ + // Install curl + "apt update && apt install -y curl", + // Install dep + "curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh", + // lightchain dependencies + "mkdir -p /go/src/github.com/lightstreams-network", + "cp -r ${repo_path} ${go_ls_path}", + "cd ${go_ls_path} && /go/bin/dep ensure", + // Cross compile for linux and OSX + "cd ${go_ls_path} && xgo --targets=linux/amd64,darwin-10.10/amd64 ./cmd/lightchain", + // Copy to shared folder so it is visible by other stages + "cp /build/lightchain-linux-amd64 ${repo_path}/", + "cp /build/lightchain-10.10-amd64 ${repo_path}/lightchain-osx" + ] + + for (command in commands) { + sh "${command}" + } + } + } + } + stage('AWS tag current version') { + agent { + docker { + image 'python:3.7.4' + args '-u root:root' + } + } + steps { + script { + def repo_path = "/var/jenkins_home/workspace/lightchain.master" + // Get current latest binary + sh 'wget "https://s3.eu-central-1.amazonaws.com/lightstreams-public/lightchain/latest/lightchain-linux-amd64" -O /tmp/lightchain' + sh "chmod +x /tmp/lightchain" + def latest_version = "v" + sh ( + script: "/tmp/lightchain version | cut -d' ' -f2", + returnStdout: true + ).replaceAll("\n", "") + // def version_match = (latest_version_str =~ /([\d.])+/) + // def latest_version = "v" + version_match[0].getAt(0) + + def aws_bin = "/root/.local/bin/aws" + def s3_bucket = "s3://lightstreams-public/lightchain" + def commands = [ + // Setup awscli + "pip3 install awscli --upgrade --user", + "mkdir /root/.aws", + "echo '[default]\nregion=eu-central-1\noutput=json' > /root/.aws/config", + "echo '[default]\naws_access_key_id=${env.aws_access_id}\naws_secret_access_key=${env.aws_access_key}' > /root/.aws/credentials", + // Move current latest to its version folder + "${aws_bin} s3 cp ${s3_bucket}/latest/lightchain-linux-amd64 ${s3_bucket}/${latest_version}/lightchain-linux-amd64 --acl public-read", + "${aws_bin} s3 cp ${s3_bucket}/latest/lightchain-osx ${s3_bucket}/${latest_version}/lightchain-osx --acl public-read", + // Upload the new latest versions + "${aws_bin} s3 cp ${repo_path}/lightchain-linux-amd64 ${s3_bucket}/latest/lightchain-linux-amd64 --acl public-read", + "${aws_bin} s3 cp ${repo_path}/lightchain-osx ${s3_bucket}/latest/lightchain-osx --acl public-read" + ] + + for (command in commands) { + sh "${command}" + } + } + } + } + } +} From 2912777128dc76b9203c4b1e9ab2c0afc9c67469 Mon Sep 17 00:00:00 2001 From: Iris Garcia Date: Wed, 11 Sep 2019 11:36:45 +0200 Subject: [PATCH 2/4] Updates Jenkinsfile_master to Jenkinsfile_tag. --- Jenkinsfile_master => Jenkinsfile_tag | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename Jenkinsfile_master => Jenkinsfile_tag (88%) diff --git a/Jenkinsfile_master b/Jenkinsfile_tag similarity index 88% rename from Jenkinsfile_master rename to Jenkinsfile_tag index 3fbe685..4055e68 100644 --- a/Jenkinsfile_master +++ b/Jenkinsfile_tag @@ -25,7 +25,7 @@ pipeline { script { checkout([ $class: 'GitSCM', - branches: [[name: '*/master']], + branches: [[name: "${params.TAG}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], @@ -83,10 +83,12 @@ pipeline { "mkdir /root/.aws", "echo '[default]\nregion=eu-central-1\noutput=json' > /root/.aws/config", "echo '[default]\naws_access_key_id=${env.aws_access_id}\naws_secret_access_key=${env.aws_access_key}' > /root/.aws/credentials", - // Move current latest to its version folder - "${aws_bin} s3 cp ${s3_bucket}/latest/lightchain-linux-amd64 ${s3_bucket}/${latest_version}/lightchain-linux-amd64 --acl public-read", - "${aws_bin} s3 cp ${s3_bucket}/latest/lightchain-osx ${s3_bucket}/${latest_version}/lightchain-osx --acl public-read", - // Upload the new latest versions + + // Upload the new tag + "${aws_bin} s3 cp ${repo_path}/lightchain-linux-amd64 ${s3_bucket}/${params.TAG}/lightchain-linux-amd64 --acl public-read", + "${aws_bin} s3 cp ${repo_path}/lightchain-osx ${s3_bucket}/${params.TAG}/lightchain-osx --acl public-read", + + // Upload the new tag as latest "${aws_bin} s3 cp ${repo_path}/lightchain-linux-amd64 ${s3_bucket}/latest/lightchain-linux-amd64 --acl public-read", "${aws_bin} s3 cp ${repo_path}/lightchain-osx ${s3_bucket}/latest/lightchain-osx --acl public-read" ] From 021c81a4a819e88b8f39fbc727455d124cf95187 Mon Sep 17 00:00:00 2001 From: Iris Garcia Date: Wed, 11 Sep 2019 11:48:15 +0200 Subject: [PATCH 3/4] Fixes Jenkinsfile_tag pipeline. --- Jenkinsfile_tag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile_tag b/Jenkinsfile_tag index 4055e68..c4f15cf 100644 --- a/Jenkinsfile_tag +++ b/Jenkinsfile_tag @@ -31,7 +31,7 @@ pipeline { submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'devops', url: 'git@github.com:lightstreams-network/lightchain.git']] ]) - def repo_path = "/var/jenkins_home/workspace/lightchain.master" + def repo_path = "/var/jenkins_home/workspace/lightchain.tag" def go_ls_path = "/go/src/github.com/lightstreams-network/lightchain" def commands = [ // Install curl @@ -64,7 +64,7 @@ pipeline { } steps { script { - def repo_path = "/var/jenkins_home/workspace/lightchain.master" + def repo_path = "/var/jenkins_home/workspace/lightchain.tag" // Get current latest binary sh 'wget "https://s3.eu-central-1.amazonaws.com/lightstreams-public/lightchain/latest/lightchain-linux-amd64" -O /tmp/lightchain' sh "chmod +x /tmp/lightchain" From ed86d532746584e91b91584d7b940755e0500200 Mon Sep 17 00:00:00 2001 From: Iris Garcia Date: Wed, 11 Sep 2019 11:56:04 +0200 Subject: [PATCH 4/4] Fixes Jenkinsfile_tag osx binary name. --- Jenkinsfile_tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile_tag b/Jenkinsfile_tag index c4f15cf..b267ab6 100644 --- a/Jenkinsfile_tag +++ b/Jenkinsfile_tag @@ -46,7 +46,7 @@ pipeline { "cd ${go_ls_path} && xgo --targets=linux/amd64,darwin-10.10/amd64 ./cmd/lightchain", // Copy to shared folder so it is visible by other stages "cp /build/lightchain-linux-amd64 ${repo_path}/", - "cp /build/lightchain-10.10-amd64 ${repo_path}/lightchain-osx" + "cp /build/lightchain-darwin-10.10-amd64 ${repo_path}/lightchain-osx" ] for (command in commands) {