Skip to content

Merge pull request #34 from agstack/dev #37

Merge pull request #34 from agstack/dev

Merge pull request #34 from agstack/dev #37

Workflow file for this run

name: Django CI/CD Pipeline
on:
push:
branches:
- main
- dev
pull_request:
branches:
- dev
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' || github.head_ref == '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