Skip to content

Commit

Permalink
up worklfow
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloeatworld committed Oct 10, 2024
1 parent 08dc574 commit 8988fb4
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 31 deletions.
65 changes: 40 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,86 @@
name: 😊 Deploiment - Laravel CD
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]
uses: actions/[email protected]
with:
fetch-depth: '0'

- name: ⚙️ Configuration de PHP
uses: shivammathur/setup-php@2.25.4
uses: shivammathur/setup-php@2.30.4
with:
php-version: '8.2'
extensions: 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
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-progress --prefer-dist --optimize-autoloader
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/ssh-agent@v0.8.0
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: 🚀 Déployer sur le serveur
- 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: |
rsync -r -avz -O --delete-after --exclude=.git --exclude=.github --exclude=dist --exclude=node_modules --exclude=.env --quiet -e 'ssh -p ${{ secrets.REMOTE_PORT }}' ${{ secrets.REMOTE_PATH }} $GITHUB_WORKSPACE/InstaRepas/ ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.REMOTE_DIR }}
- name: 🔄 Changer les permissions de /storage et bootstrap/cache
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: |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "${{ secrets.REMOTE_OWN }} ${{ secrets.REMOTE_DIR }}/storage"
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "${{ secrets.REMOTE_OWN }} ${{ secrets.REMOTE_DIR }}/bootstrap/cache"
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "${{ secrets.REMOTE_MOD }} ${{ secrets.REMOTE_DIR }}/storage"
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "${{ secrets.REMOTE_MOD }} ${{ secrets.REMOTE_DIR }}/bootstrap/cache"
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "${{ secrets.REMOTE_WWW }} ${{ secrets.REMOTE_DIR }}/public"
- name: 🔑 Copie du fichier .env si absent
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=kubernetes --exclude=database --exclude=install.sh --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 le propriétaire et les permissions des répertoires
run: |
ssh -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "if [ ! -f ${{ secrets.REMOTE_DIR }}/.env ]; then cp ${{ secrets.REMOTE_DIR }}/.env.example ${{ secrets.REMOTE_DIR }}/.env; fi"
- name: 🔄 Générer la clé Laravel si nécessaire
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 }} "if grep -q 'APP_KEY=' ${{ secrets.REMOTE_DIR }}/.env && grep -q '^APP_KEY=$' ${{ secrets.REMOTE_DIR }}/.env; then cd ${{ secrets.REMOTE_DIR }} && php artisan key:generate; fi"
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"
80 changes: 80 additions & 0 deletions .github/workflows/rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: 🔄 Rollback Deployment

on:
workflow_dispatch:
inputs:
tag_to_deploy:
description: 'Tag Git à déployer'
required: true

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Récupération du code source
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.tag_to_deploy }}
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: |
pwd
ls -la
- name: 🛠️ Installation des dépendances du projet
run: |
composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
npm install
- name: 🏗️ Construction du Projet
run: |
npm run build
- 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: 🗑️ 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=kubernetes --exclude=install.sh --exclude=database --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 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"
6 changes: 3 additions & 3 deletions .github/workflows/ssh-test-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:

steps:
- name: 📦 Récupération du Code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v4.1.4

- name: 🗝️ Installer la clé SSH
uses: shimataro/ssh-key-action@v2.5.1
uses: shimataro/ssh-key-action@v2.7.0
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}

- name: 🖥️ Tester la connexion SSH
run: ssh -p ${{ secrets.REMOTE_PORT }} -T ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}
run: ssh -p ${{ secrets.REMOTE_PORT }} -T ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}
6 changes: 3 additions & 3 deletions InstaRepas/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_DATABASE=grling_instarepas
DB_USERNAME=grling_instarepas
DB_PASSWORD=

BROADCAST_DRIVER=log
Expand Down

0 comments on commit 8988fb4

Please sign in to comment.