-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
92 lines (77 loc) · 3.45 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
image: node:20.16.0
variables:
DEBIAN_FRONTEND: noninteractive
FRONTEND_DIR: /var/www/nuxtify.connor.nl
BACKEND_DIR: /var/www/backend-nuxtify.connor.nl/build
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
deploy:
stage: deploy
tags:
- gitlab-org
before_script:
# Update package list
- apt update
# Setup locale
- apt install locales -y
- echo "en_US UTF-8" > /etc/locale.gen
- locale-gen en_US.UTF-8
# Setup SSH
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 0700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
- chmod 0600 ~/.ssh/id_rsa
- ssh-keyscan "$SSH_HOST" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- apt install -y rsync
# Setup PHP
- wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
- apt install -y lsb-release
- echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
- apt install -y php8.2-{apcu,bcmath,cli,common,curl,dom,gd,intl,mbstring,mcrypt,mysql,opcache,xmlrpc,zip}
script:
# Download Composer
- ./scripts/get-composer.sh
# Deploy backend
- ./composer.phar install --no-dev
- ssh "$SSH_USER"@"$SSH_HOST" -T "mkdir -p $BACKEND_DIR"
- rsync -avhz --delete --exclude-from=.rsyncignore web "$SSH_USER"@"[$SSH_HOST]":"$BACKEND_DIR"
- rsync -avhz --delete vendor "$SSH_USER"@"[$SSH_HOST]":"$BACKEND_DIR"
- rsync -avhz --delete config "$SSH_USER"@"[$SSH_HOST]":"$BACKEND_DIR"
- rsync -avhz --delete composer.json "$SSH_USER"@"[$SSH_HOST]":"$BACKEND_DIR"
- ssh "$SSH_USER"@"$SSH_HOST" -T "rm -f $BACKEND_DIR/web/core/install.php"
- ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web/sites/default && chmod ugo+w ."
- ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web && ../vendor/bin/drush site:install nuxtify -y --site-name="Nuxtify" --account-name=root"
- ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web && ../vendor/bin/drush user:password root $(openssl rand -base64 $(shuf -i 24-48 -n 1))"
- ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web/sites/default && chmod ugo-w ."
# Clear all caches, just to be safe
- ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web && ../vendor/bin/drush cache:rebuild"
# Navigate to the frontend directory
- cd frontend
# Add .env file
- echo "$ENV" > .env
# Get the API key from the backend and add it to the .env file
- API_KEY="$(ssh "$SSH_USER"@"$SSH_HOST" -T "cd $BACKEND_DIR/web && ../vendor/bin/drush sql:query \"SELECT api_key FROM users_field_data WHERE name='GraphQL API';\"")"
- sed -e "s/BACKEND_API_KEY=\".*/BACKEND_API_KEY=\"$API_KEY\"/" -i .env
# Install
- npm install --global pnpm
- pnpm install
# Lint
- npm run lint
# Build
- npm run build
# Deploy frontend
- rsync -avhz --delete .nuxt "$SSH_USER"@"[$SSH_HOST]":"$FRONTEND_DIR"
- rsync -avhz --delete .nvmrc "$SSH_USER"@"[$SSH_HOST]":"$FRONTEND_DIR"
- rsync -avhz --delete .output "$SSH_USER"@"[$SSH_HOST]":"$FRONTEND_DIR"
- rsync -avhz --delete .env "$SSH_USER"@"[$SSH_HOST]":"$FRONTEND_DIR"
# Restart the PM2 process for the frontend
- ssh "$SSH_USER"@"$SSH_HOST" -T ". ~/.profile && pm2 startOrGracefulReload ecosystem.config.js --update-env > /dev/null"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- if: $CI_COMMIT_BRANCH == "main"
when: always
allow_failure: false