mirror of
https://github.com/ghndrx/shellmate.git
synced 2026-02-10 06:45:02 +00:00
Fix deploy workflow and create staging/main branches
- develop: auto-deploy to dev.shellmate.sh - staging: auto-deploy to staging.shellmate.sh - main: auto-deploy to production shellmate.sh Proper CI/CD flow: 1. Feature branch → PR to develop → CI tests → merge → deploy dev 2. develop → PR to staging → deploy staging 3. staging → PR to main → deploy production
This commit is contained in:
76
.github/workflows/deploy.yml
vendored
76
.github/workflows/deploy.yml
vendored
@@ -2,66 +2,62 @@ name: Deploy
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main, develop, staging]
|
branches: [main, staging, develop]
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
env:
|
||||||
environment:
|
SERVER_IP: "46.225.26.166"
|
||||||
description: 'Environment to deploy to'
|
SSH_PORT: "2222"
|
||||||
required: true
|
|
||||||
default: 'dev'
|
|
||||||
type: choice
|
|
||||||
options:
|
|
||||||
- dev
|
|
||||||
- staging
|
|
||||||
- production
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: []
|
if: github.event_name == 'push'
|
||||||
environment:
|
|
||||||
name: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/staging' && 'staging' || 'dev' }}
|
|
||||||
url: ${{ github.ref == 'refs/heads/main' && 'https://shellmate.sh' || github.ref == 'refs/heads/staging' && 'https://staging.shellmate.sh' || 'https://dev.shellmate.sh' }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set environment variables
|
- name: Determine environment
|
||||||
id: env
|
id: env
|
||||||
run: |
|
run: |
|
||||||
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
||||||
echo "env_name=production" >> $GITHUB_OUTPUT
|
echo "name=production" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
|
echo "url=https://shellmate.sh" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_port=22" >> $GITHUB_OUTPUT
|
echo "ssh_user=play" >> $GITHUB_OUTPUT
|
||||||
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then
|
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then
|
||||||
echo "env_name=staging" >> $GITHUB_OUTPUT
|
echo "name=staging" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
|
echo "url=https://staging.shellmate.sh" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_port=2223" >> $GITHUB_OUTPUT
|
echo "ssh_user=play" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "env_name=dev" >> $GITHUB_OUTPUT
|
echo "name=dev" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
|
echo "url=https://dev.shellmate.sh" >> $GITHUB_OUTPUT
|
||||||
echo "ssh_port=2222" >> $GITHUB_OUTPUT
|
echo "ssh_user=play" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Deploy to ${{ steps.env.outputs.env_name }}
|
- name: Setup SSH
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
run: |
|
||||||
with:
|
mkdir -p ~/.ssh
|
||||||
host: ${{ steps.env.outputs.ssh_host }}
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
||||||
username: root
|
chmod 600 ~/.ssh/deploy_key
|
||||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SERVER_IP }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
port: ${{ steps.env.outputs.ssh_port }}
|
|
||||||
script: |
|
- name: Deploy to ${{ steps.env.outputs.name }}
|
||||||
|
run: |
|
||||||
|
ssh -i ~/.ssh/deploy_key -p ${{ env.SSH_PORT }} -o StrictHostKeyChecking=no root@${{ env.SERVER_IP }} << 'ENDSSH'
|
||||||
cd /opt/shellmate
|
cd /opt/shellmate
|
||||||
git fetch origin
|
git fetch origin
|
||||||
git checkout ${{ github.ref_name }}
|
git checkout ${{ github.ref_name }}
|
||||||
git pull origin ${{ github.ref_name }}
|
git pull origin ${{ github.ref_name }}
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
echo "Deployed ${{ github.ref_name }} to ${{ steps.env.outputs.env_name }}"
|
echo "✅ Deployed ${{ github.ref_name }} to ${{ steps.env.outputs.name }}"
|
||||||
|
ENDSSH
|
||||||
|
|
||||||
- name: Deployment summary
|
- name: Summary
|
||||||
run: |
|
run: |
|
||||||
echo "## Deployment Complete 🚀" >> $GITHUB_STEP_SUMMARY
|
echo "## 🚀 Deployment Complete" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "" >> $GITHUB_STEP_SUMMARY
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Environment:** ${{ steps.env.outputs.env_name }}" >> $GITHUB_STEP_SUMMARY
|
echo "| | |" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
|
echo "| **Environment** | ${{ steps.env.outputs.name }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **URL** | ${{ steps.env.outputs.url }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|||||||
Reference in New Issue
Block a user