-
Notifications
You must be signed in to change notification settings - Fork 75
/
.gitlab-ci.yml
147 lines (115 loc) · 5.99 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# docker-in-docker support
# see https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
default:
services:
- name: docker:24.0.5-dind
alias: docker
image: docker:24.0.5
variables:
# this disables HTTPS when talking to the docker daemon.
# the current otobo gitlab runners are configured without
# TLS
DOCKER_TLS_CERTDIR: ""
OTOBO_BASE:
value: "rel-11_0"
options:
- "rel-11_0"
- "rel-10_1"
- "rel-10_0"
description: "The otobo base (otobo-docker branch) to use."
OTOBO_TESTS:
value: "scripts/test/Ticket"
description: "Specify single test or directory of Tests, starting with 'scrips/test'. "
OTOBO_PACKAGES:
value: ""
description: "Space separated list of versioned otobo packages names or full urls, e.g. 'Fred-11.0.1.opm' or 'https://ftp.otobo.org/pub/otobo/packages/:Fred-11.0.1.opm'\n See output of ./otobo.Console.pl Admin::Package::RepositoryList for possible values"
OTOBO_DB_ROOT_PASSWORD: "programmieren_auf_dem_bauernhof"
# TODO: packacge might need /opt/otobo/Custom
OTOBO_INSTALL_LIBS: '$PERL5LIB:/opt/otobo_install/otobo_next:/opt/otobo:/opt/otobo_install/otobo_next/Kernel/cpan-lib'
OTOBO_TEST_LIBS: '$PERL5LIB:/opt/otobo/perl5/lib/perl5:/opt/otobo_install/local/lib/perl5/:/opt/otobo:/opt/otobo/Kernel/cpan-lib'
before_script:
# set variable TAP_FORMATTER depending on release branch.
# effectively this downgrades version for rel-10_0.
- if [ "$OTOBO_BASE" == "rel-10_0" ]; then export TAP_FORMATTER="TAP::Formatter::[email protected]"; else export TAP_FORMATTER="TAP::Formatter::JUnit"; fi
- echo "PIPELINE_SOURCE is $CI_PIPELINE_SOURCE"
stages:
- test
testsuite:
stage: test
# tags will determine which runners are allowed to pick up the job
tags:
- docker
# rules - run the testsuite if it is a scheduled build, or if it was
# triggered via UI (web), or if it is a push to a release branch
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /^rel-[0-9][0-9]_[0-9]+$/
script:
# make sure $DOCKER_HOST is set
# if using official "docker" image there is no todo
# otherwise, like running on ubuntu/debian images, do:
# - apt update && apt install -y git docker.io docker-compose-v2
# - export DOCKER_HOST="tcp://docker:2375"
# - echo "Docker $DOCKER_HOST"
- echo -e "Going to build ${CI_PROJECT_NAME} branch ${CI_COMMIT_REF_NAME} <${CI_COMMIT_SHORT_SHA}>\n from ${CI_COMMIT_AUTHOR} at ${CI_COMMIT_TIMESTAMP} with:\n ${CI_COMMIT_TITLE}\n on otobo-docker:${OTOBO_BASE}."
# we need git
- apk update -q
- apk add git -q
# prepare otobo sources
- cp Kernel/Config.pm.docker.dist Kernel/Config.pm
- mkdir -p var/tmp
- export OPT_OTOBO=$PWD
- chown -R 1000:1000 .
# clone the otobo-docker repo
- git clone https://github.com/RotherOSS/otobo-docker.git /opt/otobo-docker
- cd /opt/otobo-docker
- git checkout $OTOBO_BASE
# prepare docker .env for first run
- cp .docker_compose_env_http_selenium .env
- sed -i "s/OTOBO_DB_ROOT_PASSWORD=/OTOBO_DB_ROOT_PASSWORD=${OTOBO_DB_ROOT_PASSWORD}/" .env
# create otobo volume for docker compose holding desired branch
# note: surround with single tick quotes to prevent being parsed as yaml
- 'docker volume create --driver local -o o=bind -o type=none -o device=$OPT_OTOBO opt_otobo'
- 'sed -i "s/opt_otobo: {}/opt_otobo: { external: true }/" docker-compose/otobo-base.yml '
# start containers
- docker compose up --detach --quiet-pull
- docker ps
# wait for db
- docker exec otobo-db-1 bash -c 'TEST=""; while [ "$TEST" != "ERROR 1045" ]; do echo "wait for db"; sleep 5; TEST=$( mysql -u root otobo 2>&1 | grep -o "ERROR 1045" ); done;'
- docker logs otobo-web-1
- sleep 15
# deps (just fyi)
- docker exec otobo-web-1 bash -c 'bin/otobo.CheckModules.pl --inst'
- docker exec otobo-web-1 bash -c 'bin/otobo.CheckModules.pl --finst=devel:test'
# run quick_setup.pl
- docker exec otobo-web-1 bash -c "PERL5LIB=${OTOBO_INSTALL_LIBS} cd /opt/otobo && /usr/local/bin/perl bin/docker/quick_setup.pl --db-password ${OTOBO_DB_ROOT_PASSWORD} --http-type http --fqdn 'localhost'"
# extra Test dependencies for formatting test results in junit xml format
- docker exec otobo-web-1 bash -c "/usr/local/bin/cpanm -n -q $TAP_FORMATTER 2>/dev/null"
# install packages, if any
- 'for PACKAGE in ${OTOBO_PACKAGES}; do echo "Install Package: $PACKAGE"; if [[ $PACKAGE != http* ]]; then PACKAGE="https://ftp.otobo.org/pub/otobo/packages/:$PACKAGE" ;fi; docker exec otobo-web-1 /opt/otobo/bin/otobo.Console.pl Admin::Package::Install "$PACKAGE" ;done'
- docker exec otobo-web-1 /opt/otobo/bin/otobo.Console.pl Admin::Package::List
# wait for login to become ready
- docker exec otobo-web-1 bash -c 'TEST=""; while [ "$TEST" != "LoginButton" ]; do echo "wait for login"; sleep 5; TEST=$(curl -s "http:/localhost:5000/otobo/index.pl" | grep -o "LoginButton"); done;'
# stop the dameon before running unit tests
- docker compose down daemon
# create the archive
- docker exec otobo-web-1 bash -c "/opt/otobo/bin/otobo.CheckSum.pl -a create"
# run the tests
- echo "Running tests from ${OTOBO_TESTS}"
- docker exec otobo-web-1 bash -c "PERL5LIB=${OTOBO_TEST_LIBS} /usr/local/bin/prove --timer --formatter=TAP::Formatter::JUnit ${OTOBO_TESTS} " > $OPT_OTOBO/rspec.xml
# unit test report support - upload the test results to gitlab
# https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html
artifacts:
when: always
paths:
- rspec.xml
reports:
junit: rspec.xml
after_script:
# cleanup
- cd /opt/otobo-docker
- docker compose down
- docker volume rm otobo_mariadb_data
- docker volume rm opt_otobo
- echo "This was a build of ${CI_PROJECT_NAME} branch ${CI_COMMIT_REF_NAME} on otobo-docker:${OTOBO_BASE}. Over and out."