From b14400a6ce4cb1e4c7f114c56faf17100c697418 Mon Sep 17 00:00:00 2001 From: Steve Yonkeu Date: Thu, 8 Aug 2024 12:28:47 +0100 Subject: [PATCH] ci: trigering deployment to ec2 --- .github/workflows/push_to_ec2.yml | 50 +++++++++++++++++++++++++++++++ Dockerfile | 23 -------------- celery_start.sh | 4 +++ start.sh | 7 ++--- supervisord-celery.conf | 10 ------- supervisord-web.conf | 10 ------- 6 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/push_to_ec2.yml delete mode 100644 Dockerfile create mode 100755 celery_start.sh mode change 100644 => 100755 start.sh delete mode 100644 supervisord-celery.conf delete mode 100644 supervisord-web.conf diff --git a/.github/workflows/push_to_ec2.yml b/.github/workflows/push_to_ec2.yml new file mode 100644 index 0000000..aad2154 --- /dev/null +++ b/.github/workflows/push_to_ec2.yml @@ -0,0 +1,50 @@ +name: Deploy Django and Celery to EC2 instance + +on: + push: + branches: + - dev + +jobs: + deploy_project: + name: Deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.7 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v44.5.7 + with: + since_last_remote_commit: true + separator: "," + + - name: Copy files via scp using SSH key + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.DEPLOY_KEY }} + port: ${{ secrets.PORT }} + source: "." + target: ${{ github.event.repository.name }} + + build_project: + name: Build + needs: deploy_project + runs-on: ubuntu-latest + steps: + - name: Executing remote SSH commands using SSH key + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.DEPLOY_KEY }} + port: ${{ secrets.PORT }} + script: | + cd aws-django-redis/ + source venv/bin/activate + pip install -r requirements.txt + python manage.py migrate + sudo supervisorctl reread + sudo supervisorctl update + sudo supervisorctl restart all diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index c3b9a58..0000000 --- a/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM python:3.11-slim - -RUN apt-get update && apt-get install -y supervisor && rm -rf /var/lib/apt/lists/* - -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 - -WORKDIR /app - -RUN pip install --no-cache-dir --upgrade pip==24.2 - -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt - -COPY . /app - -COPY supervisord-web.conf /etc/supervisor/conf.d/ -COPY supervisord-celery.conf /etc/supervisor/conf.d/ - -COPY start.sh /start.sh -RUN chmod +x /start.sh - -CMD ["/start.sh"] diff --git a/celery_start.sh b/celery_start.sh new file mode 100755 index 0000000..4060487 --- /dev/null +++ b/celery_start.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +export $(cat ~/aws-django-redis/.env | xargs) +exec celery -A my_schedular worker --loglevel=INFO diff --git a/start.sh b/start.sh old mode 100644 new mode 100755 index 34b9d75..add3150 --- a/start.sh +++ b/start.sh @@ -1,7 +1,4 @@ #!/bin/bash -/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord-web.conf & - -/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord-celery.conf & - -wait +export $(cat ~/aws-django-redis/.env | xargs) +exec gunicorn my_schedular.wsgi:application --bind 0.0.0.0:8000 diff --git a/supervisord-celery.conf b/supervisord-celery.conf deleted file mode 100644 index 6f5b3d3..0000000 --- a/supervisord-celery.conf +++ /dev/null @@ -1,10 +0,0 @@ -[supervisord] -nodaemon=true -user=root - -[program:celery] -command=celery -A my_schedular worker -l info -autostart=true -autorestart=true -stderr_logfile=/var/log/celery.err.log -stdout_logfile=/var/log/celery.out.log diff --git a/supervisord-web.conf b/supervisord-web.conf deleted file mode 100644 index ee34872..0000000 --- a/supervisord-web.conf +++ /dev/null @@ -1,10 +0,0 @@ -[supervisord] -nodaemon=true -user=root - -[program:web] -command=gunicorn my_schedular.wsgi:application --bind 0.0.0.0:8000 -autostart=true -autorestart=true -stderr_logfile=/var/log/web.err.log -stdout_logfile=/var/log/web.out.log