Add LEGACY_NETWORK variable to environment files (#13)
All checks were successful
Remote Deployment Pipeline / Prepare Context (push) Successful in 3s
Remote Deployment Pipeline / Deploy (Staging) (push) Successful in 55s
Remote Deployment Pipeline / Deploy (Dev/Preview) (push) Has been skipped
Remote Deployment Pipeline / Cleanup Preview (push) Has been skipped
Remote Deployment Pipeline / Deploy (Production) (push) Successful in 10m47s
All checks were successful
Remote Deployment Pipeline / Prepare Context (push) Successful in 3s
Remote Deployment Pipeline / Deploy (Staging) (push) Successful in 55s
Remote Deployment Pipeline / Deploy (Dev/Preview) (push) Has been skipped
Remote Deployment Pipeline / Cleanup Preview (push) Has been skipped
Remote Deployment Pipeline / Deploy (Production) (push) Successful in 10m47s
Reviewed-on: #13 Co-authored-by: kovagoadi <kovagoadi@gmail.com> Co-committed-by: kovagoadi <kovagoadi@gmail.com>
This commit is contained in:
@@ -8,202 +8,139 @@ on:
|
|||||||
types: [opened, synchronize, reopened, closed]
|
types: [opened, synchronize, reopened, closed]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Base path for PR preview environments
|
# --- PATH CONFIGURATION ---
|
||||||
REMOTE_DEPLOY_PATH: /var/app/traefik/test
|
REMOTE_DEPLOY_PATH: /var/app/traefik/test
|
||||||
|
|
||||||
# --- CUSTOMIZABLE PRODUCTION PATH ---
|
|
||||||
# Set the absolute path for your production deployment on the remote server.
|
|
||||||
REMOTE_PROD_PATH: /var/app/traefik/prod
|
REMOTE_PROD_PATH: /var/app/traefik/prod
|
||||||
|
|
||||||
REMOTE_STAGING_PATH: /var/app/traefik/staging
|
REMOTE_STAGING_PATH: /var/app/traefik/staging
|
||||||
|
|
||||||
|
# --- SECRETS ---
|
||||||
SSH_HOST: ${{ secrets.SSH_HOST }}
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
SSH_USER: ${{ secrets.SSH_USER }}
|
SSH_USER: ${{ secrets.SSH_USER }}
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
SSH_PORT: ${{ secrets.SSH_PORT || 22 }}
|
SSH_PORT: ${{ secrets.SSH_PORT || 22 }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
prepare_deployment_vars:
|
# ------------------------------------------------------------------
|
||||||
name: Prepare deployment vars
|
# STAGE 1: PREPARE CONTEXT
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
prepare_context:
|
||||||
|
name: Prepare Context
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
deploy_path: ${{ steps.set-vars.outputs.deploy_path }}
|
pr_path: ${{ steps.calc.outputs.pr_path }}
|
||||||
steps:
|
steps:
|
||||||
- name: Set deployment variables
|
- id: calc
|
||||||
id: set-vars
|
name: Prepare Context
|
||||||
run: |
|
run: |
|
||||||
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
||||||
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
||||||
# For PRs, create a unique directory under the base path
|
echo "pr_path=${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
|
||||||
DEPLOY_PATH="${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}"
|
|
||||||
else
|
|
||||||
# For 'main' branch, use the specified production path.
|
|
||||||
# Fallback to a default if REMOTE_PROD_PATH is empty.
|
|
||||||
DEPLOY_PATH="${REMOTE_PROD_PATH:-${REMOTE_DEPLOY_PATH}/main}"
|
|
||||||
fi
|
fi
|
||||||
echo "DEPLOY_PATH=${DEPLOY_PATH}" >> $GITHUB_ENV
|
|
||||||
echo "deploy_path=${DEPLOY_PATH}" >> $GITHUB_OUTPUT
|
|
||||||
echo "DEPLOY_PATH will be: ${DEPLOY_PATH}"
|
|
||||||
|
|
||||||
create_remote_directory:
|
# ------------------------------------------------------------------
|
||||||
name: Create remote directory
|
# STAGE 2: DEPLOY PREVIEW (DEV)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
deploy_preview:
|
||||||
|
name: Deploy (Dev/Preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: prepare_deployment_vars
|
needs: [prepare_context]
|
||||||
if: |
|
if: github.event_name == 'pull_request' && github.event.action != 'closed'
|
||||||
(github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)
|
|
||||||
|| github.ref == 'refs/heads/main'
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup SSH
|
- uses: actions/checkout@v4
|
||||||
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1
|
|
||||||
with:
|
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Add host to known_hosts
|
- name: Deploy via Rsync & Docker
|
||||||
run: |
|
uses: easingthemes/ssh-deploy@v5.0.0
|
||||||
mkdir -p ~/.ssh
|
env:
|
||||||
chmod 700 ~/.ssh
|
SSH_PRIVATE_KEY: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
|
REMOTE_HOST: ${{ env.SSH_HOST }}
|
||||||
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
|
REMOTE_USER: ${{ env.SSH_USER }}
|
||||||
exit 1
|
REMOTE_PORT: ${{ env.SSH_PORT }}
|
||||||
}
|
TARGET: ${{ needs.prepare_context.outputs.pr_path }}
|
||||||
chmod 644 ~/.ssh/known_hosts
|
# 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
|
||||||
|
|
||||||
- name: Create directory on remote
|
# ------------------------------------------------------------------
|
||||||
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "mkdir -p '${{ needs.prepare_deployment_vars.outputs.deploy_path }}'"
|
# STAGE 3: DEPLOY STAGING
|
||||||
|
# ------------------------------------------------------------------
|
||||||
sync_repo_files:
|
deploy_staging:
|
||||||
name: Sync repository files
|
name: Deploy (Staging)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [create_remote_directory, prepare_deployment_vars]
|
|
||||||
if: |
|
|
||||||
(github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)
|
|
||||||
|| github.ref == 'refs/heads/main'
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
|
|
||||||
|
|
||||||
- name: Sync files via scp
|
|
||||||
uses: appleboy/scp-action@master
|
|
||||||
with:
|
|
||||||
host: ${{ env.SSH_HOST }}
|
|
||||||
username: ${{ env.SSH_USER }}
|
|
||||||
key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
port: ${{ env.SSH_PORT }}
|
|
||||||
source: "./"
|
|
||||||
target: "${{ needs.prepare_deployment_vars.outputs.deploy_path }}"
|
|
||||||
|
|
||||||
- name: Sync file via scp (staging)
|
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
uses: appleboy/scp-action@master
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- 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
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
deploy_prod:
|
||||||
|
name: Deploy (Production)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [deploy_staging]
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- 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 -f docker-compose.prod.yaml up -d --build --remove-orphans
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# CLEANUP (Using appleboy/ssh-action for pure command execution)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
cleanup:
|
||||||
|
name: Cleanup Preview
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [prepare_context]
|
||||||
|
if: github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.pull_request.merged == true)
|
||||||
|
steps:
|
||||||
|
- name: Remove Remote Environment
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ env.SSH_HOST }}
|
host: ${{ env.SSH_HOST }}
|
||||||
username: ${{ env.SSH_USER }}
|
username: ${{ env.SSH_USER }}
|
||||||
key: ${{ env.SSH_PRIVATE_KEY }}
|
key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
port: ${{ env.SSH_PORT }}
|
port: ${{ env.SSH_PORT }}
|
||||||
source: "./"
|
script: |
|
||||||
target: ${{ env.REMOTE_STAGING_PATH }}
|
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||||
|
if [ -d "$TARGET" ]; then
|
||||||
run_docker_compose_dev:
|
cd "$TARGET"
|
||||||
name: Run docker-compose remotely (Dev)
|
docker compose down -v || true
|
||||||
runs-on: ubuntu-latest
|
cd ..
|
||||||
needs: [sync_repo_files, prepare_deployment_vars]
|
rm -rf "$TARGET"
|
||||||
if: |
|
echo "Cleanup successful"
|
||||||
(github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.merged == false)
|
else
|
||||||
steps:
|
echo "Directory not found, skipping."
|
||||||
- name: Setup SSH
|
fi
|
||||||
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1
|
|
||||||
with:
|
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Add host to known_hosts
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
chmod 700 ~/.ssh
|
|
||||||
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
|
|
||||||
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
chmod 644 ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Run docker-compose on remote host
|
|
||||||
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose --env-file dev.env -f docker-compose.yaml up -d --build"
|
|
||||||
|
|
||||||
run_docker_compose_staging:
|
|
||||||
name: Run docker-compose remotely (Staging)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [sync_repo_files, prepare_deployment_vars]
|
|
||||||
if: |
|
|
||||||
(github.ref == 'refs/heads/main')
|
|
||||||
steps:
|
|
||||||
- name: Setup SSH
|
|
||||||
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1
|
|
||||||
with:
|
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Add host to known_hosts
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
chmod 700 ~/.ssh
|
|
||||||
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
|
|
||||||
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
chmod 644 ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Run docker-compose on remote host
|
|
||||||
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${REMOTE_STAGING_PATH}' && docker-compose --env-file staging.env -f docker-compose.yaml up -d --build"
|
|
||||||
|
|
||||||
run_docker_compose_prod:
|
|
||||||
name: Run docker-compose remotely (Prod)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [sync_repo_files, prepare_deployment_vars]
|
|
||||||
if: |
|
|
||||||
(github.ref == 'refs/heads/main')
|
|
||||||
steps:
|
|
||||||
- name: Setup SSH
|
|
||||||
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1
|
|
||||||
with:
|
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Add host to known_hosts
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
chmod 700 ~/.ssh
|
|
||||||
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
|
|
||||||
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
chmod 644 ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Run docker-compose on remote host
|
|
||||||
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose --env-file prod.env -f docker-compose.yaml up -d --build"
|
|
||||||
|
|
||||||
cleanup_mr_environment:
|
|
||||||
name: Cleanup MR environment
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: prepare_deployment_vars
|
|
||||||
if: |
|
|
||||||
github.event_name == 'pull_request' &&
|
|
||||||
(github.event.action == 'closed' || github.event.pull_request.merged == true)
|
|
||||||
steps:
|
|
||||||
- name: Setup SSH
|
|
||||||
uses: webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd # v0.9.1
|
|
||||||
with:
|
|
||||||
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
- name: Add host to known_hosts
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
chmod 700 ~/.ssh
|
|
||||||
ssh-keyscan -p "$SSH_PORT" -T 10 -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null || {
|
|
||||||
echo "::error::Failed to ssh-keyscan $SSH_HOST:$SSH_PORT"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
chmod 644 ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Run docker-compose down on remote host
|
|
||||||
run: ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "cd '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' && docker-compose down"
|
|
||||||
|
|
||||||
- name: Delete deployment directory
|
|
||||||
run: |
|
|
||||||
ssh -p "$SSH_PORT" $SSH_USER@$SSH_HOST "if [ -d '${{ needs.prepare_deployment_vars.outputs.deploy_path }}' ]; then rm -rf '${{ needs.prepare_deployment_vars.outputs.deploy_path }}'; echo 'Directory removed.'; else echo 'Directory not found, skipping.'; fi"
|
|
||||||
9
docker-compose.prod.yaml
Normal file
9
docker-compose.prod.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
traefik:
|
||||||
|
networks:
|
||||||
|
- proxy
|
||||||
|
- legacy-nginx
|
||||||
|
networks:
|
||||||
|
legacy-nginx:
|
||||||
|
name: proxy
|
||||||
|
external: true
|
||||||
@@ -6,7 +6,6 @@ services:
|
|||||||
- no-new-privileges:true
|
- no-new-privileges:true
|
||||||
networks:
|
networks:
|
||||||
- proxy
|
- proxy
|
||||||
- legacy-nginx
|
|
||||||
command:
|
command:
|
||||||
- "--providers.docker=true"
|
- "--providers.docker=true"
|
||||||
- "--providers.docker.exposedbydefault=false"
|
- "--providers.docker.exposedbydefault=false"
|
||||||
@@ -27,7 +26,7 @@ services:
|
|||||||
- "8080"
|
- "8080"
|
||||||
volumes:
|
volumes:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||||
- "./data/letsencrypt:/letsencrypt"
|
- "letsencrypt:/letsencrypt"
|
||||||
- "./${ENV}/forward-to-legacy-nginx.yaml:/etc/traefik/forward-to-legacy-nginx.yaml"
|
- "./${ENV}/forward-to-legacy-nginx.yaml:/etc/traefik/forward-to-legacy-nginx.yaml"
|
||||||
|
|
||||||
whoami:
|
whoami:
|
||||||
@@ -46,6 +45,3 @@ services:
|
|||||||
- traefik.http.routers.https.tls.certresolver=letsencrypt
|
- traefik.http.routers.https.tls.certresolver=letsencrypt
|
||||||
networks:
|
networks:
|
||||||
proxy:
|
proxy:
|
||||||
legacy-nginx:
|
|
||||||
name: proxy
|
|
||||||
external: true
|
|
||||||
|
|||||||
Reference in New Issue
Block a user