-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
94 lines (88 loc) · 3.49 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
image: php:8.3-alpine
# Preparation:
# Save $SSH_PRIVATE_KEY first in GitLab CI variables.
variables:
DRUPAL_PROJECTROOT: "/var/www/nostrver.se"
URL: "https://nostrver.se"
SSH_LOGIN: "ssh -T -p 1986 sebastix@nostrver.se"
SSH_USER: "sebastix"
SSH_HOST: "nostrver.se"
# Production
# DRUPAL_PROJECTROOT_PROD: "/var/www/vhosts/[domain]/domains/[domain]"
# URL_PROD: "https://[domain]"
# SSH_LOGIN_PROD: "ssh -T [username]@[domain]"
# SSH_USER_PROD: "[username]"
# SSH_HOST_PROD: "[domain]"
workflow:
rules:
# Pipelines do not run when branchname starts with ^aupdt_
- if: $CI_COMMIT_BRANCH =~ /^aupdt_/
when: never
- when: always
stages:
- build
- deploy
before_script:
- 'which ssh-agent || ( apk add --update openssh )'
- apk add --update bash
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY_TINYPC" | 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
# Install curl
- apk add curl
# Install git
- apk add git
# Install patch
- apk add patch
# Install composer
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
- alias composer='php /usr/bin/composer'
- composer --version
# install php extensions
# - 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
build:drupal:
stage: build
script:
- composer install --no-dev --prefer-dist --optimize-autoloader
artifacts:
expire_in: 4 hours
paths:
- web
- vendor
deploy:prd:
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
when: always
- if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"'
when: manual
stage: deploy
dependencies:
- build:drupal
environment:
name: prd
url: $URL
script:
- rsync -avz -e 'ssh -p 1986' composer.json $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
- rsync -avz -e 'ssh -p 1986' composer.lock $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
- rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e 'ssh -p 1986' ./config $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
- rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e 'ssh -p 1986' ./vendor $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
- rsync -avz --delete --exclude-from='gitlab-ci/rsync-excludes.txt' -e 'ssh -p 1986' ./web $SSH_USER@$SSH_HOST:$DRUPAL_PROJECTROOT
# - $SSH_LOGIN "chown -R sebastix:www-data $DRUPAL_PROJECTROOT"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush updatedb -y --no-cache-clear"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush cache-rebuild -y"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush config-import -y"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush ckeditor5_markdown_editor:install"
# When module locale is enabled:
#- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush locale:check"
#- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush locale:update"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush core-cron"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush cache-rebuild -y"
- $SSH_LOGIN "cd $DRUPAL_PROJECTROOT && vendor/bin/drush deploy:hook"
- echo "Deployment ready, check $URL"