-
Notifications
You must be signed in to change notification settings - Fork 22
/
ubuntu.Jenkinsfile
117 lines (112 loc) · 4.92 KB
/
ubuntu.Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Parameters:
// - ENVIRONMENT
// - VERSION
// - GENESIS_PATH
// - UBUNTU_VERSION
// - GHC_VERSION
@Library('concordium-pipelines') _
Map grpc2_port = [
mainnet: "20000",
testnet: "20001",
stagenet: "20500",
flynet: "20002"
]
Map listen_port = [
mainnet: "8888",
testnet: "8889",
stagenet: "9500",
flynet: "8890"
]
pipeline {
// Use jenkins-worker, as it has the keys for pushing to AWS.
agent { label 'jenkins-worker' }
environment {
// Extract version from code
CODE_VERSION = """${sh(
returnStdout: true,
script: '''awk '/version = / { print substr($3, 2, length($3)-2); exit }' concordium-node/Cargo.toml'''
)}""".trim()
// Use code version if the version param has not been set
OUT_VERSION = """${sh(
returnStdout: true,
script: "[[ -z '${VERSION}' ]] && echo '${CODE_VERSION}' || echo '${VERSION}'"
)}""".trim()
// Use default genesis path for each environment, if the GENESIS_PATH param has not been set.
// Uses library function defined here: https://github.com/Concordium/concordium-infra-jenkins-library/blob/master/vars/defaultGenesis.groovy
GENESIS_FULL_PATH = defaultGenesis(ENVIRONMENT, GENESIS_PATH)
DOMAIN = concordiumDomain(ENVIRONMENT)
BUILD_FILE = "concordium-${ENVIRONMENT}-node_${CODE_VERSION}_amd64.deb"
OUTFILE = "s3://distribution.${DOMAIN}/deb/concordium-${ENVIRONMENT}-node_${OUT_VERSION}_amd64.deb"
GENESIS_HASH_PATH = "genesis/${GENESIS_FULL_PATH}/genesis_hash"
GENESIS_DAT_FILE = "genesis/${GENESIS_FULL_PATH}/genesis.dat"
ENVIRONMENT_CAP = environment.capitalize()
DATA_DIR = "./scripts/distribution/ubuntu-packages/template/data/"
GRPC2_PORT = "${grpc2_port[environment]}"
LISTEN_PORT = "${listen_port[environment]}"
STATIC_BINARIES_IMAGE_TAG = "${BUILD_TAG}"
}
stages {
stage('Precheck') {
steps {
// Fail the job if the OUTFILE already exists in S3.
sh '''\
# Fail if file already exists
totalFoundObjects=$(aws s3 ls "$OUTFILE" --summarize | grep "Total Objects: " | sed "s/[^0-9]*//g")
if [ "$totalFoundObjects" -ne "0" ]; then
echo "$OUTFILE already exists"
false
fi
'''.stripIndent()
}
}
stage('Build static-node-binaries') {
steps {
sh './scripts/static-binaries/build-static-binaries.sh'
}
}
stage('Checkout genesis') {
steps {
dir('genesis') {
git credentialsId: 'jenkins-github-ssh', url: '[email protected]:Concordium/concordium-infra-genesis-data.git'
}
// Copy genesis.dat file into place in data dir, and rename.
sh '''
mkdir ${DATA_DIR}
cp ${GENESIS_DAT_FILE} ${DATA_DIR}/${ENVIRONMENT}-genesis.dat
'''
}
}
stage('Build node deb') {
steps {
sh '''
docker build\
--build-arg ubuntu_version=${UBUNTU_VERSION}\
--build-arg static_binaries_image_tag=${STATIC_BINARIES_IMAGE_TAG}\
--build-arg build_env_name=${ENVIRONMENT_CAP}\
--build-arg build_env_name_lower=${ENVIRONMENT}\
--build-arg build_catchup_url=https://catchup.${DOMAIN}/blocks.idx\
--build-arg build_genesis_hash=$(cat ${GENESIS_HASH_PATH} | tr -cd "[:alnum:]")\
--build-arg build_collector_backend_url=https://dashboard.${DOMAIN}/nodes/post\
--build-arg build_grpc2_listen_port=${GRPC2_PORT}\
--build-arg build_listen_port=${LISTEN_PORT}\
--build-arg build_bootstrap=bootstrap.${DOMAIN}:8888\
-f ./scripts/distribution/ubuntu-packages/deb.Dockerfile\
-t ${ENVIRONMENT}-deb ./scripts/distribution/ubuntu-packages/ --no-cache
'''
}
}
stage('Publish') {
steps {
// Copy out the build artifacts. We create a temporary container and use docker
// cp. This makes the output artifacts have correct file permissions (they are
// owned by the user who ran the script).
sh '''
id=$(docker create ${ENVIRONMENT}-deb)
docker cp $id:/out ${ENVIRONMENT}-build
docker rm $id
aws s3 cp ${ENVIRONMENT}-build/${BUILD_FILE} ${OUTFILE} --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
'''
}
}
}
}