This repository has been archived by the owner on Jul 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
106 lines (103 loc) · 3.45 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
pipeline {
environment {
PROJECT_NAME = 'path-to-run'
DEV_ENVIRONMENT_PORT = '9001'
STRAVA_CLIENT_ID = credentials('strava-client-id')
STRAVA_CLIENT_SECRET = credentials('strava-client-secret')
STRAVA_REFRESH_TOKEN = credentials('strava-refresh-token')
POSTGRES_USERNAME = credentials('path-to-run-postgres-username')
POSTGRES_PASSWORD = credentials('path-to-run-postgres-password')
}
agent none
stages {
stage('Lint and Build Client') {
agent {
docker {
image 'node:11-stretch'
}
}
stages {
stage('Install Client Dependencies') {
steps {
dir('client') {
sh '''
npm install -g yarn
yarn
'''
}
}
}
stage('Lint Client') {
steps {
dir('client') {
sh 'yarn lint'
}
}
}
stage('Build Client') {
steps {
dir('client') {
sh 'yarn build'
}
}
}
}
}
stage('Build Server') {
agent {
docker {
image 'maven:3.6-jdk-11'
args '-v $HOME/.m2:/root/.m2'
}
}
steps {
dir('server') {
sh '''
mvn clean install \
-DSTRAVA_CLIENT_ID=${STRAVA_CLIENT_ID} \
-DSTRAVA_CLIENT_SECRET=${STRAVA_CLIENT_SECRET} \
-DSTRAVA_REFRESH_TOKEN=${STRAVA_REFRESH_TOKEN}
'''
}
}
}
stage('Archive Artifact') {
agent any
steps {
archiveArtifacts 'server/target/*.jar'
}
}
stage('Build Docker Image') {
agent any
steps {
sh 'docker build -t ${PROJECT_NAME}:latest .'
sh 'docker image prune -f'
}
}
stage('Remove Existing Container from Dev') {
agent any
steps {
sh 'docker container stop ${PROJECT_NAME} || echo "No existing container... skipping"'
sh 'docker container rm ${PROJECT_NAME} || echo "No existing container... skipping"'
}
}
stage('Deploy to Dev Environment') {
agent any
steps {
sh '''
docker run -d \
-e STRAVA_CLIENT_ID=${STRAVA_CLIENT_ID} \
-e STRAVA_CLIENT_SECRET=${STRAVA_CLIENT_SECRET} \
-e STRAVA_REFRESH_TOKEN=${STRAVA_REFRESH_TOKEN} \
-e POSTGRES_USERNAME=${POSTGRES_USERNAME} \
-e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
-e SPRING_PROFILES_ACTIVE=prod \
-p ${DEV_ENVIRONMENT_PORT}:8080 \
--net=${PROJECT_NAME}-net \
--name ${PROJECT_NAME} \
${PROJECT_NAME}:latest
'''
}
}
}
}