Add LEGACY_NETWORK variable to environment files #13
@@ -4,7 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- legacy-network-restriction
|
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, synchronize, reopened, closed]
|
types: [opened, synchronize, reopened, closed]
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# STAGE 1: PREPARE
|
# STAGE 1: PREPARE
|
||||||
# Calculate dynamic paths (like PR folders) so other jobs can use them
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
prepare_context:
|
prepare_context:
|
||||||
name: Prepare Context
|
name: Prepare Context
|
||||||
@@ -34,42 +32,37 @@ jobs:
|
|||||||
- id: calc
|
- id: calc
|
||||||
run: |
|
run: |
|
||||||
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
|
||||||
# Only needed for PRs
|
|
||||||
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
||||||
echo "pr_path=${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
|
echo "pr_path=${REMOTE_DEPLOY_PATH}/${REPO_NAME}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# STAGE 2: DEPLOY PREVIEW (DEV)
|
# STAGE 2: DEPLOY PREVIEW (DEV)
|
||||||
# Runs only on Pull Requests
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
deploy_preview:
|
deploy_preview:
|
||||||
name: Deploy (Dev/Preview)
|
name: Deploy (Dev/Preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: prepare_context
|
needs:
|
||||||
|
- prepare_context
|
||||||
if: github.event_name == 'pull_request' && github.event.action != 'closed'
|
if: github.event_name == 'pull_request' && github.event.action != 'closed'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: webfactory/ssh-agent@v0.9.0
|
- uses: webfactory/ssh-agent@v0.9.0
|
||||||
with: { ssh-private-key: ${{ env.SSH_PRIVATE_KEY }} }
|
with:
|
||||||
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
- name: Sync & Build
|
- name: Sync & Build
|
||||||
run: |
|
run: |
|
||||||
# 1. Setup Known Hosts
|
|
||||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
# 2. Define Target
|
|
||||||
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||||
|
|
||||||
# 3. Create Remote Dir
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||||
|
|
||||||
# 4. Sync Files (Exclude .git to save bandwidth)
|
|
||||||
rsync -avz -e "ssh -p ${{ env.SSH_PORT }}" \
|
rsync -avz -e "ssh -p ${{ env.SSH_PORT }}" \
|
||||||
--exclude '.git/' --exclude '.github/' \
|
--exclude '.git/' --exclude '.github/' \
|
||||||
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
||||||
|
|
||||||
# 5. Build and Run on Server
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||||
cd '$TARGET'
|
cd '$TARGET'
|
||||||
docker compose --env-file dev.env -f docker-compose.yaml up -d --build --remove-orphans
|
docker compose --env-file dev.env -f docker-compose.yaml up -d --build --remove-orphans
|
||||||
@@ -77,7 +70,6 @@ jobs:
|
|||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# STAGE 3: DEPLOY STAGING
|
# STAGE 3: DEPLOY STAGING
|
||||||
# Runs on 'main'. Always runs before Prod.
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
deploy_staging:
|
deploy_staging:
|
||||||
name: Deploy (Staging)
|
name: Deploy (Staging)
|
||||||
@@ -85,13 +77,14 @@ jobs:
|
|||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: webfactory/ssh-agent@v0.9.0
|
- uses: webfactory/ssh-agent@v0.9.0
|
||||||
with: { ssh-private-key: ${{ env.SSH_PRIVATE_KEY }} }
|
with:
|
||||||
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
- name: Sync & Build
|
- name: Sync & Build
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
TARGET="${{ env.REMOTE_STAGING_PATH }}"
|
TARGET="${{ env.REMOTE_STAGING_PATH }}"
|
||||||
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||||
@@ -107,22 +100,23 @@ jobs:
|
|||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# STAGE 4: DEPLOY PRODUCTION
|
# STAGE 4: DEPLOY PRODUCTION
|
||||||
# Runs on 'main'. DEPENDS ON STAGING SUCCESS.
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
deploy_prod:
|
deploy_prod:
|
||||||
name: Deploy (Production)
|
name: Deploy (Production)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: deploy_staging # <--- This is the key logic separation
|
needs:
|
||||||
|
- deploy_staging
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: webfactory/ssh-agent@v0.9.0
|
- uses: webfactory/ssh-agent@v0.9.0
|
||||||
with: { ssh-private-key: ${{ env.SSH_PRIVATE_KEY }} }
|
with:
|
||||||
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
- name: Sync & Build
|
- name: Sync & Build
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
TARGET="${{ env.REMOTE_PROD_PATH }}"
|
TARGET="${{ env.REMOTE_PROD_PATH }}"
|
||||||
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "mkdir -p '$TARGET'"
|
||||||
@@ -131,29 +125,28 @@ jobs:
|
|||||||
--exclude '.git/' --exclude '.github/' \
|
--exclude '.git/' --exclude '.github/' \
|
||||||
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
./ ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:$TARGET/
|
||||||
|
|
||||||
# Note: Since Staging just built this commit on the same server,
|
|
||||||
# this build step will be nearly instant (using Docker cache).
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||||
cd '$TARGET'
|
cd '$TARGET'
|
||||||
docker compose --env-file prod.env -f docker-compose.yaml up -d --build --remove-orphans
|
docker compose --env-file prod.env -f docker-compose.yaml up -d --build --remove-orphans
|
||||||
"
|
"
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# CLEANUP (On PR Close)
|
# CLEANUP
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
cleanup:
|
cleanup:
|
||||||
name: Cleanup Preview
|
name: Cleanup Preview
|
||||||
runs-on: ubuntu-latest
|
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)
|
if: github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.pull_request.merged == true)
|
||||||
steps:
|
steps:
|
||||||
- uses: webfactory/ssh-agent@v0.9.0
|
- uses: webfactory/ssh-agent@v0.9.0
|
||||||
with: { ssh-private-key: ${{ env.SSH_PRIVATE_KEY }} }
|
with:
|
||||||
|
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
- name: Remove Remote Environment
|
- name: Remove Remote Environment
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
mkdir -p ~/.ssh && ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
TARGET="${{ needs.prepare_context.outputs.pr_path }}"
|
||||||
|
|
||||||
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
ssh -p ${{ env.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "
|
||||||
|
|||||||
Reference in New Issue
Block a user