-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
115 lines (105 loc) · 3.5 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
#!groovy
pipeline {
agent any
tools {
go 'Go'
}
environment {
GO111MODULE = 'on'
CGO_ENABLED = 0
GOPATH = "${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}"
APP_NAME = "shopping"
REGION = "${REGION}"
ACCESS_KEY = "${AWS_SECRET_ACCESS_KEY}"
KEY_ID = "${AWS_ACCESS_KEY_ID}"
JWT_SECRET_KEY = "${JWT_SECRET_KEY}"
}
stages {
stage('Pre Test') {
steps {
echo 'Installing dependencies'
sh 'go version'
}
}
stage('Build #1') {
steps {
echo 'Compiling and building'
sh 'cd shipping-service && go build'
}
}
stage('Test #1') {
steps {
withEnv(["PATH+GO=${GOPATH}/bin"]){
echo 'Running vetting'
sh 'cd shipping-service && go vet .'
echo 'Running test'
sh 'cd shipping-service && go test ./...'
}
}
}
stage('Create .env file #1') {
steps {
sh 'cd shipping-service && touch .env'
sh 'cd shipping-service && echo "REGION=${REGION}" >> .env'
sh 'cd shipping-service && echo "AWS_ACCESS_KEY_ID=${KEY_ID}" >> .env'
sh 'cd shipping-service && echo "AWS_SECRET_ACCESS_KEY=${ACCESS_KEY}" >> .env'
sh 'cd shipping-service && echo "SECRET=${JWT_SECRET_KEY}" >> .env'
}
}
stage('Run #1') {
steps {
echo 'Building the latest docker image'
sh 'cd shipping-service && chmod +x startup.sh && ./startup.sh'
}
}
stage('Run #1.1') {
steps {
echo 'Pushing image to dockerhub'
sh 'cd shipping-service && chmod +x push.sh && ./push.sh'
}
}
stage('Build #2') {
steps {
echo 'Compiling and building'
sh 'cd categories-service && go build'
}
}
stage('Test #2') {
steps {
withEnv(["PATH+GO=${GOPATH}/bin"]){
echo 'Running vetting'
sh 'cd categories-service && go vet .'
echo 'Running test'
sh 'cd categories-service && go test ./...'
}
}
}
stage('Create .env file #2') {
steps {
sh 'cd categories-service && touch .env'
sh 'cd categories-service && echo "REGION=${REGION}" >> .env'
sh 'cd categories-service && echo "AWS_ACCESS_KEY_ID=${KEY_ID}" >> .env'
sh 'cd categories-service && echo "AWS_SECRET_ACCESS_KEY=${ACCESS_KEY}" >> .env'
sh 'cd categories-service && echo "SECRET=${JWT_SECRET_KEY}" >> .env'
}
}
stage('Run #2') {
steps {
echo 'Building the latest docker image'
sh 'cd categories-service && chmod +x startup.sh && ./startup.sh'
}
}
stage('Run #2.1') {
steps {
echo 'Pushing image to dockerhub'
sh 'cd categories-service && chmod +x push.sh && ./push.sh'
}
}
stage('Run #') {
steps {
echo 'Running docker compose'
sh 'docker compose up -d'
}
}
}
}