-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (138 loc) · 6.1 KB
/
Copy pathserver-deploy.yml
File metadata and controls
159 lines (138 loc) · 6.1 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
name: Deploy whisker server to AWS
on:
workflow_run:
workflows: ["server-ci"]
types: ["completed"]
branches: ["test","main","preview","test/*","preview/*"]
push:
branches: ["test","main","preview","test/*","preview/*"]
paths:
- 'server/**'
- '.github/workflows/server-deploy.yml'
- '.aws/server_samconfig.toml'
- 'template_server.yml'
- 'docker/Dockerfile.aws.server'
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
actions: write
env:
NODE_VERSION: '20'
PACKAGE_NAME: '@petercat/whiskerrag-client'
jobs:
determine-env:
runs-on: ubuntu-latest
outputs:
environment: ${{ github.ref == 'refs/heads/main' && 'Production' || 'preview' }}
npm_tag: ${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }}
steps:
- name: Determine environment
id: env
run: |
echo "Environment: ${{ github.ref == 'refs/heads/main' && 'Production' || 'preview' }}"
echo "NPM tag: ${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }}"
server-deploy:
needs: determine-env
runs-on: ubuntu-latest
environment: ${{ needs.determine-env.outputs.environment }}
env:
ENVIRONMENT: ${{ needs.determine-env.outputs.environment }}
strategy:
fail-fast: true
outputs:
api_url: ${{ steps.get_api_url.outputs.api_url }}
steps:
- name: Print specific variables
run: |
echo "Current github.ref : ${{ github.ref }}"
echo "Deploying to ${{ env.ENVIRONMENT }}"
echo "Current AWS_REGION: ${{ vars.AWS_REGION }}"
echo "Current WHISKER_ENV: ${{ vars.WHISKER_ENV }}"
echo "GitHub actor: ${{ github.actor }}"
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC
audience: sts.amazonaws.com
aws-region: ${{ vars.AWS_REGION }}
# Build inside Docker containers
- run: sam build --use-container --template template_server.yml --config-file .aws/server_samconfig.toml
# Prevent prompts and failure when the stack is unchanged
- run: |
sam deploy \
--no-confirm-changeset \
--config-env ${{ vars.WHISKER_ENV}} \
--no-fail-on-empty-changeset \
--config-file .aws/server_samconfig.toml \
--parameter-overrides \
ParameterKey=supabaseServiceKey,ParameterValue=${{ secrets.SUPABASE_SERVICE_KEY }} \
ParameterKey=supabaseUrl,ParameterValue=${{ secrets.SUPABASE_URL }} \
ParameterKey=s3TempBucketName,ParameterValue=${{ vars.S3_TEMP_BUCKET_NAME }} \
ParameterKey=webUrl,ParameterValue=${{ vars.WEB_URL }} \
ParameterKey=knowledgeTableName,ParameterValue=${{ vars.KNOWLEDGE_TABLE_NAME }} \
ParameterKey=ApiKeyTableName,ParameterValue=${{ vars.API_KEY_TABLE_NAME }} \
ParameterKey=chunkTableName,ParameterValue=${{ vars.CHUNK_TABLE_NAME }} \
ParameterKey=taskTableName,ParameterValue=${{ vars.TASK_TABLE_NAME }} \
ParameterKey=tenantTableName,ParameterValue=${{ vars.TENANT_TABLE_NAME }} \
ParameterKey=openAIKey,ParameterValue=${{ secrets.OPENAI_API_KEY }} \
ParameterKey=dbEngineClassName,ParameterValue=${{ vars.DB_ENGINE_CLASSNAME }} \
ParameterKey=fastapiEngineClassName,ParameterValue=${{ vars.FASTAPI_ENGINE_CLASSNAME }} \
ParameterKey=taskEngineClassName,ParameterValue=${{ vars.TASK_ENGINE_CLASSNAME }} \
ParameterKey=whiskerEnv,ParameterValue=${{ vars.WHISKER_ENV }} \
ParameterKey=sqsQueueUrl,ParameterValue=${{ vars.SQS_QUEUE_URL }} \
- name: Get Stack Name
id: get_stack_name
run: |
if [ "${{ env.ENVIRONMENT }}" = "Production" ]; then
CONFIG_SECTION="prod"
else
CONFIG_SECTION="preview"
fi
STACK_NAME=$(sed -n "/\[$CONFIG_SECTION\.deploy\.parameters\]/,/^\[/p" .aws/server_samconfig.toml | grep 'stack_name' | cut -d'"' -f2)
if [ -z "$STACK_NAME" ]; then
echo "::error::can not get stack name from .aws/server_samconfig.toml, check it first"
exit 1
fi
echo "Get Stack: ${STACK_NAME}"
echo "STACK_NAME=${STACK_NAME}" >> $GITHUB_ENV
- name: Get API URL
id: get_api_url
run: |
API_URL=$(aws cloudformation describe-stacks \
--stack-name "${{ env.STACK_NAME }}" \
--query 'Stacks[0].Outputs[?OutputKey==`WhiskerFunctionUrl`].OutputValue' \
--output text)
echo "=== CloudFormation ouput ==="
aws cloudformation describe-stacks \
--stack-name "${{ env.STACK_NAME }}" \
--query 'Stacks[0].Outputs' \
--output table
if [[ -z "$API_URL" || "$API_URL" == "None" ]]; then
echo "::error::GET API URL ERROR (stack: ${{ env.STACK_NAME }})"
exit 1
fi
echo "api_url=${API_URL}" >> $GITHUB_OUTPUT
echo "success get API URL: ${API_URL}"
generate-client:
needs: [determine-env, server-deploy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- name: Install swagger-typescript-api
run: npm install -g swagger-typescript-api@latest
- name: Generate and Publish Client
env:
NPM_AUTH_TOKEN: ${{ secrets.WHISKER_NPM_TOKEN }}
working-directory: ${{ github.workspace }}
run: |
${GITHUB_WORKSPACE}/generate-client.sh \
--publish \
--ENVIRONMENT="${{ needs.determine-env.outputs.environment }}" \
--API_URL="${{ needs.server-deploy.outputs.api_url }}" \