Created
August 7, 2025 08:15
-
-
Save kidino/a1599201cf245679476dff8ec3d3ce53 to your computer and use it in GitHub Desktop.
gitlab-ci.yml for Laravel
This file contains hidden or 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
stages: | |
- build | |
- deploy | |
build_laravel: | |
stage: build | |
image: lorisleiva/laravel-docker:8.2 | |
only: | |
- master | |
script: | |
- set -e | |
- echo "Running composer install" | |
- composer install --no-dev --optimize-autoloader | |
- echo "Running npm install and build" | |
- npm install | |
- npm run build | |
artifacts: | |
paths: | |
- vendor/ | |
- public/build/ # adjust if your app uses a different folder for built assets | |
- bootstrap/cache/ | |
- .env.example # if you need this | |
- artisan | |
- composer.json | |
- composer.lock | |
- package.json | |
- package-lock.json | |
- resources/ # blade templates, etc. | |
- routes/ | |
- app/ | |
- config/ | |
- database/ | |
expire_in: 1 hour | |
deploy_laravel: | |
stage: deploy | |
image: lorisleiva/laravel-docker:8.2 | |
before_script: | |
- apk update && apk add sshpass openssh | |
only: | |
- master | |
dependencies: | |
- build_laravel | |
script: | |
- echo "Deploying to server via rsync" | |
- | | |
sshpass -p "$SSH_PASS" rsync -av --delete \ | |
-e "ssh -o StrictHostKeyChecking=no" \ | |
--exclude 'storage/app/public' \ | |
--exclude 'public/storage' \ | |
./ "app-7@$SSH_HOST:/home/app-7/" | |
- echo "Running post-deploy artisan commands" | |
- | | |
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "app-7@$SSH_HOST" 'bash -s' <<EOSSH | |
set -e | |
cd /home/app-7 | |
mkdir -p storage/app/public | |
mkdir -p public/storage | |
[ -f "public/index.html" ] && rm public/index.html | |
php artisan config:cache | |
php artisan route:cache | |
php artisan view:cache | |
EOSSH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment