-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yaml
114 lines (97 loc) · 3.17 KB
/
.gitlab-ci.yaml
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
stages:
- build
- tests
- publish
- deploy
backend-build-job:
stage: build
tags:
- deployment
image: maven:3.8.3-openjdk-17
script:
- echo "running backend BUILD job"
- cd backend/
- mvn clean install -DskipTests
- echo "✨ Backend job finished successfully ✅"
artifacts:
paths:
- backend/target/*.jar
frontend-build-job:
stage: build
tags:
- deployment
image: node:18.18
script:
- echo "running frontend BUILD job"
- cd ui/
- yarn install
- yarn build
- echo "✨ Frontend job finished successfully ✅"
artifacts:
paths:
- ui/build/*
backend-test-job:
stage: tests
image: maven:3.8.3-openjdk-17
tags:
- deployment
script:
- echo "running backend TEST job"
- cd backend/
- mvn verify
- echo "✨ Backend test job finished successfully ✅"
# frontend-test-job:
# stage: tests
# image: node:18.18
# script:
# - echo "running frontend TEST job"
# - cd ui/
# - yarn install
# - yarn run test
# - echo "✨ Frontend test job finished successfully ✅"
publish:
image: docker:latest
stage: publish
tags:
- deployment
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "tcp://docker:2375"
services:
- docker:dind
script:
- docker --version
- echo $SERVER_IP
- docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PWD docker.io
- cd backend/ # backend publish
- docker build -t docker.io/csci5308vm14/strangely:backend_$CI_COMMIT_SHORT_SHA .
- docker push docker.io/csci5308vm14/strangely:backend_$CI_COMMIT_SHORT_SHA
- cd ../ui/ # frontend publish
- docker build -t docker.io/csci5308vm14/strangely:ui_$CI_COMMIT_SHORT_SHA .
- docker push docker.io/csci5308vm14/strangely:ui_$CI_COMMIT_SHORT_SHA
only:
- main
deploy:
image: alpine:latest
stage: deploy
tags:
- deployment
script:
- chmod og= $ID_RSA
- apk update && apk add openssh-client
# login
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PWD docker.io"
# code pull
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull docker.io/csci5308vm14/strangely:backend_$CI_COMMIT_SHORT_SHA"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull docker.io/csci5308vm14/strangely:ui_$CI_COMMIT_SHORT_SHA"
# remove earlier code
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-app-backend || true"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-app-ui || true"
# run container with specific ports
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 8073:8080 --name my-app-backend docker.io/csci5308vm14/strangely:backend_$CI_COMMIT_SHORT_SHA"
- ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 8074:5173 --name my-app-ui docker.io/csci5308vm14/strangely:ui_$CI_COMMIT_SHORT_SHA"
environment:
name: production
url: http://172.17.1.123:8074 # mapping to frontend env
only:
- main