-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
158 lines (147 loc) · 5.93 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
157
158
image: php:8.3-alpine
variables:
# Test
DRUPAL_PROJECTROOT: "/var/www/cchs.sebastix.dev"
URL: "https://cchs.sebastix.dev"
SSH_LOGIN: "ssh -T root@sebastix.dev"
SSH_USER: "root"
SSH_HOST: "sebastix.dev"
# Production
DRUPAL_PROJECTROOT_PROD: "/var/www/vhosts/cchs.social/domains/cchs.social"
URL_PROD: "https://cchs.social"
SSH_LOGIN_PROD: "ssh -T cchs@cchs.social"
SSH_USER_PROD: "cchs"
SSH_HOST_PROD: "cchs.social"
workflow:
rules:
# Pipelines do not run when branchname starts with ^aupdt_
- if: $CI_COMMIT_BRANCH =~ /^aupdt_/
when: never
- when: always
stages:
- build
- validate
- test
- deploy
before_script:
- 'which ssh-agent || ( apk add --update openssh )'
- apk add --update bash
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add -
- echo "$SSH_PRIVATE_KEY_PROD" | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# Install rsync
- apk add rsync
- rsync --version
# Install curl
- apk add curl
# Install composer
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
- alias composer='php /usr/bin/composer'
- composer --version
# Install nodejs and npm
- apk add nodejs npm
- node --version
- npm --version
# install php gd extension
# - see https://github.com/mlocati/docker-php-extension-installer
- curl -sSLf -o /usr/bin/install-php-extensions https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions
- chmod +x /usr/bin/install-php-extensions
- install-php-extensions gd gmp
# install git
- apk add git
build:drupal:
stage: build
script:
- composer install --prefer-dist --optimize-autoloader
artifacts:
paths:
- web
- vendor
build:theme:
stage: build
script:
- cd web/themes/custom/hix
- npm install
- npm run build
artifacts:
paths:
- web/themes/custom/hix/dist
validate:composer-lint:
stage: validate
dependencies:
- build:drupal
script:
- composer --version
- composer validate
validate:phpcs:
stage: validate
allow_failure: true
script:
- vendor/bin/phpcs web/modules/custom
- vendor/bin/phpcs web/themes/custom
validate:phpstan:
stage: validate
allow_failure: true
script:
- vendor/bin/phpstan web/modules/custom
- vendor/bin/phpstan web/themes/custom
#deploy:test:
# rules:
# - if: $CI_COMMIT_BRANCH == "develop"
# when: always
# - if: $CI_COMMIT_BRANCH == "master"
# when: manual
# stage: deploy
# dependencies:
# - build:drupal
# - build:theme
# script:
# - rsync -avz -e ssh ./composer.json $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - rsync -avz -e ssh ./composer.lock $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e ssh ./config $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e ssh ./vendor $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e ssh ./web $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - $SSH_LOGIN "chown -R nginx:nginx $DRUPAL_PROJECTROOT"
# - $SSH_LOGIN "chcon -R -t httpd_sys_rw_content_t $DRUPAL_PROJECTROOT/private" # permission fix wit SELinux on CentOS7
# - $SSH_LOGIN "chcon -R -t httpd_sys_rw_content_t $DRUPAL_PROJECTROOT/web/sites/default/files" # permission fix wit SELinux on CentOS7
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush updatedb -y"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush cache-rebuild -y"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush config-import -y"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush locale:check"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush locale:update"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush core-cron"
# - $SSH_LOGIN "$DRUPAL_PROJECTROOT/vendor/bin/drush cache-rebuild -y"
# - $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush deploy:hook"
# - echo "Deployment ready, check $URL"
deploy:prod:
rules:
- if: $CI_COMMIT_BRANCH == "develop"
when: manual
- if: $CI_COMMIT_BRANCH == "master"
when: manual
stage: deploy
dependencies:
- build:drupal
- build:theme
script:
- rsync -avz -e ssh ./composer.json $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD
- rsync -avz -e ssh ./composer.lock $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD
- rsync -az --stats --delete -e ssh ./config $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD
- $SSH_LOGIN_PROD "cd $DRUPAL_PROJECTROOT_PROD && chmod -R 755 ./config"
- rsync -az --stats --delete -e ssh ./vendor $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD
- rsync -az --stats --delete -e ssh web/modules/custom $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD/web/modules
- rsync -az --stats --delete -e ssh web/themes/custom $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD/web/themes
- rsync -az --stats --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e ssh ./web $SSH_USER_PROD@$SSH_HOST_PROD:$DRUPAL_PROJECTROOT_PROD/web
- $SSH_LOGIN_PROD "cd $DRUPAL_PROJECTROOT_PROD && chmod -R 755 ./web"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush updatedb -y --no-cache-clear"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush cache-rebuild -y"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush config-import -y"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush locale:check"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush locale:update"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush core-cron"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush cache-rebuild -y"
- $SSH_LOGIN_PROD "$DRUPAL_PROJECTROOT_PROD/vendor/bin/drush deploy:hook"
- echo "Deployment ready, check $URL_PROD"