-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdev.Jenkinsfile
120 lines (114 loc) · 4.25 KB
/
dev.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
pipeline {
agent none
parameters {
string(name: 'GIT_COMMIT', defaultValue: 'master', description: 'Commit SHA or origin branch to deploy')
}
stages {
stage('build') {
agent {
kubernetes {
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
job: ${env.JOB_NAME}
job_id: ${env.BUILD_NUMBER}
spec:
nodeSelector:
role: worker
containers:
- name: builder
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
volumes:
- name: jenkins-docker-cfg
configMap:
name: docker-config
items:
- key: config.json
path: config.json
"""
}
}
steps {
checkout([
$class: 'GitSCM',
branches: [[name: params.GIT_COMMIT]],
userRemoteConfigs: [[url: 'https://github.com/uktrade/data-workspace-frontend.git']]
])
script {
pullRequestNumber = sh(
script: "git log -1 --pretty=%B | grep 'Merge pull request' | cut -d ' ' -f 4 | tr -cd '[[:digit:]]'",
returnStdout: true
).trim()
currentBuild.displayName = "#${env.BUILD_ID} - PR #${pullRequestNumber}"
}
lock("data-workspace-build-admin") {
container(name: 'builder', shell: '/busybox/sh') {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'DATASCIENCE_ECS_DEPLOY']]) {
withEnv(['PATH+EXTRA=/busybox:/kaniko']) {
sh """
#!/busybox/sh
/kaniko/executor \
--dockerfile ${env.WORKSPACE}/Dockerfile \
-c ${env.WORKSPACE} \
--destination=165562107270.dkr.ecr.eu-west-2.amazonaws.com/analysisworkspace-dev-admin:${params.GIT_COMMIT} \
--destination=165562107270.dkr.ecr.eu-west-2.amazonaws.com/data-workspace-staging-admin:${params.GIT_COMMIT} \
--destination=165562107270.dkr.ecr.eu-west-2.amazonaws.com/jupyterhub-admin:${params.GIT_COMMIT} \
--cache=true \
--cache-repo=165562107270.dkr.ecr.eu-west-2.amazonaws.com/data-workspace-admin-cache \
--skip-unused-stages=true \
--target=live
"""
}
}
}
}
}
}
stage('release: dev') {
parallel {
stage('release: data-workspace') {
steps {
ecs_pipeline_admin("analysisworkspace-dev", params.GIT_COMMIT)
}
}
stage('release: data-workspace-celery') {
steps {
ecs_pipeline_celery("analysisworkspace-dev", params.GIT_COMMIT)
}
}
}
}
}
}
void ecs_pipeline_admin(cluster, version) {
lock("data-workspace-ecs-pipeline-${cluster}-admin") {
build job: "ecs-pipeline", parameters: [
string(name: "Image", value: "165562107270.dkr.ecr.eu-west-2.amazonaws.com/${cluster}-admin:${version}"),
string(name: "Cluster", value: cluster),
string(name: "Service", value: "${cluster}-admin"),
string(name: "CredentialsId", value: "DATASCIENCE_ECS_DEPLOY"),
string(name: "EcsPipelineRepository", value: "public.ecr.aws/j9o7k4h4/ecs-pipeline:latest")
]
}
}
void ecs_pipeline_celery(cluster, version) {
lock("data-workspace-ecs-pipeline-${cluster}-celery") {
build job: "ecs-pipeline", parameters: [
string(name: "Image", value: "165562107270.dkr.ecr.eu-west-2.amazonaws.com/${cluster}-admin:${version}"),
string(name: "Cluster", value: cluster),
string(name: "Service", value: "${cluster}-admin-celery"),
string(name: "CredentialsId", value: "DATASCIENCE_ECS_DEPLOY"),
string(name: "EcsPipelineRepository", value: "public.ecr.aws/j9o7k4h4/ecs-pipeline:latest")
]
}
}