Last active
November 18, 2021 12:39
-
-
Save hosseinm1997/92a0dece564d90dadecb87b588d36a57 to your computer and use it in GitHub Desktop.
Gitlab simple auto devops. Add both files into your project repository and customize according to your need.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: alpine:latest | |
pages: | |
only: | |
- master | |
stage: deploy | |
before_script: | |
- 'command -v ssh-agent >/dev/null || ( apk add --update openssh )' | |
- eval $(ssh-agent -s) | |
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - | |
- mkdir -p ~/.ssh | |
- chmod 700 ~/.ssh | |
- ssh-keyscan $VM_IPADDRESS >> ~/.ssh/known_hosts | |
- chmod 644 ~/.ssh/known_hosts | |
script: | |
- ssh $SSH_USER@$VM_IPADDRESS "cd /path/to/project/dir && ./server_deploy.sh" | |
# artifacts: | |
# paths: | |
# - public | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
echo "Deploying application ..." | |
# Enter maintanance mode | |
php artisan down | |
# Update codebase | |
git pull origin master | |
# Install dependencies based on lock file | |
composer install --no-interaction --prefer-dist --optimize-autoloader | |
# Migrate database | |
#php artisan migrate --force | |
# Clear cache | |
php artisan optimize | |
# Reload PHP to update opcache | |
#echo "" | sudo -S service php7.4-fpm reload | |
# Exit maintenance mode | |
php artisan up | |
#if [[ `ps -acx|grep httpd|wc -l` > 0 ]]; then | |
# chown -R apache:apache storage/ bootstrap/cache/ | |
#fi | |
# for nginx write permission problem | |
if [[ `ps -acx|grep nginx|wc -l` > 0 ]]; then | |
chown -R www-data:www-data storage/ bootstrap/cache/ | |
fi | |
echo "🚀 Application deployed!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment