-
Notifications
You must be signed in to change notification settings - Fork 9
/
.gitlab-ci.yml
156 lines (144 loc) · 4.63 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
147
148
149
150
151
152
153
154
155
156
variables:
CI_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH/$CI_COMMIT_REF_SLUG:$CI_PIPELINE_ID
CI_DEV_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH/dev/$CI_COMMIT_REF_SLUG:$CI_PIPELINE_ID
BASE_URL: https://nevercodealone.projects.nevercodealone.de
stages:
- build
- codeanalysis
- deploy_stage
- trigger_test
- deploy_live
- trigger_live_tests
cypress_full_test_preview_stage:
stage: trigger_test
trigger:
project: never-code-alone/never-code-alone-cypress-basis-tests
branch: main
strategy: depend
variables:
CYPRESS_BASE_URL: https://nevercodealone.projects.nevercodealone.de
TESTS_FAILED_cypress_full_test_preview_stage: $CI_JOB_STATUS == 'success'
cypress_custom_tests_preview_stage:
stage: trigger_test
trigger:
project: never-code-alone/nca-cypress-nevercodealon-custom
branch: main
strategy: depend
variables:
CYPRESS_BASE_URL: https://nevercodealone.projects.nevercodealone.de
TESTS_FAILED_cypress_custom_tests_preview_stage: $CI_JOB_STATUS == 'success'
build:
stage: build
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build -f Dockerfile.conversis --target webserver-live -t $CI_IMAGE --pull .
- docker push $CI_IMAGE
- docker build -f Dockerfile.conversis --target webserver-dev -t $CI_DEV_IMAGE --pull .
- docker push $CI_DEV_IMAGE
tags:
- docker1
codeanalysis_phpunit:
stage: codeanalysis
image: $CI_DEV_IMAGE
script:
- cd /var/www/html
- ls -la
- vendor/bin/phpunit --testdox
tags:
- docker1
.deploy:
image: docker:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
- docker compose -f docker-compose.conversis.yml -p $SHORTCODE1 rm -sfv ||true
- docker volume rm $SHORTCODE1"_var" ||true
script:
- docker exec mariadb /bin/clonedb.sh $DB_USER $DB_NAME ${PREFIX}_${DB_NAME}
- DB_NAME=${PREFIX}_${DB_NAME} docker compose -f docker-compose.conversis.yml -p $SHORTCODE1 up -d --remove-orphans
- docker cp $SHORTCODE-web:/var/www/html/var/uploads /tmp/
- docker cp $SHORTCODE-web:/var/www/html/public/uploads /tmp/public-uploads
- docker cp /tmp/uploads $SHORTCODE1-web:/var/www/html/var/
- docker cp /tmp/public-uploads/. $SHORTCODE-web:/var/www/html/public/uploads
- docker exec $SHORTCODE1-web rm -rf /var/www/html/var/cache/*
- docker exec $SHORTCODE1-web rm -rf /var/www/html/var/cache
- docker exec $SHORTCODE1-web chown www-data:www-data -R /var/www/html/var/
- docker exec $SHORTCODE1-web chown www-data:www-data -R /var/www/html/public/
deploy_stage:
stage: deploy_stage
tags:
- docker2
only:
- main
extends: .deploy
environment:
name: stage
url: https://$URL
variables:
IMAGE: $CI_DEV_IMAGE
SHORTCODE1: stage-$SHORTCODE
DATABASE_URL: mysql://$DB_USER:$DB_PWD@$DB_HOST:3306/${PREFIX}_${DB_NAME}
PREFIX: stage
deploy_branch:
stage: deploy_stage
tags:
- docker2
except:
- main
extends: .deploy
environment:
name: $CI_COMMIT_BRANCH
url: https://$URL
variables:
IMAGE: $CI_DEV_IMAGE
SHORTCODE1: $CI_COMMIT_BRANCH-$SHORTCODE
DATABASE_URL: mysql://$DB_USER:$DB_PWD@$DB_HOST:3306/${PREFIX}_${DB_NAME}
URL: $CI_COMMIT_BRANCH.$URL
PREFIX: $CI_COMMIT_BRANCH
.deploy_live:
stage: deploy_live
tags:
- docker2
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
image: docker:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker compose -f docker-compose.conversis.yml -p $SHORTCODE1 up -d --remove-orphans
- docker exec $SHORTCODE1-web rm -rf /var/www/html/var/cache/*
- docker exec $SHORTCODE1-web rm -rf /var/www/html/var/cache
- docker exec $SHORTCODE1-web chown www-data:www-data -R /var/www/html/var/
- docker exec $SHORTCODE1-web chown www-data:www-data -R /var/www/html/public/
environment:
name: live
url: https://$URL
variables:
IMAGE: $CI_IMAGE
SHORTCODE1: $SHORTCODE
DATABASE_URL: mysql://$DB_USER:$DB_PWD@$DB_HOST:3306/$DB_NAME
deploy_live:
extends: .deploy_live
when: on_success
needs:
- cypress_full_test_preview_stage
- cypress_custom_tests_preview_stage
deploy_live_manual:
extends: .deploy_live
when: manual
allow_failure: true
needs: []
cypress_internal_links_test_live:
stage: trigger_live_tests
trigger:
project: never-code-alone/never-code-alone-cypress-basis-tests
branch: main
strategy: depend
variables:
CYPRESS_BASE_URL: https://$URL
CYPRESS_SPEC: "cypress/e2e/internal-links.cy.ts"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: on_success
needs:
- job: deploy_live