Skip to content

Add pub_date field to recipe endpoints, update Recipe model docstring… #649

Add pub_date field to recipe endpoints, update Recipe model docstring…

Add pub_date field to recipe endpoints, update Recipe model docstring… #649

name: good_food workflow
on:
push:
branches:
jobs:
flake8_and_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: send start message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.workflow }} started!
Repository: ${{ github.repository }}.
Branch name: ${{ github.ref_name }}.
Commit author: ${{ github.actor }}.
Commit message: ${{ github.event.commits[0].message }}.
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1
virtualenvs-create: false
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
- name: Test with flake8
run: |
python -m flake8
- name: Test with pytest
run: |
cd backend
pytest
- name: send message
if: ${{ github.ref != 'refs/heads/main' }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.workflow }} completed successfully!
Repository: ${{ github.repository }}.
Branch name: ${{ github.ref_name }}.
Commit author: ${{ github.actor }}.
Commit message: ${{ github.event.commits[0].message }}.
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
build_and_push_to_docker_hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: flake8_and_tests
if: github.ref == 'refs/heads/main'
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push backend to Docker Hub
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/good_food:v.01
deploy:
runs-on: ubuntu-latest
needs: build_and_push_to_docker_hub
steps:
- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
echo ${{ secrets.SSH_HOST_USER_PASSWORD }} | sudo -S docker compose stop
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/good_food:v.01
touch .env
echo DB_ENGINE=${{ secrets.DB_ENGINE }} > .env
echo DB_NAME=${{ secrets.DB_NAME }} >> .env
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }} >> .env
echo EMAIL_HOST_APP_PASSWORD=${{ secrets.EMAIL_HOST_APP_PASSWORD }} >> .env
echo MODE=${{ secrets.MODE }} >> .env
echo DOCKER=${{ secrets.DOCKER }} >> .env
echo ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} >> .env
echo CSRF_TRUSTED_ORIGINS=${{ secrets.CSRF_TRUSTED_ORIGINS }} >> .env
echo STRIPE_PUBLISHABLE_KEY=${{ secrets.STRIPE_PUBLISHABLE_KEY }} >> .env
echo STRIPE_SECRET_KEY=${{ secrets.STRIPE_SECRET_KEY }} >> .env
echo STRIPE_WEBHOOK_SECRET=${{ secrets.STRIPE_WEBHOOK_SECRET }} >> .env
echo VITE_API_URL=${{ secrets.VITE_API_URL }} >> .env
echo VITE_BASE_URL=${{ secrets.VITE_BASE_URL }} >> .env
sudo docker compose up -d
sudo docker image prune -f
sudo docker compose exec -T web python manage.py collectstatic --no-input
echo ${{ secrets.SSH_HOST_USER_PASSWORD }} | sudo -S docker compose exec -T web python manage.py migrate
send_message:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: send message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.workflow }} completed successfully!
Repository: ${{ github.repository }}.
Branch name: ${{ github.ref_name }}.
Commit author: ${{ github.actor }}.
Commit message: ${{ github.event.commits[0].message }}.
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}