generated from life-librarians/life-bookshelf-server
-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (120 loc) · 5.14 KB
/
ci.yml
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
name: AI Server CI/CD
on:
push:
workflow_dispatch:
permissions:
contents: read
jobs:
AI-Server-CI:
runs-on: ubuntu-latest
# strategy:
# matrix:
# module:
# - flows/autobiographies/standard/generate_autobiography
# - flows/autobiographies/standard/generate_correction
# - flows/chapters/standard/generate_chapter
# - flows/interviews/chat/interview_chat
# - flows/interviews/standard/generate_interview_questions
steps:
- name: 체크아웃
uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
# - name: Install dependencies for ${{ matrix.module }}
# run: |
# if [ -f ${{ matrix.module }}/requirements.txt ]; then
# pip install -r ${{ matrix.module }}/requirements.txt
# else
# echo "No requirements.txt found for ${{ matrix.module }}. Skipping dependency installation."
# fi
# - name: Batch Run Tests for ${{ matrix.module }}
# # TODO: Batct Run Tests logic 추가
# run: |
# cd ${{ matrix.module }}
# python test_script.py
- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dedendency for FastAPI Server
run: |
cd serve
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Verify Application Build and Run
run: |
cd serve
echo ${{ secrets.ENV_PRODUCTION }} | base64 -d > .env.production
# uvicorn main:app --env-file .env.production --port 3000 &
# sleep 10 # Give some time for the server to start
# curl -f http://127.0.0.1:3000 || (echo "Application failed to start" && exit 1)
# pkill -f "uvicorn main:app --env-file .env.production --port 3000"
shell: bash
- name: Configure AWS credentials
if: ${{ github.ref == 'refs/heads/main' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push Docker image to Amazon ECR
if: ${{ github.ref == 'refs/heads/main' }}
env:
REGISTRY: 211125363878.dkr.ecr.ap-northeast-2.amazonaws.com
REPOSITORY: lifebookshelf-ai
IMAGE_TAG: latest
run: |
cp -r flows deploy-main/
cp -r serve deploy-main/
cd deploy-main
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $REGISTRY
docker buildx build --platform linux/amd64,linux/arm64 -t $REGISTRY/$REPOSITORY:$IMAGE_TAG --push .
rm -rf flows/
- name: Upload deployment package to S3 and trigger CodeDeploy
if: ${{ github.ref == 'refs/heads/main' }}
run: |
mkdir -p deploy && cp -r deploy-main/* deploy/
zip -r deploy.zip deploy
aws s3 cp deploy.zip s3://${{ secrets.AWS_S3_DEPLOY_MAIN_BUCKET_NAME }}/deploy.zip
DEPLOYMENT_ID=$(aws deploy create-deployment \
--application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ secrets.AWS_S3_DEPLOY_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip \
--output text --query 'deploymentId')
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV
- name: Check Deployment Status and Notify
if: ${{ github.ref == 'refs/heads/main' }}
run: |
TIMEOUT=600
INTERVAL=15
ELAPSED=0
while [ $ELAPSED -le $TIMEOUT ]; do
STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID --output text --query 'deploymentInfo.status')
if [[ "$STATUS" == "Succeeded" ]]; then
curl -H "Content-Type: application/json" \
-d '{"content": "AI Server Deployment succeeded! 🚀"}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
exit 0
elif [[ "$STATUS" == "Failed" || "$STATUS" == "Stopped" ]]; then
curl -H "Content-Type: application/json" \
-d '{"content": "AI Server Deployment failed. 🚨"}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
exit 1
fi
sleep $INTERVAL
let ELAPSED=ELAPSED+INTERVAL
done
curl -H "Content-Type: application/json" \
-d '{"content": "AI Server Deployment timed out. ⏲️"}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
exit 1
shell: bash