Update .gitea/workflows/deploy.yml
This commit is contained in:
166
.gitea/workflows/deploy.yml
Normal file
166
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,166 @@
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
tech_stack:
|
||||
required: true
|
||||
type: string
|
||||
branch_name:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
app_path_beta:
|
||||
required: false
|
||||
type: string
|
||||
app_path_staging:
|
||||
required: false
|
||||
type: string
|
||||
app_path_prod:
|
||||
required: false
|
||||
type: string
|
||||
|
||||
pm2_id:
|
||||
required: false
|
||||
type: string
|
||||
|
||||
secrets:
|
||||
BETA_SERVER_HOST:
|
||||
required: false
|
||||
BETA_SERVER_PORT:
|
||||
required: false
|
||||
BETA_SERVER_USERNAME:
|
||||
required: false
|
||||
BETA_SERVER_PASSWORD:
|
||||
required: false
|
||||
BETA_SERVER_KEY:
|
||||
required: false
|
||||
|
||||
STAGING_SERVER_HOST:
|
||||
required: false
|
||||
STAGING_SERVER_PORT:
|
||||
required: false
|
||||
STAGING_SERVER_USERNAME:
|
||||
required: false
|
||||
STAGING_SERVER_PASSWORD:
|
||||
required: false
|
||||
STAGING_SERVER_KEY:
|
||||
required: false
|
||||
|
||||
PROD_SERVER_HOST:
|
||||
required: false
|
||||
PROD_SERVER_PORT:
|
||||
required: false
|
||||
PROD_SERVER_USERNAME:
|
||||
required: false
|
||||
PROD_SERVER_PASSWORD:
|
||||
required: false
|
||||
PROD_SERVER_KEY:
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
# 🔹 BETA / TESTING
|
||||
- name: Deploy Beta/Testing
|
||||
if: inputs.branch_name == 'beta' || inputs.branch_name == 'testing'
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.BETA_SERVER_HOST }}
|
||||
username: ${{ secrets.BETA_SERVER_USERNAME }}
|
||||
port: ${{ secrets.BETA_SERVER_PORT }}
|
||||
password: ${{ secrets.BETA_SERVER_PASSWORD }}
|
||||
key: ${{ secrets.BETA_SERVER_KEY }}
|
||||
|
||||
script: |
|
||||
set -xe
|
||||
cd ${{ inputs.app_path_beta }}
|
||||
|
||||
git fetch
|
||||
git reset --hard origin/${{ inputs.branch_name }}
|
||||
git pull origin ${{ inputs.branch_name }}
|
||||
|
||||
case "${{ inputs.tech_stack }}" in
|
||||
node|react|nestjs)
|
||||
npm install
|
||||
npm run build || true
|
||||
pm2 reload ${{ inputs.pm2_id }} || true
|
||||
;;
|
||||
docker)
|
||||
docker compose up -d --build
|
||||
;;
|
||||
*)
|
||||
echo "Unknown tech"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# 🔹 STAGING
|
||||
- name: Deploy Staging
|
||||
if: inputs.branch_name == 'staging'
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.STAGING_SERVER_HOST }}
|
||||
username: ${{ secrets.STAGING_SERVER_USERNAME }}
|
||||
port: ${{ secrets.STAGING_SERVER_PORT }}
|
||||
password: ${{ secrets.STAGING_SERVER_PASSWORD }}
|
||||
key: ${{ secrets.STAGING_SERVER_KEY }}
|
||||
|
||||
script: |
|
||||
set -xe
|
||||
cd ${{ inputs.app_path_staging }}
|
||||
|
||||
git fetch
|
||||
git reset --hard origin/${{ inputs.branch_name }}
|
||||
git pull origin ${{ inputs.branch_name }}
|
||||
|
||||
case "${{ inputs.tech_stack }}" in
|
||||
node|react|nestjs)
|
||||
npm install
|
||||
npm run build || true
|
||||
pm2 reload ${{ inputs.pm2_id }} || true
|
||||
;;
|
||||
docker)
|
||||
docker compose up -d --build
|
||||
;;
|
||||
*)
|
||||
echo "Unknown tech"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# 🔹 PRODUCTION
|
||||
- name: Deploy Production
|
||||
if: inputs.branch_name == 'main' || inputs.branch_name == 'prod'
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.PROD_SERVER_HOST }}
|
||||
username: ${{ secrets.PROD_SERVER_USERNAME }}
|
||||
port: ${{ secrets.PROD_SERVER_PORT }}
|
||||
password: ${{ secrets.PROD_SERVER_PASSWORD }}
|
||||
key: ${{ secrets.PROD_SERVER_KEY }}
|
||||
|
||||
script: |
|
||||
set -xe
|
||||
cd ${{ inputs.app_path_prod }}
|
||||
|
||||
git fetch
|
||||
git reset --hard origin/${{ inputs.branch_name }}
|
||||
git pull origin ${{ inputs.branch_name }}
|
||||
|
||||
case "${{ inputs.tech_stack }}" in
|
||||
node|react|nestjs)
|
||||
npm install
|
||||
npm run build || true
|
||||
pm2 reload ${{ inputs.pm2_id }} || true
|
||||
;;
|
||||
docker)
|
||||
docker compose up -d --build
|
||||
;;
|
||||
*)
|
||||
echo "Unknown tech"
|
||||
;;
|
||||
esac
|
||||
@@ -1,82 +0,0 @@
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
host:
|
||||
required: true
|
||||
type: string
|
||||
username:
|
||||
required: true
|
||||
type: string
|
||||
port:
|
||||
required: true
|
||||
type: number
|
||||
project_folder:
|
||||
required: true
|
||||
type: string
|
||||
pm2_id:
|
||||
required: false
|
||||
type: string
|
||||
branch_name:
|
||||
required: true
|
||||
type: string
|
||||
tech:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
secrets:
|
||||
password:
|
||||
required: false
|
||||
key:
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Deploy via SSH
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ inputs.host }}
|
||||
username: ${{ inputs.username }}
|
||||
password: ${{ secrets.password }}
|
||||
key: ${{ secrets.key }}
|
||||
port: ${{ inputs.port }}
|
||||
|
||||
script: |
|
||||
set -xe
|
||||
|
||||
cd ${{ inputs.project_folder }}
|
||||
|
||||
git fetch
|
||||
git reset --hard origin/${{ inputs.branch_name }}
|
||||
git pull origin ${{ inputs.branch_name }}
|
||||
|
||||
echo "Installing deps"
|
||||
npm install
|
||||
|
||||
echo "Running tech-specific steps"
|
||||
case "${{ inputs.tech }}" in
|
||||
node)
|
||||
npm i
|
||||
npx prisma generate
|
||||
npx prisma migrate deploy
|
||||
npm run build
|
||||
pm2 reload ${{ inputs.pm2_id }}
|
||||
;;
|
||||
nestjs)
|
||||
npm i
|
||||
npx prisma generate
|
||||
npx prisma migrate deploy
|
||||
npm run build
|
||||
pm2 reload ${{ inputs.pm2_id }}
|
||||
;;
|
||||
python)
|
||||
docker-compose up -d --build
|
||||
;;
|
||||
*)
|
||||
echo "Unknown tech"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user