-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.xml
147 lines (130 loc) · 4.63 KB
/
Jenkinsfile.xml
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
<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="[email protected]">
<actions>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="[email protected]_9944b_5"/>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="[email protected]_9944b_5">
<jobProperties/>
<triggers/>
<parameters/>
<options/>
</org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
</actions>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="[email protected]">
<projectUrl>http://192.168.34.202:3000/douser/bgapp.git/</projectUrl>
<displayName></displayName>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers>
<com.cloudbees.jenkins.GitHubPushTrigger plugin="[email protected]">
<spec></spec>
</com.cloudbees.jenkins.GitHubPushTrigger>
<hudson.triggers.SCMTrigger>
<spec></spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]_a_38b_62b_b_7">
<script>pipeline
{
environment
{
DOCKERHUB_CREDENTIALS=credentials("docker-hub")
GITEA_SERVER = "http://192.168.34.202:3000"
GITEA_ACCOUNT = "douser"
GITEA_REPOSITORY = "bgapp"
DOCKER_COMPOSE_DEVELOPMENT="development/docker-compose.yaml"
DOCKER_COMPOSE_PRODUCTION="production/docker-compose.yaml"
WEB_IMAGE = "img-web"
DB_IMAGE = "img-db"
}
agent
{
label "docker-node"
}
stages
{
stage("Downloading the project from your Gitea repository")
{
steps
{
git branch: "main", url: "${GITEA_SERVER}/${GITEA_ACCOUNT}/${GITEA_REPOSITORY}.git"
}
}
stage("Prepare volumes")
{
steps
{
sh 'sudo rm -r /home/vagrant/web || true'
sh 'sudo cp -r ./web /home/vagrant/web'
}
}
stage("Deploy on development")
{
steps
{
sh 'docker compose -f $DOCKER_COMPOSE_DEVELOPMENT down || true'
sh 'docker compose -f $DOCKER_COMPOSE_DEVELOPMENT up -d --wait'
}
}
stage("Testing the application for reachability on development")
{
steps
{
script
{
echo "Test #1 - reachability"
sh 'echo $(curl --write-out "%{http_code}" --silent --output /dev/null http://localhost:8080) | grep 200'
sleep(time: 30, unit: "SECONDS")
echo "Test #2 - Test if db is up and running"
sh 'echo $(curl -silent http://localhost:8080) | grep -oh "\\w*Русе\\w*"'
}
}
}
stage("Publishing the images to Docker Hub")
{
steps
{
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
sh 'docker image tag $WEB_IMAGE $DOCKERHUB_CREDENTIALS_USR/$WEB_IMAGE'
sh 'docker image tag $DB_IMAGE $DOCKERHUB_CREDENTIALS_USR/$DB_IMAGE'
sh 'docker push $DOCKERHUB_CREDENTIALS_USR/$WEB_IMAGE'
sh 'docker push $DOCKERHUB_CREDENTIALS_USR/$DB_IMAGE'
}
}
stage("Stopping the application and removing the containers")
{
steps
{
sh 'docker compose -f $DOCKER_COMPOSE_DEVELOPMENT down --rmi all || true'
}
}
stage("Deploy on production")
{
steps
{
sh 'docker image rm $DOCKERHUB_CREDENTIALS_USR/$WEB_IMAGE || true'
sh 'docker image rm $DOCKERHUB_CREDENTIALS_USR/$DB_IMAGE || true'
sh 'docker compose -f $DOCKER_COMPOSE_PRODUCTION down || true'
sh 'docker compose -f $DOCKER_COMPOSE_PRODUCTION up -d --wait'
}
}
}
post
{
always
{
cleanWs()
}
}
}
</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>