From 6e038ead84b5d28653e19ed492cae3350210beb4 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 29 Oct 2025 01:35:49 +0100 Subject: [PATCH] Automates deployment workflow using Gitea Actions Sets up a Gitea Actions workflow to automatically build and deploy the React portfolio website to the production server. This includes: - Using a containerized environment for consistent builds. - Installing dependencies and building the project. - Deploying the built files to the web server via SSH and rsync. - Reloading the web server configuration to apply changes. Also, this change updates the .gitignore file to exclude the 'dist' directory. --- .gitea/workflows/deploy.yaml | 61 +++++++++++++++++++++++------------- .gitignore | 3 ++ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 3359369..b9d8729 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -1,4 +1,4 @@ -name: Deploy Portfolio +name: Deploy React portfolio on: push: @@ -8,35 +8,52 @@ on: jobs: deploy: runs-on: ubuntu-latest + container: + image: node:20-bookworm + volumes: + - /home/deploy/.ssh:/root/.ssh:ro steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' + - name: Install SSH client + run: | + apt-get update && apt-get install -y openssh-client rsync - - name: Install dependencies + - name: Checkout + uses: actions/checkout@v4 + + - name: Install deps run: npm ci - name: Build run: npm run build - + + - name: Check SSH keys + run: | + echo "=== SSH keys available? ===" + ls -la /root/.ssh/ + - name: Deploy to web server run: | - cd dist - tar czf ../portfolio.tar.gz * - cd .. + # determine build output dir + if [ -d build ]; then DIR=build + elif [ -d dist ]; then DIR=dist + else + echo "❌ No build output directory found" >&2 + ls -la + exit 1 + fi + echo "Using build dir: $DIR" + + # deploy + tar czf portfolio.tar.gz -C "$DIR" . scp -i /root/.ssh/deploy_to_web -o StrictHostKeyChecking=accept-new portfolio.tar.gz deploy@91.98.34.152:/tmp/ - ssh -i /root/.ssh/deploy_to_web -o StrictHostKeyChecking=accept-new deploy@91.98.34.152 "cd /tmp && \ - sudo rm -rf /var/www/louisemard.dev/* && \ - tar xzf portfolio.tar.gz -C /var/www/louisemard.dev/ && \ - rm portfolio.tar.gz && \ - sudo chown -R deploy:www-data /var/www/louisemard.dev/ && \ - sudo chmod -R 775 /var/www/louisemard.dev/ && \ - sudo systemctl reload nginx" + ssh -i /root/.ssh/deploy_to_web -o StrictHostKeyChecking=accept-new deploy@91.98.34.152 "\ + sudo rm -rf /var/www/louisemard.dev/* && \ + sudo tar xzf /tmp/portfolio.tar.gz -C /var/www/louisemard.dev/ && \ + sudo rm /tmp/portfolio.tar.gz && \ + sudo chown -R deploy:www-data /var/www/louisemard.dev && \ + sudo chmod -R 775 /var/www/louisemard.dev && \ + sudo systemctl reload nginx" - - name: Deployment success - run: echo "✅ Portfolio déployé sur https://louisemard.dev" \ No newline at end of file + - name: Success + run: echo "✅ Déployé sur https://louisemard.dev" \ No newline at end of file diff --git a/.gitignore b/.gitignore index ed0d3c8..12a47fb 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,6 @@ typings/ # DynamoDB Local files .dynamodb/ + +# Vite react build output +dist/ \ No newline at end of file