Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .github/workflows/deploy-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ on:
description: "Docker image digest to deploy"
required: true
type: string
render-service-ids:
description: "Comma-separated list of Render service IDs to deploy to"
render-api-service-id:
description: "Render API service ID"
required: true
type: string
render-worker-service-ids:
description: "Comma-separated list of Render worker service IDs"
required: true
type: string
has-migrations:
description: "Whether this deployment includes database migrations"
required: false
type: boolean
default: false
skip-backend:
description: "Skip backend deployment if no backend changes"
required: false
Expand Down Expand Up @@ -88,8 +97,11 @@ jobs:

- name: Deploy Backend to Render
run: |
IFS=',' read -ra SERVICE_IDS <<< "${{ inputs.render-service-ids }}"
./.github/workflows/deploy_server.sh ${{ inputs.docker-digest }} "${SERVICE_IDS[@]}"
./.github/workflows/deploy_server.sh \
${{ inputs.docker-digest }} \
${{ inputs.has-migrations }} \
"${{ inputs.render-api-service-id }}" \
"${{ inputs.render-worker-service-ids }}"
env:
RENDER_API_TOKEN: ${{ secrets.RENDER_API_TOKEN }}

Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
migrations: ${{ steps.filter.outputs.migrations }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
Expand All @@ -34,6 +35,8 @@ jobs:
- 'clients/**'
- '.github/workflows/deploy.yml'
- '.github/workflows/deploy-environment.yml'
migrations:
- 'server/migrations/**'

build:
name: "Build Docker Image 🐳"
Expand Down Expand Up @@ -103,7 +106,9 @@ jobs:
with:
environment: sandbox
docker-digest: ${{ needs.build.outputs.digest }}
render-service-ids: "srv-crkocgbtq21c73ddsdbg,srv-d089jj7diees73934kgg"
render-api-service-id: "srv-crkocgbtq21c73ddsdbg"
render-worker-service-ids: "srv-d089jj7diees73934kgg"
has-migrations: ${{ needs.changes.outputs.migrations == 'true' || github.event_name == 'workflow_dispatch' }}
skip-backend: ${{ needs.changes.outputs.backend != 'true' && github.event_name != 'workflow_dispatch' }}
skip-frontend: ${{ needs.changes.outputs.frontend != 'true' && github.event_name != 'workflow_dispatch' }}
secrets:
Expand All @@ -122,7 +127,9 @@ jobs:
with:
environment: production
docker-digest: ${{ needs.build.outputs.digest }}
render-service-ids: "srv-ci4r87h8g3ne0dmvvl60,srv-d4k6otfgi27c73cicnpg,srv-d4k62svpm1nc73af5e3g,srv-d3hrh1j3fgac73a1t4r0"
render-api-service-id: "srv-ci4r87h8g3ne0dmvvl60"
render-worker-service-ids: "srv-d4k6otfgi27c73cicnpg,srv-d4k62svpm1nc73af5e3g,srv-d3hrh1j3fgac73a1t4r0"
has-migrations: ${{ needs.changes.outputs.migrations == 'true' || github.event_name == 'workflow_dispatch' }}
skip-backend: ${{ needs.changes.outputs.backend != 'true' && github.event_name != 'workflow_dispatch' }}
skip-frontend: ${{ needs.changes.outputs.frontend != 'true' && github.event_name != 'workflow_dispatch' }}
secrets:
Expand Down
46 changes: 33 additions & 13 deletions .github/workflows/deploy_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

set -euo pipefail

# Usage: ./deploy_server.sh <docker_digest> <service_id_1> [service_id_2] [service_id_n]
if [ $# -lt 2 ]; then
echo "Usage: $0 <docker_digest> <service_id_1> [service_id_2] [service_id_n]"
echo "Example: $0 sha256:abc123... srv-123 srv-456"
# Usage: ./deploy_server.sh <docker_digest> <has_migrations> <api_service_id> <worker_service_ids>
if [ $# -lt 4 ]; then
echo "Usage: $0 <docker_digest> <has_migrations> <api_service_id> <worker_service_ids>"
echo "Example: $0 sha256:abc123... true srv-123 srv-456,srv-789"
exit 1
fi

IMG="ghcr.io/polarsource/polar@${1}"
shift # Remove the first argument, leaving only service IDs
HAS_MIGRATIONS="${2}"
API_SERVICE_ID="${3}"
WORKER_SERVICE_IDS="${4}"

# Read service IDs from remaining arguments
declare -a servers=("$@")
# Convert worker service IDs from comma-separated string to array
IFS=',' read -ra WORKER_SERVERS <<< "$WORKER_SERVICE_IDS"

# Configuration
TIMEOUT=300 # 5 minutes timeout
Expand All @@ -37,9 +39,10 @@ check_deployment_status() {
# Function to deploy a set of servers
deploy_servers() {
local -n servers_ref=$1
local environment=${2:-"unknown"}
local services=${2:-"unknown"}
local environment=${3:-"unknown"}

echo "🚀 Starting deployment to ${environment}..."
echo "🚀 Starting deployment of ${services} to ${environment}..."

# Trigger deployments
local -A deploy_map=() # Maps service_id to deploy_id
Expand All @@ -66,7 +69,7 @@ deploy_servers() {
done

# Wait for deployments to complete
echo "⏳ Waiting for ${environment} deployments to complete..."
echo "⏳ Waiting for ${services} in ${environment} deployments to complete..."

local start_time=$(date +%s)
local all_complete=false
Expand Down Expand Up @@ -116,10 +119,27 @@ deploy_servers() {
fi
done

echo "✅ All deployments completed successfully!"
echo "✅ ${services} deployments completed successfully!"
}

# Deploy the provided servers
deploy_servers servers "environment"
# Deploy based on migration status
if [ "$HAS_MIGRATIONS" = "true" ]; then
echo "📋 Deploying sequentially (migrations detected)"

# Deploy API first (runs migrations via preDeployCommand)
api_server=("$API_SERVICE_ID")
deploy_servers api_server "API" "environment"

# Deploy workers after API completes
if [ ${#WORKER_SERVERS[@]} -gt 0 ]; then
deploy_servers WORKER_SERVERS "workers" "environment"
fi
else
echo "📋 Deploying all services in parallel"

# Deploy all services in parallel
all_servers=("$API_SERVICE_ID" "${WORKER_SERVERS[@]}")
deploy_servers all_servers "All" "environment"
fi

echo "🎉 Deployment completed successfully!"