😊 Premier Deploiment - Laravel CD #26
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: 😊 Premier Deploiment - Laravel CD | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Numéro de version pour le déploiement (format: X.Y.Z)' | |
required: true | |
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 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: 🚀 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=conf --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 }}' . ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.PROD_DIR }} | |
- name: 🔄 Changer les permissions de /storage et bootstrap/cache | |
run: | | |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "sudo chown -R www-data:www-data ${{ secrets.PROD_DIR }}/public ${{ secrets.PROD_DIR }}/storage ${{ secrets.PROD_DIR }}/bootstrap/cache && sudo chmod -R 775 ${{ secrets.PROD_DIR }}/storage ${{ secrets.PROD_DIR }}/bootstrap/cache" |