-
Notifications
You must be signed in to change notification settings - Fork 1
66 lines (58 loc) · 2.26 KB
/
deploy_uat_agents.yaml
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
name: Deploy UAT Agent
on:
push:
branches:
- "agent/uat/*"
paths:
- "implementation/agent.py"
jobs:
build_and_deploy:
runs-on: ubuntu-latest
environment: uat
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Read agent_name from .agent_name
run: echo "AGENT_NAME=$(grep AGENT_NAME .agent_name | cut -d '=' -f2 | xargs)" >> $GITHUB_ENV
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Get Access Token
id: get_token
run: |
# Obtain the access token
ACCESS_TOKEN=$(gcloud auth print-identity-token --audiences=${{ vars.API_HOST }})
# Mask the access token in logs
echo "::add-mask::$ACCESS_TOKEN"
# Set the access token as an environment variable for use in subsequent steps
echo "ACCESS_TOKEN=$ACCESS_TOKEN" >> $GITHUB_ENV
- name: Call Google Cloud API
run: |
response=$(curl -s -o response.json -w "%{http_code}" ${{ vars.API_HOST }}/checkers \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
-v \
-d '{"name": "'"$AGENT_NAME"'", "type": "ai", "telegramId": null}')
if [ "$response" = "409" ]; then
echo "Name already exists, continuing..."
elif [ "$response" = "200" ]; then
echo "Successfully created agent, continuing..."
else
echo "API call failed with response code $response"
cat response.json
exit 1
fi
- name: Deploy cloud function with pubsub trigger
run: |
gcloud functions deploy agent_$AGENT_NAME \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=. \
--entry-point=subscribe \
--trigger-topic=${{ vars.TOPIC_NAME }} \
--set-env-vars AGENT_NAME=$AGENT_NAME,API_HOST=${{ vars.API_HOST }},WEBDRIVER_HOST=${{ vars.WEBDRIVER_HOST}} \
--set-secrets 'OPENAI_API_KEY=OPENAI_API_KEY:latest'