forked from d2iq-archive/dcos-docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
93 lines (85 loc) · 2.91 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
#!/usr/bin/env groovy
boolean isProduction = env.BRANCH_NAME == "production"
boolean isBeta = env.BRANCH_NAME == "beta"
boolean isPreview = env.BRANCH_NAME == "main"
def bucket = isProduction ? "production"
: isBeta ? "staging"
: isPreview ? "preview" // TODO: Create this bucket
: "pr-${env.CHANGE_ID}"
def creds = isProduction ? "s3-production"
: isBeta ? "s3-staging"
: "s3-development" // TODO: Can we use these credentials for develop branch and PRs?
def hostname = isProduction ? "docs.d2iq.com"
: isBeta ? "beta-docs.d2iq.com"
: isPreview ? "dev-docs.d2iq.com" // TODO: Where to get this url from?
: "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')
REDIR_HOSTNAME = "${hostname}"
}
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("Push image") {
when { branch "production" }
steps {
sh '''
docker login -u ${DOCKER_USR} -p ${DOCKER_PSW}
docker push mesosphere/docs:latest
'''
}
}
stage("Build & Deploy Docs") {
environment {
ALGOLIA_UPDATE = "${isProduction ? 'true' : ''}"
AWS_DEFAULT_REGION = "us-west-2"
BUCKET = "docs-d2iq-com-${bucket}"
// TODO: What does that mean?
PRINCIPAL = "arn:aws:iam::139475575661:role/Jenkins/Jenkins-S3-DOCS-${isProduction ? 'Production' : 'Development'}"
REDIR_HOSTNAME = "${hostname}"
}
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: creds]]) {
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 \
mesosphere/docs /src/ci/deploy.sh
'''
}
}
}
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
'''
}
}
stage("Deployment URL") {
steps { echo "http://${hostname}" }
}
}
}