😊 Deploiment - InstaRepas #97
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
name: 😊 Deploiment - InstaRepas | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Numéro de version pour le déploiement (format: X.Y.Z)' | |
required: false | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: 📦 Récupération du Code | |
uses: actions/[email protected] | |
with: | |
fetch-depth: '0' | |
- name: ⚙️ Configuration de PHP | |
uses: shivammathur/[email protected] | |
with: | |
php-version: '8.3' | |
extensions: mongodb, bcmath, bz2, calendar, Core, ctype, curl, date, dom, exif, FFI, fileinfo, filter, ftp, gd, gettext, hash, iconv, igbinary, imagick, imap, intl, json, libxml, mbstring, mcrypt, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, Phar, posix, readline, redis, Reflection, session, shmop, SimpleXML, soap, sockets, sodium, SPL, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib, Zend OPcache | |
tools: composer:v2 | |
- name: 📚 Installation de NPM | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y npm | |
npm --version | |
- name: 🚀 Aller au répertoire Laravel et afficher | |
run: | | |
cd InstaRepas | |
pwd | |
ls -la | |
- name: 🛠️ Installation des dépendances du projet | |
run: | | |
composer install --no-dev --no-progress --prefer-dist --optimize-autoloader | |
npm install | |
working-directory: ./InstaRepas | |
- name: 🏗️ Construction du Projet | |
run: | | |
npm run build | |
working-directory: ./InstaRepas | |
- name: 🗝️ Ajouter la clé SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_KNOWN_HOSTS }}" >> ~/.ssh/known_hosts | |
- name: 🔐 Configuration de SSH et rsync | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: 🏷️ Création du tag de version | |
uses: anothrNick/github-tag-action@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CUSTOM_TAG: ${{ github.event.inputs.version }} | |
WITH_V: true | |
- name: 🗑️ Supprimer les répertoires bootstrap/cache, public et storage | |
run: | | |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "sudo rm -rf ${{ secrets.PROD_DIR }}/bootstrap/ ${{ secrets.PROD_DIR }}/public ${{ secrets.PROD_DIR }}/storage" | |
- name: 🚀 Déploiement sur le serveur de production | |
run: | | |
echo "Répertoire de travail local :" | |
pwd | |
echo "Contenu du répertoire de travail local :" | |
ls -la | |
echo "Déploiement des fichiers vers le serveur de production..." | |
rsync -r -avz -O --delete-after --exclude=DB --exclude=GIT --exclude=scripts --exclude=logo_for_foodequlibre.png --exclude=.github --exclude=.editorconfig --exclude=dist --exclude=node_modules --exclude=.env --exclude=Dockerfile --exclude=_ide_helper.php --exclude=_ide_helper_models.php --exclude=shell-php.nix --exclude=shell-stripe.nix --exclude=php.nix --exclude=deploy.yaml --exclude=README.md --exclude=tests --exclude=.phpstorm.meta.php --exclude=.env.example --exclude=phpunit.xml --exclude=.gitattributes --exclude=.git --exclude=.gitignore --quiet -e 'ssh -p ${{ secrets.REMOTE_PORT }}' InstaRepas/ ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.PROD_DIR }}/ | |
- name: 🔄 Changer le propriétaire et les permissions des répertoires | |
run: | | |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "sudo chown -R www-data:www-data ${{ secrets.PROD_DIR }}/bootstrap/cache ${{ secrets.PROD_DIR }}/public ${{ secrets.PROD_DIR }}/storage" | |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "sudo chmod -R 775 ${{ secrets.PROD_DIR }}/bootstrap/cache ${{ secrets.PROD_DIR }}/storage" | |
- name: 🎨 Exécuter les commandes de maintenance Laravel | |
run: | | |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "cd ${{ secrets.PROD_DIR }} && sudo php artisan cache:clear && sudo php artisan route:clear && sudo php artisan view:clear" |