-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (50 loc) · 2.16 KB
/
deploy_prod_api.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
name: Deploy API - Prod
on:
push:
branches: [ github-actions-prod ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Get Github action IP
id: ip
uses: haythem/[email protected]
- name: Setting environment variables..
run: |
echo "AWS_DEFAULT_REGION=eu-west-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=${{ secrets.AWS_SECURITY_GROUP_ID_PROD }}" >> $GITHUB_ENV
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
- name: Steps
uses: appleboy/ssh-action@master
continue-on-error: false
with:
host: ${{ secrets.PRODSERVER_API }}
username: ${{ secrets.USERNAME_PROD }}
key: ${{ secrets.SECRETKEY_PROD }}
command_timeout: 10m
script: |
cd xfluencer/influencer-marketplace
pwd
git status
git pull
cd src/api/marketplace
source venv/bin/activate
pip3 install -r requirements.txt
python3 manage.py migrate
python3 manage.py collectstatic -link --noinput
pkill -f "celery worker" && pkill -f "beat" && pkill -f "marketplace"
nohup sh -c 'gunicorn -w 4 marketplace.wsgi:application > gunicorn.out 2>&1' & nohup sh -c 'celery -A marketplace worker -l info > celery_worker.out 2>&1' & nohup sh -c 'celery -A marketplace beat -l info > celery_beat.out 2>&1' & echo -ne '\n'
- name: Remove Github Actions IP from security group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}