-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
47 lines (41 loc) · 1.26 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
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
# 3 stages we use
stages:
- build
- package
- deploy
# run this script before every stages
before_script:
- export IMAGE_TAG_SHA=${CI_COMMIT_SHA:0:7}
# building stage, based image maven to do the building and testing, output is war file
maven-build:
image: maven:3.5.0-jdk-8
stage: build
script:
- cd backend
- mvn package -B
artifacts:
paths:
- backend/target/*.war
# packaging stage, we make docker image based on the war file outputted before
docker-build:
stage: package
script:
- cd backend
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker build -t $CI_REGISTRY_IMAGE:${IMAGE_TAG_SHA} -t $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE
# deploying stage, we use ansible to access the server and deploy the docker image
deploy:
image: williamyeh/ansible:debian8
stage: deploy
environment:
name: production
url: http://kildin.informatik.rwth-aachen.de:1234/rabatt/api/v1/users/
script:
- cd backend/deploy
- ansible-playbook site.yml -v -i production --extra-vars "ansible_ssh_pass=$SSH_PASS ansible_ssh_common_args='-o StrictHostKeyChecking=no' IMAGE_TAG_SHA=${IMAGE_TAG_SHA}"