forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (209 loc) · 10 KB
/
Copy pathebs-common-stage-prod.yml
File metadata and controls
249 lines (209 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: EBS Common - Staging/Prod Deploy
on:
workflow_dispatch:
inputs:
branch:
description: "Select a Branch to deploy"
required: true
default: "main"
environment:
description: "Select environment to deploy (staging or prod)"
required: true
default: "staging"
email:
description: "Admin email for deployment"
required: true
default: "saravana.k.r@gmail.com"
commit_id:
description: "Commit ID to deploy (leave blank for latest on branch)"
required: false
default: ""
env:
STAGING_HOST: staging.visualaiagentsbuilder.com
PROD_HOST: visualaiagentsbuilder.com
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout selected branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Checkout specific commit if provided
if: ${{ github.event.inputs.commit_id != '' }}
run: |
git fetch --depth=1 origin ${{ github.event.inputs.commit_id }}
git checkout ${{ github.event.inputs.commit_id }}
echo "✅ Checked out commit ${{ github.event.inputs.commit_id }}"
- name: Determine Commit ID
id: commit
run: |
if [ -n "${{ github.event.inputs.commit_id }}" ]; then
echo "commit_id=${{ github.event.inputs.commit_id }}" >> $GITHUB_OUTPUT
else
if [ "${{ github.event.inputs.branch }}" = "main" ]; then
COMMIT_ID=$(git rev-parse HEAD)
else
COMMIT_ID=$(git log -1 --format="%H")
fi
echo "commit_id=$COMMIT_ID" >> $GITHUB_OUTPUT
fi
- name: Determine Branch Name
id: branch
run: |
BRANCH_NAME=$(echo "${{ github.event.inputs.branch }}" | tr '/' '-')
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y sshpass
- name: Create GitHub Deployment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
COMMIT_ID=${{ steps.commit.outputs.commit_id }}
ENVIRONMENT=${{ github.event.inputs.environment }}
BRANCH=${{ github.event.inputs.branch }}
ACTOR=${{ github.actor }}
echo "📦 Creating deployment for $ENVIRONMENT commit=$COMMIT_ID branch=$BRANCH"
DEPLOYMENT_ID=$(gh api repos/${{ github.repository }}/deployments \
-F ref=${{ github.event.inputs.branch }} \
-F environment=$ENVIRONMENT \
-F description="Deployment by $ACTOR from branch $BRANCH with commit $COMMIT_ID" \
-F auto_merge=false \
-F required_contexts[]=null --jq '.id')
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV
- name: Mark Deployment In Progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/${{ github.repository }}/deployments/${{ env.DEPLOYMENT_ID }}/statuses \
-F state=in_progress \
-F description="Deployment started and is in progress"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: forwardemailforaifirstdesk
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker Image (for staging)
if: ${{ github.event.inputs.environment == 'staging' }}
run: |
COMMIT_ID=${{ steps.commit.outputs.commit_id }}
BRANCH_NAME=${{ steps.branch.outputs.branch_name }}
echo "Using branch=$BRANCH_NAME commit=$COMMIT_ID"
echo "=== Building Staging Image ==="
DOCKER_BUILDKIT=1 \
VITE_AUTO_LOGIN=false \
VITE_CLERK_AUTH_ENABLED=true \
VITE_CLERK_PUBLISHABLE_KEY=${{ secrets.CLERK_PUBLISHABLE_KEY }} \
make docker_build TAG=langflow:staging-$BRANCH_NAME-$COMMIT_ID
docker tag langflow:staging-$BRANCH_NAME-$COMMIT_ID forwardemailforaifirstdesk/langflow:staging-$BRANCH_NAME-$COMMIT_ID
docker push forwardemailforaifirstdesk/langflow:staging-$BRANCH_NAME-$COMMIT_ID
echo "=== Building Prod Image ==="
DOCKER_BUILDKIT=1 \
VITE_AUTO_LOGIN=false \
VITE_CLERK_AUTH_ENABLED=true \
VITE_CLERK_PUBLISHABLE_KEY=${{ secrets.PROD_CLERK_PUBLISHABLE_KEY }} \
make docker_build TAG=langflow:prod-$BRANCH_NAME-$COMMIT_ID
docker tag langflow:prod-$BRANCH_NAME-$COMMIT_ID forwardemailforaifirstdesk/langflow:prod-$BRANCH_NAME-$COMMIT_ID
docker push forwardemailforaifirstdesk/langflow:prod-$BRANCH_NAME-$COMMIT_ID
- name: Cleanup old Docker Hub tags (skip for prod)
if: ${{ github.event.inputs.environment == 'staging' }}
run: |
#!/usr/bin/env bash
set -euo pipefail
DOCKERHUB_USERNAME="forwardemailforaifirstdesk"
DOCKERHUB_PASSWORD="${{ secrets.DOCKERHUB_TOKEN }}"
REPOSITORY="forwardemailforaifirstdesk/langflow"
echo "=== Getting Docker Hub token ==="
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST \
-d '{"username": "'$DOCKERHUB_USERNAME'", "password": "'$DOCKERHUB_PASSWORD'"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
if [ -z "$TOKEN" ] || [ "$TOKEN" == "null" ]; then
echo "❌ Failed to authenticate"
exit 1
fi
echo "✅ Authentication successful"
echo "=== Fetching tags ==="
RESPONSE=$(curl -s -H "Authorization: JWT $TOKEN" \
"https://hub.docker.com/v2/repositories/$REPOSITORY/tags?page_size=100")
TAGS=$(echo "$RESPONSE" | jq -r '.results[] | .name')
if [ -z "$TAGS" ]; then
echo "ℹ️ No tags found in repository $REPOSITORY. Nothing to delete."
exit 0
fi
echo "Found tags: $TAGS"
for TAG in $TAGS; do
COMMIT_ID=${{ steps.commit.outputs.commit_id }}
BRANCH_NAME=${{ steps.branch.outputs.branch_name }}
if [[ "$TAG" == "staging-$BRANCH_NAME-$COMMIT_ID" || "$TAG" == "prod-$BRANCH_NAME-$COMMIT_ID" ]]; then
echo "⏭️ Skipping current branch+commit tag: $TAG"
continue
fi
echo "Deleting old tag: $TAG"
DELETE_RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" \
-X DELETE -H "Authorization: JWT $TOKEN" \
"https://hub.docker.com/v2/repositories/$REPOSITORY/tags/$TAG/")
HTTP_CODE=$(echo $DELETE_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
if [ "$HTTP_CODE" = "204" ]; then
echo " ✅ Successfully deleted tag $TAG"
else
echo " ❌ Failed to delete tag $TAG (HTTP: $HTTP_CODE)"
fi
sleep 1
done
echo "Note: Docker Hub will automatically clean up unreferenced images within 24-48 hours"
- name: Copy deployment files to VM
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ github.event.inputs.environment == 'staging' && env.STAGING_HOST || env.PROD_HOST }}
username: root
password: ${{ github.event.inputs.environment == 'staging' && secrets.VM_PASSWORD || secrets.PROD_VM_PASSWORD }}
source: "./deploy/ebs-staging-prod.sh,./.env-file"
target: /root/
- name: Run deployment script on VM
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ github.event.inputs.environment == 'staging' && env.STAGING_HOST || env.PROD_HOST }}
username: root
password: ${{ github.event.inputs.environment == 'staging' && secrets.VM_PASSWORD || secrets.PROD_VM_PASSWORD }}
script: |
chmod +x /root/deploy/ebs-staging-prod.sh
if [ "${{ github.event.inputs.environment }}" = "staging" ]; then
/root/deploy/ebs-staging-prod.sh \
--image forwardemailforaifirstdesk/langflow:staging-${{ steps.branch.outputs.branch_name }}-${{ steps.commit.outputs.commit_id }} \
--domain ${{env.STAGING_HOST}} \
--email ${{ github.event.inputs.email }} \
--env-file /root/.env-file \
--db-user ${{ secrets.POSTGRES_USER }} \
--db-password ${{ secrets.POSTGRES_PASSWD }} \
--db-name ${{ secrets.POSTGRES_DB }} \
--volume-name ${{ vars.STAGING_VOLUME_NAME }}
else
/root/deploy/ebs-staging-prod.sh \
--image forwardemailforaifirstdesk/langflow:prod-${{ steps.branch.outputs.branch_name }}-${{ steps.commit.outputs.commit_id }} \
--domain ${{env.PROD_HOST}} \
--email ${{ github.event.inputs.email }} \
--env-file /root/.env-file \
--db-user ${{ secrets.PROD_POSTGRES_USER }} \
--db-password ${{ secrets.PROD_POSTGRES_PASSWD }} \
--db-name ${{ secrets.PROD_POSTGRES_DB }} \
--volume-name ${{ vars.PROD_VOLUME_NAME }}
fi
- name: Copy deploy_status.env from VM
run: |
sshpass -p "${{ secrets.VM_PASSWORD }}" scp -o StrictHostKeyChecking=no \
root@staging.visualaiagentsbuilder.com:/root/deploy_status.env \
$GITHUB_WORKSPACE/deploy_status.env
- name: Update GitHub Deployment Status with Docker info
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source "${GITHUB_WORKSPACE}/deploy_status.env"
# Encode container info for safe URL usage
CONTAINER_ENCODED=$(echo "$FINAL_CONTAINER" | jq -s -R -r @uri)
gh api repos/${{ github.repository }}/deployments/${{ env.DEPLOYMENT_ID }}/statuses \
-F state=$FINAL_STATUS \
-F description="$FINAL_DESCRIPTION" \
-F log_url="https://logs.${{ github.repository_owner }}.com/deploy/${{ env.DEPLOYMENT_ID }}?container=${CONTAINER_ENCODED}"