-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
107 lines (100 loc) · 2.72 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
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
POSTGRES_DB: postgres
POSTGRES_HOST: db.jloitwiozsvxuefbktfo.supabase.co
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: proyekakhirkelar
REGISTRY_USER: $REGISTRY_USER
IMAGE_NAME: $IMAGE_NAME
IMAGE_TAG: latest
CONTAINER_NAME: $CONTAINER_NAME
GCP_USERNAME: $GCP_USERNAME
GCP_STATIC_IP: $GCP_STATIC_IP
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
stages:
- sonarcloud-check
- build
- test
- publish
- deploy
sonarcloud-check:
stage: sonarcloud-check
image: gradle:jdk17-alpine
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script: gradle sonar
allow_failure: true
only:
- master
- post-sprint-revision
- staging
Build:
stage: build
image: gradle:jdk17-alpine
before_script:
- echo `pwd`
- export GRADLE_USER_HOME=`pwd`/.gradle
script:
- gradle wrapper
- ./gradlew assemble
- ls
artifacts:
when: always
paths:
- build/libs/*.jar
expire_in: 1 week
Test:
stage: test
image: gradle:jdk17-alpine
dependencies:
- Build
services:
- "postgres:latest"
before_script:
- echo `pwd`
- export GRADLE_USER_HOME=`pwd`/.gradle
- export SPRING_PROFILES_ACTIVE=test
script:
- gradle check --info --stacktrace
- gradle test
- gradle jacocoTestReport
- grep -Eo "Total.*?([0-9]{1,3})%" build/jacocoHtml/index.html
artifacts:
when: always
reports:
junit: build/test-results/test/**/TEST-*.xml
coverage: '/Total.*?([0-9]{1,3})%/'
Publish:
stage: publish
image: docker:latest
services:
- docker:dind
dependencies:
- Build
before_script:
- echo $DOCKER_PASSWORD| docker login -u $REGISTRY_USER --password-stdin docker.io
script:
- ls
- docker build --build-arg PRODUCTION=$PRODUCTION --build-arg JDBC_DATABASE_PASSWORD=$JDBC_DATABASE_PASSWORD --build-arg JDBC_DATABASE_URL=$JDBC_DATABASE_URL --build-arg JDBC_DATABASE_USERNAME=$JDBC_DATABASE_USERNAME -t $REGISTRY_USER/$IMAGE_NAME:$IMAGE_TAG .
- docker push $REGISTRY_USER/$IMAGE_NAME:$IMAGE_TAG
tags:
- dind
only:
- master
Deploy:
stage: deploy
image: alpine:latest
before_script:
- chmod 400 $SSH_KEY
- apk update && apk add openssh-client
script:
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $GCP_USERNAME@$GCP_STATIC_IP "
docker container rm -f $CONTAINER_NAME || true &&
docker image rm -f $REGISTRY_USER/$IMAGE_NAME:$IMAGE_TAG || true &&
docker run --name $CONTAINER_NAME -d -p 80:8080 $REGISTRY_USER/$IMAGE_NAME:$IMAGE_TAG"
only:
- master