Automate common commands used for deployment is very useful to simplify deployment process. One of my project have the following set of commands used for deployment.
#!/usr/bin/env bash
echo "Navigate to project directory..."
cd /var/www/project
echo "Pulling codes..."
git fetch --tags
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Checkout latest tag"
git checkout $tag
echo "Install dependencies..."
y | composer install
echo "Clear config caches..."
php artisan config:clear
echo "Clear view caches..."
php artisan view:clear
echo "Change project ownerhship to www-data..."
chown www-data:www-data /var/www/project -R
clear
You may want to add SSH key to your project repository, to skip Git ask for credentials.
Idea for Enhancements
I may want to automate deployment from release event.
On released, Github would send webhook to my webhook handler, to run the above script. But I might need a server which handle the webhook and handle internally connect to respective nodes to execute the deploy script I've created above.
- Additional server to handle Github Webhook
- Webhook handler server should be able to SSH to respective app servers to login and run deploy script.
- Each app servers require SSH key to be add to Github repository.
Basically the flow as following:
Github Webhook > Webhook Handler > App Servers
Since this project is on client's premise, I would definitely require to request to have additional server to handle any incoming Github Webhooks.
Photo by Annie Spratt on Unsplash
Top comments (0)