-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
135 lines (123 loc) · 4.02 KB
/
.gitlab-ci.yml
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
stages: # List of stages for jobs, and their order of execution
- build-backend
- build-frontend
- test-backend
- quality
- publish-backend
- publish-frontend
- deploy-backend
- deploy-frontend
build-backend:
stage: build-backend
image: maven:latest
script:
- cd ridesync_backend
- mvn clean package
only:
- main
build-frontend:
stage: build-frontend
image: node:latest
script:
- cd ridesync_frontend
- npm install
- npm run build
only:
- main
test-backend:
stage: test-backend
image: maven:latest
script:
- cd ridesync_backend
- mvn test
only:
- main
quality:
stage: quality
image: openjdk:17-jdk-alpine
script:
- echo "Extracting the smells..."
- mkdir smells/
- echo $CI_PROJECT_DIR
- java -jar $CI_PROJECT_DIR/.gitlab/DesigniteJava.jar -i $CI_PROJECT_DIR/ridesync_backend -o $CI_PROJECT_DIR/smells/ -d
artifacts:
paths:
- smells/
- $CI_PROJECT_DIR
only:
- main
publish-backend:
image: docker:latest
stage: publish-backend
tags:
- test-runner
# checking tags
variables:
# these values may need to be different if using TLS, k8s, etc.
# You can alternatively set defaults in your runner config
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "tcp://docker:2375"
services:
- docker:dind
script:
- pwd
- echo $SERVER_IP
- docker --version
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PWD docker.io
- cd ridesync_backend
- docker build -t docker.io/meer2838/cicdtest:backend .
- docker push docker.io/meer2838/cicdtest:backend
only:
- main
publish-frontend:
image: docker:latest
stage: publish-frontend
tags:
- test-runner
# checking tags
variables:
# these values may need to be different if using TLS, k8s, etc.
# You can alternatively set defaults in your runner config
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "tcp://docker:2375"
services:
- docker:dind
script:
- pwd
- echo $SERVER_IP
- docker --version
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PWD docker.io
- cd ridesync_frontend
- docker build -t docker.io/meer2838/cicdtest:frontend .
- docker push docker.io/meer2838/cicdtest:frontend
only:
- main
deploy-backend:
image: alpine:latest
stage: deploy-backend
tags:
- test-runner
script:
- apk update && apk add openssh-client sshpass
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PWD docker.io"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull docker.io/meer2838/cicdtest:backend"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-backend-app || true"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 8073:8073 -e SERVER_PORT=$SERVER_PORT -e PROD_DB_URL=$PROD_DB_URL -e PROD_DB_USER=$PROD_DB_USER -e REMOTE_DB_PASSWORD=$REMOTE_DB_PASSWORD -e FRONTEND_PORT=$FRONTEND_PORT -e IP_ADDRESS=$IP_ADDRESS --name my-backend-app docker.io/meer2838/cicdtest:backend"
environment:
name: development
url: http://172.17.1.101:$SERVER_PORT
only:
- main
deploy-frontend:
image: alpine:latest
stage: deploy-frontend
tags:
- test-runner
script:
- apk update && apk add openssh-client sshpass
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PWD docker.io"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull docker.io/meer2838/cicdtest:frontend"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-frontend-app || true"
- sshpass -p "$MY_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 3000:3000 --name my-frontend-app -e REACT_APP_API_URL=$REACT_APP_API_URL docker.io/meer2838/cicdtest:frontend"
only:
- main