Skip to content

Add more unittests as necessary. #66

Add more unittests as necessary.

Add more unittests as necessary. #66

Workflow file for this run

name: Main Foodgram workflow
on:
push:
branches:
- main
jobs:
# frontend_tests:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
# - name: Set up nodeJS
# uses: actions/setup-node@v4
# with:
# node-version: 16
# - name: Install dependencies
# run: |
# cd frontend/
# npm ci
# - name: Test frontend
# run: |
# cd frontend/
# npm run test
backend_tests:
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:14.11
env:
POSTGRES_USER: django_user
POSTGRES_PASSWORD: django_password
POSTGRES_DB: django_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Check out repo code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8==7.0.0
pip install -r ./backend/requirements.txt
- name: Test with flake8 and other django tests
env:
POSTGRES_USER: django_user
POSTGRES_PASSWORD: django_password
POSTGRES_DB: django_db
# The DB server been started under Docker, with its port piped to
# the host, => we're connecting to 127.0.0.1:5432
DB_HOST: 127.0.0.1
DB_PORT: 5432
run: |
python -m flake8 backend/
cd backend/
pytest
build_and_push_backend_to_docker_hub:
name: Build & push FG backend Docker img to DockerHub
runs-on: ubuntu-22.04
# needs: [backend_tests, frontend_tests]
needs: backend_tests
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v5
with:
context: ./backend/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/foodgram_backend:latest
build_and_push_frontend_to_docker_hub:
name: Build & push FG frontend Docker img to DockerHub
runs-on: ubuntu-22.04
# needs: frontend_tests
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v5
with:
context: ./frontend/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/foodgram_frontend:latest
deploy:
runs-on: ubuntu-22.04
needs:
- build_and_push_backend_to_docker_hub
- build_and_push_frontend_to_docker_hub
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Copy docker-compose.production.yaml via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: "./infra/docker-compose.production.yaml"
target: "foodgram"
- name: Copy nginx.conf via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: "./infra/nginx.conf"
target: "foodgram"
- name: Copy doc folder via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: "./docs"
target: "foodgram"
- name: Execute remote ssh commands to deploy(1)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
cd foodgram
cp infra/docker-compose.production.yaml .
cp infra/nginx.conf .
docker compose -f docker-compose.production.yaml --progress=quiet pull
docker compose -f docker-compose.production.yaml --progress=quiet down -v
docker compose -f docker-compose.production.yaml --progress=quiet up -d
- name: Execute remote ssh commands to deploy(2)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
cd foodgram
docker compose -f docker-compose.production.yaml exec backend python manage.py migrate
docker compose -f docker-compose.production.yaml exec backend python manage.py collectstatic
docker compose -f docker-compose.production.yaml exec backend python manage.py loaddata db.json
docker compose -f docker-compose.production.yaml exec backend python manage.py import_csv eng
rm -r infra
rm nginx.conf
send_telegram:
runs-on: ubuntu-22.04
needs: deploy
steps:
- name: Send a telegram to mark the end of the deployment
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: Foodgram been refreshed in builds & deployed OK to WebSpace.