forked from mesosphere/dcos-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
158 lines (146 loc) · 4.39 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
154
155
156
157
158
#!/usr/bin/env groovy
boolean isMain = env.BRANCH_NAME == "main"
boolean isBeta = env.BRANCH_NAME == "beta"
def bucket = isMain ? "preview"
: isBeta ? "staging"
: "pr-${env.CHANGE_ID}"
def hostname = isMain ? "dev-docs.d2iq.com"
: "docs-d2iq-com-pr-${env.CHANGE_ID}.s3-website-us-west-2.amazonaws.com"
pipeline {
agent { label "mesos" }
environment {
DOCKER = credentials('docker-hub-credentials')
ALGOLIA_PRIVATE_KEY = credentials('algolia_private_key')
AWS_DEFAULT_REGION = "us-west-2"
}
stages {
stage("Build image") {
steps {
sh '''
docker login -u ${DOCKER_USR} -p ${DOCKER_PSW}
docker pull mesosphere/docs:latest
cp docker/Dockerfile.production.dockerignore .dockerignore
docker build --cache-from mesosphere/docs:latest -f docker/Dockerfile.production -t mesosphere/docs:latest .
'''
}
}
stage("Build & Deploy Preview Docs") {
when {
not {
branch 'beta'
}
}
environment {
ALGOLIA_UPDATE = ""
BUCKET = "docs-d2iq-com-${bucket}"
PRINCIPAL = "arn:aws:iam::139475575661:role/Jenkins/Jenkins-S3-DOCS-Development"
REDIR_HOSTNAME = "${hostname}"
DOCS_ENV = "preview"
}
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "s3-development"]]) {
sh '''
docker run \
-v "$PWD/pages":/src/pages \
-e ALGOLIA_PRIVATE_KEY \
-e ALGOLIA_UPDATE \
-e AWS_ACCESS_KEY_ID \
-e AWS_DEFAULT_REGION \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN \
-e BUCKET \
-e PRINCIPAL \
-e REDIR_HOSTNAME \
-e DOCS_ENV \
mesosphere/docs /src/ci/deploy.sh
'''
}
}
}
stage("Preview Deployment URL") {
when {
not {
branch 'beta'
}
}
steps { echo "http://${hostname}" }
}
stage("Build & Deploy Beta Docs") {
when { branch "beta" }
environment {
ALGOLIA_UPDATE = ""
BUCKET = "docs-d2iq-com-staging"
PRINCIPAL = "arn:aws:iam::139475575661:role/Jenkins/Jenkins-S3-DOCS-Development"
REDIR_HOSTNAME = "beta-docs.d2iq.com"
DOCS_ENV = "beta"
}
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "s3-staging"]]) {
sh '''
docker run \
-v "$PWD/pages":/src/pages \
-e ALGOLIA_PRIVATE_KEY \
-e ALGOLIA_UPDATE \
-e AWS_ACCESS_KEY_ID \
-e AWS_DEFAULT_REGION \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN \
-e BUCKET \
-e PRINCIPAL \
-e REDIR_HOSTNAME \
-e DOCS_ENV \
mesosphere/docs /src/ci/deploy.sh
'''
}
}
}
stage("Build & Deploy Production Docs") {
when { branch "main" }
environment {
ALGOLIA_UPDATE = "true"
BUCKET = "docs-d2iq-com-production"
PRINCIPAL = "arn:aws:iam::139475575661:role/Jenkins/Jenkins-S3-DOCS-Production"
REDIR_HOSTNAME = "docs.d2iq.com"
DOCS_ENV = "production"
}
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "s3-production"]]) {
sh '''
docker run \
-v "$PWD/pages":/src/pages \
-e ALGOLIA_PRIVATE_KEY \
-e ALGOLIA_UPDATE \
-e AWS_ACCESS_KEY_ID \
-e AWS_DEFAULT_REGION \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN \
-e BUCKET \
-e PRINCIPAL \
-e REDIR_HOSTNAME \
-e DOCS_ENV \
mesosphere/docs /src/ci/deploy.sh
'''
}
}
}
stage("Push image") {
when { branch "main" }
steps {
sh '''
docker login -u ${DOCKER_USR} -p ${DOCKER_PSW}
docker push mesosphere/docs:latest
'''
}
}
stage("Restart dev deployment") {
agent { label 'docs-site-kubectl' }
when { branch "main" }
steps {
sh '''
kubectl -n docs-site rollout restart deployment docs-site-dev
kubectl -n docs-site rollout status deploy/docs-site-dev -w --timeout=10m
'''
}
}
}
}