-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from healthy-food-and-dietary-products/feature…
…/ci-cd Feature/ci cd
- Loading branch information
Showing
19 changed files
with
280 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/ | ||
db.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: good_food_develop workflow | ||
|
||
on: | ||
push: | ||
branches: [main, develop] | ||
pull_request: | ||
|
||
jobs: | ||
|
||
flake8_and_tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
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: | | ||
# pytest | ||
|
||
build_and_push_to_docker_hub: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
needs: flake8_and_tests | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
- 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.PASSPHRASE }} | ||
# script: | | ||
# echo ${{ secrets.SSH_USER_PASSWORD }} | sudo -S docker image prune -f | ||
# sudo docker-compose stop | ||
# sudo docker-compose rm web | ||
# 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=${{ secrets.EMAIL }} >> .env | ||
# echo EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }} >> .env | ||
# sudo docker-compose up -d | ||
# sudo docker cp .env ${{ secrets.SSH_USER }}_web_1:/app/good_food | ||
# sudo docker-compose exec -T web python manage.py collectstatic --no-input | ||
# echo ${{ secrets.SSH_USER_PASSWORD }} | sudo -S docker-compose exec -T web python manage.py migrate | ||
|
||
send_message: | ||
runs-on: ubuntu-latest | ||
needs: build_and_push_to_docker_hub | ||
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
FROM python:3.10-slim | ||
LABEL author='Healthy Food' version=1 | ||
LABEL author='Good Food' version=1 | ||
RUN pip install "poetry==1.6.1" | ||
WORKDIR /app | ||
COPY poetry.lock pyproject.toml backend/ /app/ | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --without dev --no-interaction --no-root | ||
CMD ["gunicorn", "healthy_food.wsgi:application", "--bind", "0:8000"] | ||
CMD ["gunicorn", "good_food.wsgi:application", "--bind", "0:8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# healthy-food | ||
# good-food | ||
|
||
![healthy_food workflow](https://github.com/healthy-food-and-dietary-products/backend/actions/workflows/healthy_food_workflow.yaml/badge.svg) | ||
![good_food_develop workflow](https://github.com/healthy-food-and-dietary-products/backend/actions/workflows/good_food_develop_workflow.yaml/badge.svg) | ||
|
||
# TODO: добавить пример заполнения файла .env и указать, в каких папках он должен лежать |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
""" | ||
Django settings for healthy_food project. | ||
Generated by 'django-admin startproject' using Django 4.2.6. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/4.2/ref/settings/ | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = os.getenv("SECRET_KEY", default="key") | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [ | ||
"localhost", | ||
"127.0.0.1", | ||
"[::1]", | ||
"web", | ||
] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
"django.contrib.admin", | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
"rest_framework", | ||
"products.apps.ProductsConfig", | ||
"users.apps.UsersConfig", | ||
"api.apps.ApiConfig", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
"django.middleware.security.SecurityMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.middleware.common.CommonMiddleware", | ||
"django.middleware.csrf.CsrfViewMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.messages.middleware.MessageMiddleware", | ||
"django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
] | ||
|
||
ROOT_URLCONF = "good_food.urls" | ||
|
||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
"DIRS": [], | ||
"APP_DIRS": True, | ||
"OPTIONS": { | ||
"context_processors": [ | ||
"django.template.context_processors.debug", | ||
"django.template.context_processors.request", | ||
"django.contrib.auth.context_processors.auth", | ||
"django.contrib.messages.context_processors.messages", | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = "good_food.wsgi.application" | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
"default": { | ||
# 'ENGINE': 'django.db.backends.sqlite3', | ||
# 'NAME': BASE_DIR / 'db.sqlite3', | ||
"ENGINE": os.getenv("DB_ENGINE", default="django.db.backends.postgresql"), | ||
"NAME": os.getenv("DB_NAME", default="postgres"), | ||
"USER": os.getenv("POSTGRES_USER", default="postgres"), | ||
"PASSWORD": os.getenv("POSTGRES_PASSWORD", default="postgres"), | ||
"HOST": os.getenv("DB_HOST", default="db"), | ||
"PORT": os.getenv("DB_PORT", default="5432"), | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/4.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = "en-us" | ||
|
||
TIME_ZONE = "UTC" | ||
|
||
USE_I18N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/4.2/howto/static-files/ | ||
|
||
STATIC_URL = "static/" | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.