Skip to content

Instantly share code, notes, and snippets.

@andikurnia
Last active March 25, 2025 03:52
Show Gist options
  • Select an option

  • Save andikurnia/def64d2b98b70794e8b936d6e2d3bdae to your computer and use it in GitHub Desktop.

Select an option

Save andikurnia/def64d2b98b70794e8b936d6e2d3bdae to your computer and use it in GitHub Desktop.
A little tools for running a new laravel application and setup it's container by using the power of Sail
#!/bin/bash
SAIL="./vendor/bin/sail"
if [ ! -f "$SAIL" ]; then
echo "Sail not found. Run sail.sh to install sail...."
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php83-composer:latest \
composer install --ignore-platform-reqs
else
echo "Sail found. Continue running sails commands...."
fi
# check if .env file exists, copy from example if not
if [ ! -f ".env" ]; then
cp .env.example .env
fi
# import all variables from .env file
source .env
# test if the command exists
if [ ! -f "$SAIL" ]; then
echo "Sail not found or not configured properly. Please refers to the documentation at https://laravel.com/docs/11.x/sail...."
exit 1
fi
# stop comtainer if it is running
$SAIL stop
# check if parameter is contains up
if [ "$1" == "up" ]; then
$SAIL "$@" -d
# # check if php inside laravel.test container can be connected, if not wait 5 seconds and try again. If connected, break the loop and print message
while true; do
sleep 1
$SAIL php -v && break
done
echo "PHP is ready!"
# # get container name contain laravel.test
PHP_CONTAINER_NAME=$(docker ps | grep 'laravel.test' | awk '{print $1}')
# check if mysql container is ready from laravel.test container and connect, if not wait 5 seconds and try again. If connected, break the loop and print message
while true; do
sleep 1
docker exec -it $PHP_CONTAINER_NAME mysql -h$DB_HOST -u$DB_USERNAME -p$DB_PASSWORD -e "SHOW DATABASES" && break
done
echo "Database is ready!"
#run composer install
$SAIL composer install
# run laravel starter artisan command using sail
$SAIL artisan key:generate
$SAIL artisan storage:link
# ask user to run artisan migrate, if there is no action in 30 seconds, continue
$SAIL artisan migrate:status
echo "Run artisan migrate? (y/n)"
read -t 10 answer
if [ "$answer" == "y" ]; then
$SAIL artisan migrate
else
echo "Skipping artisan migrate..."
fi
# check if node inside laravel.test container can be connected, if not wait 5 seconds and try again. If connected, break the loop and print message
while true; do
sleep 1
docker exec -it $PHP_CONTAINER_NAME node -v && break
done
echo "Node is ready!"
#run npm install inside laravel.test container
$SAIL npm install
# ask user whether to run make:filament-user, if there is no action in 30 seconds, continue
echo "Run make:filament-user? (y/n)"
read -t 10 answer
if [ "$answer" == "y" ]; then
$SAIL php artisan make:filament-user
else
echo "Skipping make:filament-user..."
fi
$SAIL artisan filament:optimize-clear
$SAIL php artisan filament:optimize
echo "done. Have fun!"
else
$SAIL "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment