This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
72 lines (67 loc) · 3.6 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
stages:
- deploy
# Select image from https://hub.docker.com/_/php/
image: php:7.2-cli
# Select what we should cache
cache:
paths:
- vendor/
- node_modules/
variables:
RELEASES: "$REMOTE_BASE/releases"
SHARED: "$REMOTE_BASE/shared"
before_script:
# setup SSH & private key
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -yqq )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh; chmod 700 ~/.ssh
- ssh-keyscan -p $REMOTE_PORT $REMOTE_SERVER >> ~/.ssh/known_hosts
# the following line is optional (likely remove previous line)
#- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Install packages
- apt-get install gnupg2 build-essential libssl-dev -yqq
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
# Install git, the php image doesn't have installed
- apt-get install git zip unzip gcc g++ make nodejs -yqq
- alias nodejs=node
# add package key for yarn
- curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt-get update -yqq && apt-get install yarn -yqq
- curl -sS https://getcomposer.org/installer | php
deploy:
stage: deploy
when: manual
allow_failure: false
script:
- export SYMFONY_ENV=prod
- php -v
- php composer.phar --version
- node --version
# setup vars for paths
- TIMESTAMP=$(date +%s); RELEASE="$RELEASES/$TIMESTAMP"
- echo "Paths:"; echo $REMOTE_BASE; echo $RELEASE; echo $SHARED
- echo "Remote:"; echo $REMOTE_USER@$REMOTE_SERVER:$REMOTE_PORT
# install php dependencies
- php composer.phar install --no-dev --classmap-authoritative --no-interaction --no-progress --no-scripts --no-plugins
# Install node/JS dependencies
- yarn install --non-interactive --frozen-lockfile
- yarn build
# add .revision file
- git rev-parse --verify --short HEAD > .revision
# ensure based paths exist
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "mkdir -p $RELEASES $SHARED $SHARED/var $SHARED/html/uploads $SHARED/html/media/cache"
# sync files to deployment cache
- rsync --archive --stats --human-readable --no-perms --exclude ".git/" --exclude ".idea/" --exclude "node_modules/" --exclude "html/app_dev.php" --exclude "html/config.php" -e "ssh -p $REMOTE_PORT" . $REMOTE_USER@$REMOTE_SERVER:$RELEASE
# copy parameters file into place
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "cp -a $SHARED/parameters.yml $RELEASE/app/config/parameters.yml"
# link shared folders
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "rm -rf $RELEASE/var; ln -s $SHARED/var $RELEASE/var; rm -rf $RELEASE/html/uploads; ln -s $SHARED/html/uploads $RELEASE/html/uploads; rm -rf $RELEASE/html/media/cache; ln -s $SHARED/html/media/cache $RELEASE/html/media/cache"
# switch to new version; run composer on server; db migrations
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "rm -f $REMOTE_BASE/current; ln -s $RELEASE $REMOTE_BASE/current; cd $REMOTE_BASE/current; export SYMFONY_ENV=prod; php composer.phar run-script post-update-cmd; php bin/console doctrine:migrations:migrate --no-interaction --no-debug --allow-no-migration"
# clear opcache
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "cd $RELEASE; export SYMFONY_ENV=prod; php bin/console cache:accelerator:clear --opcode" || echo -e "\033[0;31mFAILURE unable to reset OPcache"
# remove >3 releases
- ssh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER "ls -1d $RELEASES/* | sort -rg | tail -n +4 | xargs /bin/rm -rf"