Skip to content

Commit 7fdb13a

Browse files
authored
Add FE deploy (#363)
1 parent 379dde3 commit 7fdb13a

File tree

2 files changed

+107
-18
lines changed

2 files changed

+107
-18
lines changed
Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,130 @@
1-
name: Deploy to Vapor Production
1+
name: Deploy to Vapor and Frontend
22

33
on:
44
push:
55
branches:
6-
- master
7-
- feat/vapor
6+
- main
7+
- develop
88

99
jobs:
10-
vapor:
11-
name: Deploy to Vapor Production
10+
backend:
11+
name: Deploy Backend
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
# Step 1: Checkout the repository
1615
- uses: actions/checkout@v2
1716

18-
# Step 2: Setup PHP
1917
- name: Setup PHP
2018
uses: shivammathur/setup-php@v2
2119
with:
2220
php-version: 8.3
2321
tools: composer:v2
2422
coverage: none
2523

26-
# Step 3: Prepare Laravel Environment
2724
- name: Prepare Laravel Environment
2825
working-directory: ./backend
2926
run: |
3027
mkdir -p bootstrap/cache
3128
chmod -R 775 bootstrap/cache
3229
33-
# Step 4: Prepare HTMLPurifier Cache Directory
3430
- name: Prepare HTMLPurifier Cache Directory
3531
working-directory: ./backend
3632
run: |
3733
mkdir -p storage/app/htmlpurifier
3834
chmod -R 775 storage/app/htmlpurifier
3935
40-
# Step 5: Install Dependencies
4136
- name: Install Dependencies
4237
working-directory: ./backend
4338
run: composer install --no-dev --no-progress --no-scripts --optimize-autoloader
4439

45-
# Step 6: Install Vapor CLI
4640
- name: Install Vapor CLI
4741
run: composer global require laravel/vapor-cli
4842

49-
# Step 7: Log the branch being deployed (Optional enhancement)
50-
- name: Log Branch
51-
run: echo "Deploying branch ${{ github.ref_name }}"
43+
- name: Set Deployment Environment
44+
run: |
45+
if [[ "${{ github.ref_name }}" == "develop" ]]; then
46+
echo "VAPOR_ENV=staging" >> "$GITHUB_ENV"
47+
else
48+
echo "VAPOR_ENV=production" >> "$GITHUB_ENV"
49+
fi
50+
51+
- name: Log Branch and Environment
52+
run: |
53+
echo "🚀 Deploying branch ${{ github.ref_name }} to Vapor environment: $VAPOR_ENV"
5254
53-
# Step 8: Deploy to the Vapor Production Environment
54-
- name: Deploy to Production
55+
- name: Deploy to Vapor
5556
working-directory: ./backend
56-
run: vapor deploy production
57+
run: vapor deploy $VAPOR_ENV
5758
env:
5859
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
60+
61+
frontend:
62+
name: Deploy Frontend
63+
runs-on: ubuntu-latest
64+
needs: backend
65+
66+
steps:
67+
- uses: actions/checkout@v2
68+
69+
- name: Set Deployment Environment
70+
run: |
71+
if [[ "${{ github.ref_name }}" == "develop" ]]; then
72+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_STAGING_APP_ID }}" >> "$GITHUB_ENV"
73+
else
74+
echo "DO_APP_ID=${{ secrets.DIGITALOCEAN_PRODUCTION_APP_ID }}" >> "$GITHUB_ENV"
75+
fi
76+
77+
- name: Trigger Deployment on DigitalOcean
78+
id: trigger_deployment
79+
run: |
80+
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "https://api.digitalocean.com/v2/apps/$DO_APP_ID/deployments" \
81+
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_API_TOKEN }}" \
82+
-H "Content-Type: application/json")
83+
84+
if [ "$RESPONSE" -ne 200 ]; then
85+
ERROR_MSG=$(jq -r '.message // "Unknown error occurred."' response.json)
86+
echo "❌ Failed to trigger deployment. HTTP Status: $RESPONSE. Error: $ERROR_MSG"
87+
exit 1
88+
fi
89+
90+
DEPLOYMENT_ID=$(jq -r '.deployment.id' response.json)
91+
if [ "$DEPLOYMENT_ID" == "null" ]; then
92+
echo "❌ Failed to extract deployment ID."
93+
exit 1
94+
fi
95+
96+
echo "::add-mask::$DEPLOYMENT_ID"
97+
echo "✅ Deployment triggered successfully."
98+
99+
echo "deployment_id=$DEPLOYMENT_ID" >> "$GITHUB_ENV"
100+
101+
- name: Poll Deployment Status
102+
run: |
103+
MAX_RETRIES=30
104+
SLEEP_TIME=10
105+
COUNTER=0
106+
107+
while [ $COUNTER -lt $MAX_RETRIES ]; do
108+
RESPONSE=$(curl -s -X GET "https://api.digitalocean.com/v2/apps/$DO_APP_ID/deployments/${{ env.deployment_id }}" \
109+
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_API_TOKEN }}" \
110+
-H "Content-Type: application/json")
111+
112+
STATUS=$(echo "$RESPONSE" | jq -r '.deployment.phase')
113+
114+
echo "🔄 Deployment Status: $STATUS"
115+
116+
if [ "$STATUS" == "ACTIVE" ]; then
117+
echo "✅ Deployment completed successfully."
118+
exit 0
119+
elif [[ "$STATUS" == "FAILED" || "$STATUS" == "CANCELLED" ]]; then
120+
echo "❌ Deployment failed or was cancelled."
121+
exit 1
122+
fi
123+
124+
COUNTER=$((COUNTER + 1))
125+
echo "⏳ Retrying in $SLEEP_TIME seconds... ($COUNTER/$MAX_RETRIES)"
126+
sleep $SLEEP_TIME
127+
done
128+
129+
echo "⏰ Deployment timed out."
130+
exit 1

backend/vapor.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ environments:
1919
- 'php artisan optimize'
2020
deploy:
2121
- 'php artisan migrate --force'
22-
22+
staging:
23+
gateway-version: 2.0
24+
domain: staging.hi.events
25+
memory: 1024
26+
cli-memory: 512
27+
runtime: 'php-8.3:al2'
28+
warm: 3
29+
cache: hievents-redis-prod
30+
database: hievents-db-staging
31+
queue: hievents-queue-staging
32+
queue-memory: 1024
33+
queue-concurrency: 2
34+
concurrency: 100
35+
build:
36+
- 'composer install --no-dev'
37+
- 'php artisan optimize'
38+
deploy:
39+
- 'php artisan migrate --force'

0 commit comments

Comments
 (0)