Skip to content

Commit

Permalink
Merge pull request #4 from Roman-Zhirovskis/newname
Browse files Browse the repository at this point in the history
creat diffrents ways of docker/pre-commit/actions
  • Loading branch information
Roman-Zhirovskis authored Nov 15, 2023
2 parents 7eda40f + 64e478f commit 51340b1
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ repos:
additional_dependencies:
- flake8-bugbear

- repo: local
hooks:
- id: tests
name: Run tests
entry: "bash run_tests.sh"
language: system
# - repo: local
# hooks:
# - id: tests
# name: Run tests
# entry: "bash run_tests.sh"
# language: system


# - repo: https://github.com/pycqa/isort
Expand Down Expand Up @@ -81,4 +81,4 @@ repos:
# # S101 Use of assert detected
# ]
# additional_dependencies:
# - flake8-bugbear
# - flake8-bugbear
38 changes: 38 additions & 0 deletions Dockerfiles/Dockerfiles_django.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM python:3.11-slim-buster

ENV \
# python:
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
# pip:
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

# System deps:
RUN apt-get update && \
apt-get install --no-install-recommends -y \
build-essential \
gettext \
libpq-dev \
wget && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Copy only requirements, to cache them in docker layer
WORKDIR /app
COPY ./requirements.txt /app/

# Project initialization:
RUN pip install -r requirements.txt

# Creating folders, and files for a project:
COPY . /app

# Setting up proper permissions:

RUN mkdir -p /app/media /app/static

WORKDIR backend

CMD python manage.py collectstatic --noinput && python manage.py migrate && \
gunicorn -b 0.0.0.0:8000 --log-level info --access-logfile - config.wsgi:application
22 changes: 22 additions & 0 deletions Dockerfiles/Dockerfiles_fastapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.11 as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* /tmp/

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM python:3.11

WORKDIR /app

COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY . /app

CMD ["uvicorn", "src.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000", "--log-level", "debug" , "--use-colors"]

71 changes: 71 additions & 0 deletions docker-compose_configs/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: "3.9"

#for fastapi
services:
web:
build: .
restart: always
container_name: app-back
env_file:
- .env
depends_on:
db:
condition: service_healthy

#postgreSql
db:
container_name: db
image: postgres:15.3-alpine
env_file:
- .env
healthcheck:
test: pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}
interval: 10s
timeout: 5s
retries: 5
volumes:
- pg_data:/var/lib/postgresql/data

version: '3'

#mongoDB
services:
mongodb:
image: mongo
container_name: my-mongodb
restart: always
volumes:
- ./data:/data/db
ports:
- 27017:27017
#rabbitmq
rabbitmq:
image: rabbitmq:3.11-management
container_name: users-service-rabbitmq
expose:
- 5672
- 15672
env_file:
- .env.prod
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
timeout: 30s
retries: 3

#redis
redis:
restart: always
command: /bin/sh -c "redis-server --requirepass $$REDIS_LOCAL_PASSWORD"
image: redis:7.0.5-alpine
env_file:
- .env.prod
expose:
- 6379
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 1s
timeout: 3s
retries: 30


50 changes: 50 additions & 0 deletions gidHub_action_with_docker/docker-compose_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.9"

services:
web_users_tests:
build: ./
env_file:
- .env.tests
restart: "no"
command: >
sh -c "python manage.py test"
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy
db:
extends:
file: docker-compose.yml
service: db
container_name: users-service-db-tests
env_file:
- .env.tests
rabbitmq:
image: rabbitmq:3.11-management
container_name: users-service-rabbitmq
expose:
- 5672
- 15672
env_file:
- .env.tests
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
timeout: 30s
retries: 3
redis:
restart: always
command: /bin/sh -c "redis-server --requirepass $$REDIS_LOCAL_PASSWORD"
image: redis:7.0.5-alpine
expose:
- 6379
env_file:
- .env.tests
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 1s
timeout: 3s
retries: 30
32 changes: 32 additions & 0 deletions gidHub_action_with_docker/github_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Users CI/CD

on:
push:
branches: [ "users" ]
pull_request:
branches: ["users" ]
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository code
uses: actions/checkout@v3

- name: Install python
uses: actions/setup-python@v3

- run: pip install pre-commit
- run: pre-commit --version

- run: |
cd backend/users && pre-commit install
- run: |
cd backend/users && pre-commit run --all-files
- name: Run test in docker-compose
run: |
cd backend/users/ && docker-compose -f docker-compose.tests.yml \
up \
--build \
--abort-on-container-exit \
--exit-code-from web_users_tests
41 changes: 41 additions & 0 deletions gidHub_action_with_docker/pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
files: 'backend/users*'
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.74.1
hooks:
- id: terraform_fmt
args: [--args=-write=true]

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--skip-string-normalization, --line-length=100, backend/users]
language_version: python3

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black]

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/pycqa/flake8.git
rev: 6.0.0
hooks:
- id: flake8
args: [--config, backend/users/.flake8]
additional_dependencies: [
"flake8-bugbear",
"flake8-builtins",
"pep8-naming",
"flake8-commas",
"flake8-quotes",
"flake8-todo",
"flake8-django",
"flake8-cognitive-complexity"
]

0 comments on commit 51340b1

Please sign in to comment.