forked from blockscout/frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
153 lines (145 loc) · 9.23 KB
/
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
pipeline {
agent any
tools {
dockerTool 'docker'
}
environment {
IMAGENAME = 'blockscout-v2' // Set the image name as an environment variable
}
parameters {
choice(name: 'BUILD_TYPE', choices: ['patch', 'minor', 'major'], description: 'Select version to build in develop')
choice(name: 'NET', choices: ['stagenet', 'testnet', 'mainnet'], description: 'Select net type to build')
choice(name: 'CLOUD', choices: ['AZURE', 'GCP', 'AWS'], description: 'Select cloud operator to push docker image')
}
stages {
stage('GCP Release') {
when {
expression { return params.CLOUD == 'GCP' }
}
environment {
INCREMENT_TYPE = "${params.BUILD_TYPE}"
TAG = "${params.NET}"
GCR = "asia-south1-docker.pkg.dev/prod-dojima/${params.NET}"
}
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: 'dojimanetwork', keyFileVariable: 'SSH_KEY'),
string(credentialsId: 'gcloud-access-token', variable: 'GCLOUD_ACCESS_TOKEN'),
string(credentialsId: 'ci-registry-user', variable: 'CI_REGISTRY_USER'),
string(credentialsId: 'ci-registry', variable: 'CI_REGISTRY'),
string(credentialsId: 'ci-pat', variable: 'CR_PAT')]) {
// Set the SSH key for authentication
withEnv(["GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i ${env.SSH_KEY}"]) {
echo "Selected action: $INCREMENT_TYPE, $TAG, $GCR"
sh 'gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin --password-stdin https://$GCR'
sh 'make release'
}
}
}
}
}
stage('AZURE Release') {
when {
expression { return params.CLOUD == 'AZURE' }
}
environment {
INCREMENT_TYPE = "${params.BUILD_TYPE}"
}
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: 'dojimanetwork', keyFileVariable: 'SSH_KEY'),
string(credentialsId: 'azure-stagenet-cr-token', variable: 'AZURE_STAGENET_ACCESS_TOKEN'),
string(credentialsId: 'azure-mainnet-cr-token', variable: 'AZURE_MAINNET_ACCESS_TOKEN'),
string(credentialsId: 'azure-testnet-cr-token', variable: 'AZURE_TESTNET_ACCESS_TOKEN'),
string(credentialsId: 'ci-registry-user', variable: 'CI_REGISTRY_USER'),
string(credentialsId: 'ci-registry', variable: 'CI_REGISTRY'),
string(credentialsId: 'ci-pat', variable: 'CR_PAT'),
string(credentialsId: 'DOCKER_HUB_CREDENTIALS_ID', variable: 'DOCKER_PASSWORD')]) {
// Set the SSH key for authentication
withEnv(["GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i ${env.SSH_KEY}"]) {
// Declaring env var here gives flexibility to modify within the scope
env.AZURE = "${params.NET}.azurecr.io"
def _azure = "${params.NET}.azurecr.io"
def _net = "${params.NET}"
env.TAG = "${params.NET}"
if (params.NET == "stagenet") {
sh 'echo $AZURE_STAGENET_ACCESS_TOKEN | docker login -u stagenet --password-stdin $AZURE'
} else if (params.NET == "mainnet") {
sh 'echo $AZURE_MAINNET_ACCESS_TOKEN | docker login -u mainnet --password-stdin $AZURE'
} else if (params.NET == "testnet") {
_azure = "${params.NET}1.azurecr.io"
sh """
echo $AZURE_TESTNET_ACCESS_TOKEN | docker login -u testnet1 --password-stdin $_azure
"""
}
// Overriding env var
env.AZURE = _azure
sh "/usr/bin/make azure-release AZURE=${env.AZURE} INCREMENT_TYPE=${params.BUILD_TYPE}"
// Capture environment variables from Makefile after release
def buildInfo = sh(script: "make print-vars INCREMENT_TYPE=${params.BUILD_TYPE}", returnStdout: true).trim().split('\n')
def envVars = [:]
buildInfo.each {
def (key, value) = it.split('=')
envVars[key.trim()] = value.trim()
}
// Assign values to Jenkins environment variables
env.GITREF = envVars['GITREF']
env.VERSION = envVars['VERSION']
// Verify the captured environment variables
echo "Captured GITREF: ${env.GITREF}"
echo "Captured VERSION: ${env.VERSION}"
def imageDigest = sh(
script: "docker inspect --format='{{index .RepoDigests 0}}' ${env.AZURE}/${IMAGENAME}:${GITREF}_${VERSION} | awk -F'@' '{print \$2}'",
returnStdout: true
).trim()
echo "Image Digest: ${imageDigest}"
if (params.NET == 'mainnet') {
withCredentials([string(credentialsId: 'Gitops_PAT', variable: 'GIT_TOKEN')]) {
sh """
cd ${WORKSPACE}
git clone https://${GIT_TOKEN}@github.com/dojimanetwork/helm_charts.git -b azure_master
cd helm_charts
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*tag:\\).*|\\1 ${GITREF}_${VERSION}|" dependency_charts/blockscout-v2-frontend/values.yaml
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*hash:\\).*|\\1 \"${imageDigest}\"|" dependency_charts/blockscout-v2-frontend/values.yaml
git add .
git commit -m "Update mainnet_hash with image digest ${imageDigest}"
git push origin azure_master
cd ${WORKSPACE} && rm -r helm_charts
"""
}
} else if (params.NET == "testnet") {
withCredentials([string(credentialsId: 'Gitops_PAT', variable: 'GIT_TOKEN')]) {
sh """
cd ${WORKSPACE}
git clone https://${GIT_TOKEN}@github.com/dojimanetwork/helm_charts.git -b azure_develop
cd helm_charts
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*tag:\\).*|\\1 ${GITREF}_${VERSION}|" dependency_charts/blockscout-v2-frontend/values.yaml
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*hash:\\).*|\\1 \"${imageDigest}\"|" dependency_charts/blockscout-v2-frontend/values.yaml
git add .
git commit -m "Update testnet_hash with image digest ${imageDigest}"
git push origin azure_develop
cd ${WORKSPACE} && rm -r helm_charts
"""
}
} else if (params.NET == "stagenet") {
withCredentials([string(credentialsId: 'Gitops_PAT', variable: 'GIT_TOKEN')]) {
sh """
cd ${WORKSPACE}
git clone https://${GIT_TOKEN}@github.com/dojimanetwork/helm_charts.git -b azure_stagenet
cd helm_charts
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*tag:\\).*|\\1 ${GITREF}_${VERSION}|" dependency_charts/blockscout-v2-frontend/values.yaml
sed -i "/^ frontend:/,/^ frontend:/s|^\\(\\s*hash:\\).*|\\1 \"${imageDigest}\"|" dependency_charts/blockscout-v2-frontend/values.yaml
git add .
git commit -m "Update stagenet_hash with image digest ${imageDigest}"
git push origin azure_stagenet
cd ${WORKSPACE} && rm -r helm_charts
"""
}
}
}
}
}
}
}
}
}