Use github action instead
All checks were successful
Remote Deployment Pipeline / Prepare Context (pull_request) Successful in 3s
Remote Deployment Pipeline / Deploy (Staging) (pull_request) Has been skipped
Remote Deployment Pipeline / Deploy (Dev/Preview) (pull_request) Successful in 56s
Remote Deployment Pipeline / Cleanup Preview (pull_request) Has been skipped
Remote Deployment Pipeline / Deploy (Production) (pull_request) Has been skipped
All checks were successful
Remote Deployment Pipeline / Prepare Context (pull_request) Successful in 3s
Remote Deployment Pipeline / Deploy (Staging) (pull_request) Has been skipped
Remote Deployment Pipeline / Deploy (Dev/Preview) (pull_request) Successful in 56s
Remote Deployment Pipeline / Cleanup Preview (pull_request) Has been skipped
Remote Deployment Pipeline / Deploy (Production) (pull_request) Has been skipped
This commit is contained in:
@@ -21,7 +21,7 @@ env:
|
||||
|
||||
jobs:
|
||||
# ------------------------------------------------------------------
|
||||
# STAGE 1: PREPARE
|
||||
# STAGE 1: PREPARE CONTEXT
|
||||
# ------------------------------------------------------------------
|
||||
prepare_context:
|
||||
name: Prepare Context
|
||||
@@ -42,31 +42,28 @@ jobs:
|
||||
deploy_preview:
|
||||
name: Deploy (Dev/Preview)
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- prepare_context
|
||||
needs: [prepare_context]
|
||||
if: github.event_name == 'pull_request' && github.event.action != 'closed'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Sync & Build
|
||||
run: |
|
||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||
|
||||
rsync -avz -e "ssh -p ${{ env.SSH_PORT }}" \
|
||||
--exclude '.git/' --exclude '.github/' \
|
||||
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||
cd '$TARGET'
|
||||
- name: Deploy via Rsync & Docker
|
||||
uses: easingthemes/ssh-deploy@v5.0.0
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ env.SSH_PRIVATE_KEY }}
|
||||
REMOTE_HOST: ${{ env.SSH_HOST }}
|
||||
REMOTE_USER: ${{ env.SSH_USER }}
|
||||
REMOTE_PORT: ${{ env.SSH_PORT }}
|
||||
TARGET: ${{ needs.prepare_context.outputs.pr_path }}
|
||||
# Exclude git internals to save bandwidth
|
||||
EXCLUDE: ".git/, .github/"
|
||||
# 1. Create directory first
|
||||
SCRIPT_BEFORE: |
|
||||
mkdir -p ${{ needs.prepare_context.outputs.pr_path }}
|
||||
# 2. Run Docker Compose after sync
|
||||
SCRIPT_AFTER: |
|
||||
cd ${{ needs.prepare_context.outputs.pr_path }}
|
||||
docker compose --env-file dev.env -f docker-compose.yaml up -d --build --remove-orphans
|
||||
"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# STAGE 3: DEPLOY STAGING
|
||||
@@ -77,26 +74,21 @@ jobs:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Sync & Build
|
||||
run: |
|
||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||
TARGET="${{ env.REMOTE_STAGING_PATH }}"
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||
|
||||
rsync -avz -e "ssh -p ${{ env.SSH_PORT }}" \
|
||||
--exclude '.git/' --exclude '.github/' \
|
||||
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||
cd '$TARGET'
|
||||
- name: Deploy via Rsync & Docker
|
||||
uses: easingthemes/ssh-deploy@v5.0.0
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ env.SSH_PRIVATE_KEY }}
|
||||
REMOTE_HOST: ${{ env.SSH_HOST }}
|
||||
REMOTE_USER: ${{ env.SSH_USER }}
|
||||
REMOTE_PORT: ${{ env.SSH_PORT }}
|
||||
TARGET: ${{ env.REMOTE_STAGING_PATH }}
|
||||
EXCLUDE: ".git/, .github/"
|
||||
SCRIPT_BEFORE: |
|
||||
mkdir -p ${{ env.REMOTE_STAGING_PATH }}
|
||||
SCRIPT_AFTER: |
|
||||
cd ${{ env.REMOTE_STAGING_PATH }}
|
||||
docker compose --env-file staging.env -f docker-compose.yaml up -d --build --remove-orphans
|
||||
"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# STAGE 4: DEPLOY PRODUCTION
|
||||
@@ -104,59 +96,50 @@ jobs:
|
||||
deploy_prod:
|
||||
name: Deploy (Production)
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- deploy_staging
|
||||
needs: [deploy_staging]
|
||||
if: github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Sync & Build
|
||||
run: |
|
||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||
TARGET="${{ env.REMOTE_PROD_PATH }}"
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||
|
||||
rsync -avz -e "ssh -p ${{ env.SSH_PORT }}" \
|
||||
--exclude '.git/' --exclude '.github/' \
|
||||
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||
cd '$TARGET'
|
||||
- name: Deploy via Rsync & Docker
|
||||
uses: easingthemes/ssh-deploy@v5.0.0
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ env.SSH_PRIVATE_KEY }}
|
||||
REMOTE_HOST: ${{ env.SSH_HOST }}
|
||||
REMOTE_USER: ${{ env.SSH_USER }}
|
||||
REMOTE_PORT: ${{ env.SSH_PORT }}
|
||||
TARGET: ${{ env.REMOTE_PROD_PATH }}
|
||||
EXCLUDE: ".git/, .github/"
|
||||
SCRIPT_BEFORE: |
|
||||
mkdir -p ${{ env.REMOTE_PROD_PATH }}
|
||||
SCRIPT_AFTER: |
|
||||
cd ${{ env.REMOTE_PROD_PATH }}
|
||||
docker compose --env-file prod.env -f docker-compose.yaml up -d --build --remove-orphans
|
||||
"
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# CLEANUP
|
||||
# CLEANUP (Using appleboy/ssh-action for pure command execution)
|
||||
# ------------------------------------------------------------------
|
||||
cleanup:
|
||||
name: Cleanup Preview
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- prepare_context
|
||||
needs: [prepare_context]
|
||||
if: github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.pull_request.merged == true)
|
||||
steps:
|
||||
- uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Remove Remote Environment
|
||||
run: |
|
||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||
|
||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||
if [ -d '$TARGET' ]; then
|
||||
cd '$TARGET'
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.SSH_HOST }}
|
||||
username: ${{ env.SSH_USER }}
|
||||
key: ${{ env.SSH_PRIVATE_KEY }}
|
||||
port: ${{ env.SSH_PORT }}
|
||||
script: |
|
||||
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||
if [ -d "$TARGET" ]; then
|
||||
cd "$TARGET"
|
||||
docker compose down -v || true
|
||||
cd ..
|
||||
rm -rf '$TARGET'
|
||||
echo 'Cleanup successful'
|
||||
rm -rf "$TARGET"
|
||||
echo "Cleanup successful"
|
||||
else
|
||||
echo 'Directory not found, skipping.'
|
||||
fi
|
||||
"
|
||||
echo "Directory not found, skipping."
|
||||
fi
|
||||
Reference in New Issue
Block a user