-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
122 lines (113 loc) · 4.51 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
stages:
- build
- release
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
.mvn_build_and_it_tests:
image: registry.internal.pablintino.net/tools-rel/jdk-builder:v0.0.1-jdk11
before_script:
- source <(builder2 source)
services:
- name: postgres:13.4
alias: postgres
- name: rabbitmq:3.9.5
alias: rabbitmq
- name: registry.internal.pablintino.net/arq-svcs-rel/scheduler-service:latest
alias: scheduler-service
# Dirty wait until rabbit is up
entrypoint:
- '/bin/sh'
- '-c'
- |
sleep 20
exec java -jar /app.jar
# arg $0 should be explicitly passed when using 'sh -c' entrypoints
- '/bin/sh'
variables:
SPRING_DATASOURCE_URL: "jdbc:postgresql://postgres:5432/it-database"
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: changeme
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_RABBITMQ_PORT: 5672
COM_PABLINTINO_SCHEDULER_CLIENT_RABBIT_URI: amqp://guest:guest@rabbitmq:5672
COM_PABLINTINO_SCHEDULER_CLIENT_URL: http://scheduler-service:8080
POSTGRES_DB: "it-database"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "changeme"
# On branches just build and test the package
maven-verify-branch:
extends: .mvn_build_and_it_tests
stage: build
script:
- 'mvn $MAVEN_CLI_OPTS verify -P ci-it-test'
rules:
# Avoid pipeline creation for maven release plugin commits
- if: $CI_COMMIT_MESSAGE =~ /^\[maven\-release\-plugin\]/
when: never
allow_failure: false
# Else is non master nor tag run
- if: $CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_TAG == null
when: always
allow_failure: false
# On master test and deploy the snapshot
maven-verify-master:
extends: .mvn_build_and_it_tests
stage: build
script:
- |
attempt_counter=0
max_attempts=5
until $(curl --output /dev/null --silent --head http://scheduler-service:8080); do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi
printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 5
done
- 'mvn $MAVEN_CLI_OPTS deploy -s ci_settings.xml -P ci-it-test'
rules:
# Avoid pipeline creation for maven release plugin commits
- if: $CI_COMMIT_MESSAGE =~ /^\[maven\-release\-plugin\]/
when: never
allow_failure: false
# Else is a master run
- if: $CI_COMMIT_REF_NAME == "master"
when: always
allow_failure: false
release:
extends: .mvn_build_and_it_tests
stage: release
before_script:
- source <(builder2 source)
- 'mkdir -p ~/.ssh/'
- echo -n "$DEPLOY_PRIVATE_KEY" | base64 --decode > ~/.ssh/id_rsa
- 'chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_rsa'
- 'ssh-keyscan $CI_SERVER_HOST >> ~/.ssh/known_hosts'
- 'chmod 644 ~/.ssh/known_hosts'
- 'git config --global user.email "[email protected]"'
- 'git config --global user.name "GitLab CI"'
- 'git checkout -B "$CI_COMMIT_REF_NAME"'
script:
- if [ ! -f ci_settings.xml ];
then echo "CI settings missing\! If deploying to GitLab Maven Repository, please see https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd for instructions.";
fi
- 'mvn release:prepare release:perform -s ci_settings.xml'
rules:
# Avoid pipeline creation for maven release plugin commits
- if: $CI_COMMIT_MESSAGE !~ /^\[maven\-release\-plugin\]/ && $CI_COMMIT_REF_NAME == "master"
when: manual
allow_failure: false
- when: never