forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (286 loc) · 10.7 KB
/
Copy pathpreview-envs-deploy.yml
File metadata and controls
322 lines (286 loc) · 10.7 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: Preview Environments
on:
pull_request:
branches:
- main
concurrency:
group: preview-${{ github.event.pull_request.number }}-deploy
cancel-in-progress: false
jobs:
build_images:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'automated-version-pr') }}
runs-on: ubuntu-latest
name: Build Images
strategy:
matrix:
app:
- {
project: "coagents-research-canvas",
type: "agent",
runtime: "python",
deps: "local-deps",
}
- {
project: "coagents-research-canvas",
type: "agent",
runtime: "js",
deps: "local-deps",
}
- { project: "coagents-research-canvas", type: "ui" }
- {
project: "coagents-routing",
type: "agent",
runtime: "python",
deps: "local-deps",
}
- {
project: "coagents-routing",
type: "agent",
runtime: "js",
deps: "local-deps",
}
- { project: "coagents-routing", type: "ui" }
- {
project: "coagents-qa-text",
type: "agent",
runtime: "python",
deps: "local-deps",
}
- {
project: "coagents-qa-text",
type: "agent",
runtime: "js",
deps: "local-deps",
}
- { project: "coagents-qa-text", type: "ui" }
- {
project: "coagents-qa-native",
type: "agent",
runtime: "python",
deps: "local-deps",
}
- {
project: "coagents-qa-native",
type: "agent",
runtime: "js",
deps: "local-deps",
}
- { project: "coagents-qa-native", type: "ui" }
- { project: "next-openai", type: "next-openai" }
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Configure AWS Profile
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile default
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile default
aws configure set region us-east-1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: AWS ECR Login
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 058264219587.dkr.ecr.us-east-1.amazonaws.com
- name: (UI) Setup pnpm
if: matrix.app.type == 'ui' || matrix.app.type == 'next-openai'
uses: pnpm/action-setup@v4
with:
version: "9.5"
- name: (UI) Use Node.js 21
if: matrix.app.type == 'ui' || matrix.app.type == 'next-openai'
uses: actions/setup-node@v2
with:
node-version: 21.x
- name: (UI) Install app dependencies
if: matrix.app.type == 'ui'
working-directory: examples/${{ matrix.app.project }}/${{ matrix.app.type }}
run: pnpm install --frozen-lockfile
- name: (UI, Local Deps) Install monorepo
if: matrix.app.type == 'ui' || matrix.app.type == 'next-openai'
working-directory: ./CopilotKit
run: pnpm install --frozen-lockfile
- name: (UI, Local Deps) Build @copilotkit packages
if: matrix.app.type == 'ui' || matrix.app.type == 'next-openai'
working-directory: ./CopilotKit
run: pnpm run freshbuild
- name: (UI, Local Deps) Link @copilotkit packages
if: matrix.app.type == 'ui'
working-directory: ./examples/${{ matrix.app.project }}/${{ matrix.app.type }}
run: |
for package in $(ls -d ../../../CopilotKit/packages/*); do
pnpm link $package
done
- name: (UI) Build app
if: matrix.app.type == 'ui'
working-directory: examples/${{ matrix.app.project }}/${{ matrix.app.type }}
run: pnpm run build
env:
OPENAI_API_KEY: placeholder
- name: (next-openai) Build app
if: matrix.app.type == 'next-openai'
working-directory: CopilotKit/examples/next-openai
run: pnpm run example-build
env:
OPENAI_API_KEY: placeholder
- name: (UI) Build Image
if: matrix.app.type == 'ui'
run: |
docker buildx build \
-t 058264219587.dkr.ecr.us-east-1.amazonaws.com/coagents:${{ matrix.app.project }}-ui-${{ github.run_id }} \
--build-arg APP_DIR=examples/${{ matrix.app.project }}/${{ matrix.app.type }} \
-f ./examples/Dockerfile.${{ matrix.app.type }} \
--platform=linux/amd64 \
--provenance=false \
--push \
.
env:
DOCKER_BUILDKIT: 1
- name: (next-openai) Build Image
if: matrix.app.type == 'next-openai'
run: |
docker buildx build \
-t 058264219587.dkr.ecr.us-east-1.amazonaws.com/coagents:next-openai-${{ github.run_id }} \
-f ./CopilotKit/examples/next-openai/Dockerfile \
--platform=linux/amd64 \
--provenance=false \
--push \
.
env:
DOCKER_BUILDKIT: 1
- name: (Agent) Build Image - Python Agent
if: matrix.app.type == 'agent' && matrix.app.runtime == 'python'
run: |
docker buildx build \
-t 058264219587.dkr.ecr.us-east-1.amazonaws.com/coagents:${{ matrix.app.project }}-agent-python-${{ matrix.app.deps }}-${{ github.run_id }} \
--build-arg APP_DIR=examples/${{ matrix.app.project }}/agent \
-f ./examples/Dockerfile.agent-python \
--build-arg WITH_LOCAL_DEPS=${{ matrix.app.deps == 'local-deps' }} \
--platform=linux/amd64 \
--provenance=false \
--push \
.
env:
DOCKER_BUILDKIT: 1
- name: (Agent) Build Image - JS Agent
if: matrix.app.type == 'agent' && matrix.app.runtime == 'js'
run: |
docker buildx build \
-t 058264219587.dkr.ecr.us-east-1.amazonaws.com/coagents:${{ matrix.app.project }}-agent-js-${{ matrix.app.deps }}-${{ github.run_id }} \
--build-arg APP_DIR=examples/${{ matrix.app.project }}/agent-js \
-f ./examples/Dockerfile.agent-js \
--platform=linux/amd64 \
--provenance=false \
--push \
.
env:
DOCKER_BUILDKIT: 1
deploy:
runs-on: ubuntu-latest
name: Deploy Preview Environments
needs: build_images
outputs:
e2e-urls: ${{ steps.export-e2e-urls.outputs.e2e-urls }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Set Environment Name
id: set-environment-name
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "environment=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "environment=main" >> "$GITHUB_OUTPUT"
fi
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: "9.5"
- name: Use Node.js 21
uses: actions/setup-node@v2
with:
node-version: 21.x
- name: Infra install dependencies
working-directory: infra
run: pnpm i
- name: Install AWS CDK
run: npm install -g aws-cdk
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Configure AWS Profile
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile default
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile default
aws configure set region us-east-1
- name: cdk deploy
working-directory: ./infra
run: cdk deploy --profile default --all --require-approval never --outputs-file=cdk_outputs.json --concurrency 10
env:
UNIQUE_ENV_ID: "PR${{ github.event.number }}"
GITHUB_ACTIONS_RUN_ID: "${{ github.run_id }}"
GITHUB_PR_NUMBER: "${{ github.event.number }}"
- name: Print CDK Outputs
working-directory: infra
run: |
cat cdk_outputs.json
- name: Generate table from outputs
id: generate-table
working-directory: infra
run: |
node generate-table
env:
GITHUB_SHA: ${{ github.sha }}
- name: Delete a comment
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v3
with:
comment-tag: preview-status-update
mode: delete
- name: Comment post-deployment
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v3
with:
comment-tag: preview-status-update
file-path: ./infra/preview-comment.md
- name: Export Variable - E2E URLs
id: export-e2e-urls
working-directory: infra
run: |
echo "e2e-urls=$(node get-e2e-tests-urls.js | base64 -w 0)" >> "$GITHUB_OUTPUT"
- name: Add preview label
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['preview']
})
test:
if: github.event_name == 'pull_request'
name: End to End Tests
uses: ./.github/workflows/e2e.yml
needs: deploy
with:
ref: "${{ github.event.pull_request.head.ref }}"
sha: "${{ github.event.pull_request.head.sha }}"
urls: "${{ needs.deploy.outputs.e2e-urls }}"
pr_number: "${{ github.event.pull_request.number }}"
secrets: inherit