Skip to content

Instantly share code, notes, and snippets.

@hosseinm1997
Last active November 18, 2021 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hosseinm1997/92a0dece564d90dadecb87b588d36a57 to your computer and use it in GitHub Desktop.
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.
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
#!/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