Skip to content

Commit

Permalink
feat: add adonisjs workflow and nginx.cong + update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Leoglme committed Jan 13, 2024
1 parent 03f155a commit 60be520
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 7 deletions.
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,45 @@ Each folder contains a `deploy-vps.yml` file for GitHub Actions and an `nginx.co
Replace `example.com` with your domain or subdomain name.


## Nuxt.js 3 / Vue.js 3 / AdonisJS Deployment
### How to Use
## Specific Deployment Instructions

1. Navigate to the folder for your technology (e.g. `nuxtjs3`).
2. Use the `deploy-vps.yml` in your GitHub Actions workflow to automate the deployment process.
### Nuxt.js 3 Deployment

- #### GitHub Actions Workflow
1. Navigate to the [nuxtjs3](nuxtjs3) directory.
2. Use the [deploy-vps.yml](nuxtjs3/deploy-vps.yml) in your GitHub Actions workflow to automate the deployment process.
3. Add `SSH_HOST`, `SSH_USERNAME`, `SSH_PRIVATE_KEY`, and `SSH_PORT` as secrets to your GitHub repository.
4. Replace `/var/www/dibodev.com/html` with the path to your application on your VPS.
5. Replace `dibodev.com` with your pm2 process name.
6. Customize the `nginx.conf` file as needed and place it in your Nginx configuration directory (usually `/etc/nginx/sites-available`) on your VPS.

- #### Nginx Configuration
1. Customize the [nginx.conf](nuxtjs3/nginx.conf) file as needed and place it in your Nginx configuration directory (usually `/etc/nginx/sites-available`) on your VPS.


### Vue.js 3 Deployment

- Navigate to the `vuejs3` directory.

- #### GitHub Actions Workflow
Coming soon...

- #### Nginx Configuration
Coming soon...

### AdonisJS Deployment

- #### GitHub Actions Workflow
1. Navigate to the [adonisjs](adonisjs) directory.
2. Use the [deploy-vps.yml](adonisjs/deploy-vps.yml) in your GitHub Actions workflow to automate the deployment process.
3. Add `SSH_HOST`, `SSH_USERNAME`, `SSH_PRIVATE_KEY`, and `SSH_PORT` as secrets to your GitHub repository.
4. To generate .env file, add `APP_KEY`, `MYSQL_DATABASE`, `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_ROOT_PASSWORD` as secrets to your GitHub repository.
5. Replace `/var/www/dibodev.com/html` with the path to your application on your VPS.
6. Replace `dibodev.com` with your pm2 process name.

- #### Nginx Configuration
1. Customize the [nginx.conf](adonisjs/nginx.conf) file as needed and place it in your Nginx configuration directory (usually `/etc/nginx/sites-available`) on your VPS.



## Resolve problems
- resolve the right problem on job 📤 Deploy to VPS
Expand Down
73 changes: 73 additions & 0 deletions adonisjs/deploy-vps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 🚀 Deploy API to OVH VPS

on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
env:
APP_DIR: /var/www/dibodev.com
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v4

- name: 🚀 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: 🔍 Install dependencies
run: npm install

- name: 📝 Create .env file
run: |
echo "PORT=3333" > .env
echo "HOST=0.0.0.0" >> .env
echo "NODE_ENV=production" >> .env
echo "APP_KEY=${{ secrets.APP_KEY }}" >> .env
echo "DRIVE_DISK=local" >> .env
echo "DB_CONNECTION=mysql" >> .env
echo "MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }}" >> .env
echo "MYSQL_HOST=${{ secrets.MYSQL_HOST }}" >> .env
echo "MYSQL_PORT=3306" >> .env
echo "MYSQL_USER=${{ secrets.MYSQL_USER }}" >> .env
echo "MYSQL_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .env
echo "CACHE_VIEWS=false" >> .env
echo "BASE_URL=https://dibodev.com" >> .env
- name: 🧱 Build application
run: |
npm run build
cp .env build/.env
- name: 🛁 Clean install for production
run: cd build && npm ci --production --ignore-scripts

- name: 📤 Deploy to VPS
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "./build/"
target: ${{ env.APP_DIR }}/html

- name: 🚀 Restart API with PM2, Run Migrations and Seeders
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ env.APP_DIR }}/html/build
pm2 restart dibodev.com || pm2 start server.js --name dibodev.com
pm2 save
node ace migration:run --force
node ace db:seed
28 changes: 28 additions & 0 deletions adonisjs/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80;
listen [::]:80;

listen 443 ssl;
listen [::]:443 ssl;

server_name dibodev.com www.dibodev.com;

ssl_certificate /etc/letsencrypt/live/dibodev.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dibodev.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location / {
proxy_pass http://localhost:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

# Redirections pour Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
}
6 changes: 4 additions & 2 deletions nuxtjs3/deploy-vps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
build:
name: 🏗️ Build
runs-on: ubuntu-latest
env:
APP_DIR: /var/www/dibodev.com
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -47,7 +49,7 @@ jobs:
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ".output/"
target: "/var/www/dibodev.com/html"
target: ${{ env.APP_DIR }}/html

- name: 🚀 Install dependencies and restart Server with PM2
uses: appleboy/ssh-action@master
Expand All @@ -57,6 +59,6 @@ jobs:
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/dibodev.com/html/.output
cd ${{ env.APP_DIR }}/html/.output
npm install
pm2 restart dibodev.com || pm2 start server.js --name dibodev.com

0 comments on commit 60be520

Please sign in to comment.