forked from elasticpath/react-pwa-reference-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
101 lines (96 loc) · 3.6 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
currentBuild.description = "Image Tag: ${DOCKER_IMAGE_TAG}"
pipeline {
agent {
label 'node-small'
}
stages {
stage('SETUP') {
steps {
deleteDir()
dir('scm'){
checkout scm
}
dir('solrHome') {
git branch: SOLR_HOME_BRANCH, url: SOLR_HOME_GIT_URL
}
}
}
stage('BUILD') {
steps {
dir('scm') {
// Build the docker image, push to aws
sh """
docker build --tag ${DOCKER_REGISTRY_ADDRESS}/${STORE_NAMESPACE}/ep-blueprint-dev:\$(jq -r .version package.json) \
--build-arg BUILD_DATE="\$(date --rfc-3339=seconds)" --build-arg VERSION=\$(jq -r .version package.json) \
--build-arg VCS_REF=\$(git rev-parse HEAD) -f ./docker/dev/Dockerfile .
eval "\$(aws ecr get-login --no-include-email)"
docker tag ${DOCKER_REGISTRY_ADDRESS}/${STORE_NAMESPACE}/ep-blueprint-dev:\$(jq -r .version package.json) ${DOCKER_REGISTRY_ADDRESS}/${STORE_NAMESPACE}/ep-blueprint-dev:latest
docker push ${DOCKER_REGISTRY_ADDRESS}/${STORE_NAMESPACE}/ep-blueprint-dev:\$(jq -r .version package.json)
docker push ${DOCKER_REGISTRY_ADDRESS}/${STORE_NAMESPACE}/ep-blueprint-dev:latest
"""
}
}
}
stage('UNDEPLOY_EXISTING') {
steps {
// Remove if exists: working directory, docker containers, and images
sh """
ssh -i ${EC2_INSTANCE_SSH_KEY} ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST} \"\"\"
if [ -d ref-store-service ]; then
cd ~
rm -rf ref-store-service
fi
if [ ! -z \\\"\\\$(docker ps -aq)\\\" ]; then
docker rm -f \\\$(docker ps -aq)
fi
if [ ! -z \\\"\\\$(docker images -q)\\\" ]; then
docker rmi \\\$(docker images -q)
fi
\"\"\"
"""
}
}
stage('DEPLOY') {
steps {
// Create the working directory
sh """
ssh -i ${EC2_INSTANCE_SSH_KEY} ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST} "mkdir -p ref-store-service"
"""
// Copy over new deployment files
sh """
scp -i ${EC2_INSTANCE_SSH_KEY} -r scm/* ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST}:~/ref-store-service
scp -i ${EC2_INSTANCE_SSH_KEY} -r ${env.WORKSPACE}/solrHome/${SOLR_HOME_PATH} ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST}:/ep
"""
// Deploy new version
sh """
ssh -i ${EC2_INSTANCE_SSH_KEY} ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST} \"\"\"
export REGISTRY_ADDRESS=${DOCKER_REGISTRY_ADDRESS}
export STORE_NAMESPACE=${STORE_NAMESPACE}
export CORTEX_NAMESPACE=${CORTEX_NAMESPACE}
export STORE_IMAGE_TAG=${STORE_IMAGE_TAG}
export DB_IMAGE_TAG=${DB_IMAGE_TAG}
export DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}
export SOLR_HOME_CONFIG=\$(basename ${SOLR_HOME_PATH})
export CORTEX=http://${EC2_INSTANCE_HOST}:9080
export STORE=${STORE_NAME}
cd ref-store-service/docker/dev
eval '\$(aws ecr get-login --no-include-email)'
docker-compose up -d
\"\"\"
"""
}
}
stage('TEST') {
steps {
// Run unit & Puppeteer tests
timeout(time: 10, unit: 'MINUTES') {
sh """
ssh -i ${EC2_INSTANCE_SSH_KEY} ${EC2_INSTANCE_USER}@${EC2_INSTANCE_HOST} \"\"\"
sleep 35 && docker exec -t store sh -c 'export TEST_HOST=http://${EC2_INSTANCE_HOST}:8080 && CI=true npm test'
\"\"\"
"""
}
}
}
}
}