-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
148 lines (146 loc) · 6.79 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
pipeline {
agent none
parameters {
string(
name: 'Branch',
defaultValue: 'main',
description: 'The name of the git branch or commit ID to deploy.',
trim: true,
)
extendedChoice(
name: 'Environment',
defaultValue: 'analysisworkspace-dev',
description: 'The environment to deploy to.',
type: 'PT_RADIO',
visibleItemCount: 3,
value: '' +
'analysisworkspace-dev,' +
'data-workspace-staging,' +
'jupyterhub',
descriptionPropertyValue: '' +
'<strong>🌱 dev</strong>: https://analysisworkspace.dev.uktrade.io/,' +
'<strong>🎪 staging</strong>: https://data.trade.staging.uktrade.digital/,' +
'<strong>🏆 production</strong>: https://data.trade.gov.uk/',
)
extendedChoice(
name: 'Component',
defaultValue: 'python-jupyterlab|jupyterlab-python|master',
description: 'The component to deploy, matching the stage name of the Dockerfile.',
type: 'PT_RADIO',
visibleItemCount: 10,
value: '' +
'python-jupyterlab|jupyterlab-python|master,' +
'python-theia|theia|master,' +
'python-visualisation|visualisation-base|python,' +
'rv4-cran-binary-mirror|mirrors-sync-cran-binary-rv4|master,' +
'rv4-rstudio|rstudio-rv4|master,' +
'rv4-visualisation|visualisation-base|rv4,' +
'pgadmin|pgadmin|master,' +
'remote-desktop|remotedesktop|master,' +
's3sync|s3sync|master,' +
'metrics|metrics|master',
descriptionPropertyValue: '' +
'<strong>python-jupyterlab</strong>: JupyterLab,' +
'<strong>python-theia</strong>: Theia,' +
'<strong>python-visualisation</strong>: Base for Python visualisations,' +
'<strong>rv4-cran-binary-mirror</strong>: Image for CRAN binary mirror pipeline,' +
'<strong>rv4-rstudio</strong>: RStudio (R version 4),' +
'<strong>rv4-visualisation</strong>: Base for R version 4 visualisations,' +
'<strong>pgadmin</strong>: pgAdmin,' +
'<strong>remote-desktop</strong>: Remote desktop,' +
'<strong>s3sync</strong>: Sidecar for syncing Your Files,' +
'<strong>metrics</strong>: Sidecar for extracting metrics so tools automatically shut down'
)
extendedChoice(
name: 'Caching',
defaultValue: '',
description: 'By default layers pushed in the 12 hours before a build are used as a cache.',
type: 'PT_CHECKBOX',
visibleItemCount: 1,
value: 'skip',
descriptionPropertyValue: 'Ignore any cached layers and force a rebuild from the top of the Dockerfile. If you\'re not sure, leave this unticked.',
)
}
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 {
script {
(dockerTarget, dockerRepoSuffix, dockerTag) = params.Component.tokenize('|')
cacheTTL = params.Caching == 'skip' ? '0' : '12h'
def Map<String, String> envDescriptions = [
'analysisworkspace-dev': '🌱 dev',
'data-workspace-staging': '🎪 staging',
'jupyterhub': '🏆 production',
]
currentBuild.displayName = envDescriptions[params.Environment] + "[${dockerTarget}]"
currentBuild.description = "Branch: ${params.Branch}"
}
checkout([
$class: 'GitSCM',
branches: [[name: params.Branch]],
userRemoteConfigs: [[url: 'https://github.com/uktrade/data-workspace-tools.git']]
])
container(name: 'builder', shell: '/busybox/sh') {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'DATASCIENCE_ECS_DEPLOY']]) {
withCredentials([string(credentialsId: 'DATA_INFRASTRUCTURE_PROD_ACCOUNT_ID', variable: 'DATA_INFRASTRUCTURE_PROD_ACCOUNT_ID')]) {
withEnv([
"PATH+EXTRA=/busybox:/kaniko",
"Environment=${params.Environment}",
"dockerTarget=${dockerTarget}",
"dockerRepoSuffix=${dockerRepoSuffix}",
"dockerTag=${dockerTag}",
"cacheTTL=${cacheTTL}",
]) {
sh '''
#!/busybox/sh
/kaniko/executor \
--context ${WORKSPACE} \
--dockerfile ${WORKSPACE}/Dockerfile \
--target=${dockerTarget} \
--skip-unused-stages=true \
--cache=true \
--cache-ttl=${cacheTTL} \
--cache-copy-layers=true \
--cache-run-layers=true \
--cache-repo=${DATA_INFRASTRUCTURE_PROD_ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${Environment}-${dockerRepoSuffix} \
--destination=${DATA_INFRASTRUCTURE_PROD_ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${Environment}-${dockerRepoSuffix}:${dockerTag}
'''
}}}
}
}
}
}
}