-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
95 lines (82 loc) · 3.41 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
// https://hackmamba.io/blog/2022/04/running-docker-in-a-jenkins-container/
// http://13.211.91.77/#/login
// docker run -it -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v jenkins_home:/var/jenkins_home custom-jenkins-docker
pipeline {
agent any
tools {
nodejs 'node_18.10.0'
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
stage('Clone and install dependencies') {
steps {
sh 'pwd'
dir('web-gen-no-code') {
echo 'Install dependencies web'
sh 'rm -f package-lock.json'
sh 'rm -f yarn.lock'
sh 'npm install'
}
dir('api-gen-no-code') {
echo 'Install dependencies api'
sh 'rm -f package-lock.json'
sh 'rm -f yarn.lock'
sh 'npm install --force'
}
}
}
stage('Unit testing') {
steps {
script {
echo 'Unit test web'
}
}
}
stage('Interation testing') {
steps {
script {
echo 'Interation test web'
}
}
}
stage('Build docker image') {
steps {
script {
sh 'docker login -u 2080600383 -p dd'
dir('web-gen-no-code') {
sh 'docker rmi -f 2080600383/low-code-angular16-web'
sh 'docker build -t 2080600383/low-code-angular16-web .'
sh 'docker login -u 2080600383 -p dd'
sh 'docker push 2080600383/low-code-angular16-web'
echo 'Build web done nice'
}
dir('api-gen-no-code') {
sh 'docker rmi -f 2080600383/low-code-angular16-api'
sh 'docker build -t 2080600383/low-code-angular16-api .'
sh 'docker push 2080600383/low-code-angular16-api'
echo 'Build api done nice'
}
}
}
}
stage('Deploy aws') {
steps {
script {
def serverAddress = 'ec2-52-63-21-87.ap-southeast-2.compute.amazonaws.com'
def webServerAddress = 'ec2-13-239-113-235.ap-southeast-2.compute.amazonaws.com';
sshagent(['AWS_EC2_LOW_CODE_PRIVATE_KEY']) {
sh "ssh -o StrictHostKeyChecking=no -l ubuntu $webServerAddress 'sudo docker stop \$(sudo docker ps -q)'"
sh "ssh -o StrictHostKeyChecking=no -l ubuntu $webServerAddress sudo docker pull 2080600383/low-code-angular16-web"
sh "ssh -o StrictHostKeyChecking=no -l ubuntu $webServerAddress sudo docker run -dp 80:4200 2080600383/low-code-angular16-web"
}
sshagent(['AWS_EC2_LOW_CODE_PRIVATE_KEY']) {
sh "ssh -o StrictHostKeyChecking=no -l ubuntu $serverAddress sudo docker-compose -f docker_compose.yml down"
sh "ssh -o StrictHostKeyChecking=no -l ubuntu $serverAddress sudo docker-compose -f docker_compose.yml up -d"
}
}
}
}
}
}