-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
61 lines (55 loc) · 1.67 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
stages:
- build
- docker
- deploy
build-job: # builds spring boot apps
image: maven:3.8.7-eclipse-temurin-17
stage: build
script:
- cd microservices/
- mvn clean install -B
only:
changes:
- microservices/**/*
docker-frontend-job: # build FE image + pushes it to Docker hub
image: docker:20.10.16
stage: docker
services:
- docker:20.10.16-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
script:
- cd frontend/
- docker build -t ase40/ui-service:latest .
- docker push ase40/ui-service:latest
only:
- main
docker-backend-job: # builds BE images using jib + pushes to Docker hub
stage: docker
image: maven:3.8.7-eclipse-temurin-17
script:
- cd microservices/
- echo "Deploying to Docker hub... This will take some time."
- mvn compile jib:build -Djib.to.auth.username=${CI_REGISTRY_USER} -Djib.to.auth.password=${CI_REGISTRY_PASSWORD}
- echo "Deployment to Docker hub Done!"
only:
- main
deploy: # deploys to linode and runs services with docker-compose (pullling from hub)
stage: deploy
before_script:
- 'command -v ssh-agent >/dev/null || ( apk add --update openssh )'
- eval $(ssh-agent -s)
- echo "$PRIVATE_SSH" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $SSH_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- scp docker-compose.yml [email protected]:/root/ # copy docker-compose to linode
- ssh $SSH_USER@$SSH_IP "docker compose --env-file ./.env up -d"
only:
- main