-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (77 loc) · 2.7 KB
/
ci-cd.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
name: Django CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
DJANGO_SETTINGS_MODULE: eudr_backend.settings
jobs:
test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create env file
run: |
echo "AGSTACK_API_EMAIL=$AGSTACK_API_EMAIL" >> .env
echo "AGSTACK_API_PASSWORD=$AGSTACK_API_PASSWORD" >> .env
echo "EMAIL_HOST_USER=$EMAIL_HOST_USER" >> .env
echo "EMAIL_HOST_PASSWORD=$EMAIL_HOST_PASSWORD" >> .env
echo "EMAIL_HOST_DEFAULT_USER=$EMAIL_HOST_DEFAULT_USER" >> .env
echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> .env
echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> .env
echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> .env
echo "AWS_S3_REGION_NAME=$AWS_S3_REGION_NAME" >> .env
echo "EE_ACCOUNT_NAME=$EE_ACCOUNT_NAME" >> .env
echo "SERVER_USER=$SERVER_USER" >> .env
echo "SERVER_HOST=$SERVER_HOST" >> .env
- name: Create ee creds json file
run: |
echo "${{ secrets.EE_CREDENTIALS_JSON }}" | base64 --decode > ee-eudr-compliance-bc1b62e4e930.json
- name: Apply Migrations
run: python manage.py migrate
- name: Validate ee creds json
run: |
python -c "import json; json.load(open('ee-eudr-compliance-bc1b62e4e930.json'))"
- name: Run Unit Tests
run: python manage.py test
deploy:
name: Deploy to AWS EC2
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set Up SSH Key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY_PEM }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to AWS EC2
env:
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_USER: ${{ secrets.SERVER_USER }}
run: |
ssh $SERVER_USER@$SERVER_HOST << EOF
cd TerraTrac-Validation-Portal/
git pull origin main
source venv/bin/activate
pip install -r requirements.txt &&
python manage.py migrate &&
python manage.py collectstatic --noinput &&
sudo systemctl restart gunicorn
EOF