Skip to content

Commit

Permalink
Merge pull request #101 from Pet-projects-CodePET/dev_docker
Browse files Browse the repository at this point in the history
Dev docker
  • Loading branch information
VladislavCR authored Mar 9, 2024
2 parents 42ad86a + 5ef7456 commit 061eb2a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 46 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
push: true
Expand All @@ -30,16 +30,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./infra/nginx/
push: true
Expand All @@ -52,7 +52,7 @@ jobs:
- build_and_push_to_docker_hub_nginx
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Create project directory and .env-file
uses: appleboy/ssh-action@master
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/qa_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ jobs:
DOCKERHUB_USERNAME_FRONT=${{ secrets.DOCKERHUB_USERNAME_FRONT }}
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }}
EMAIL_HOST=${{ secrets.EMAIL_HOST }}
EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }}
NEXT_PUBLIC_CAPTCHA_SITE_KEY=${{ secrets.NEXT_PUBLIC_CAPTCHA_SITE_KEY }}
NEXT_SHARP_PATH=${{ secrets.NEXT_SHARP_PATH }}
_EOF_
- name: Copy docker-compose-prod.yaml via ssh
uses: appleboy/scp-action@master
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ RUN apt-get update && apt-get install -y vim

RUN pip install -r requirements.txt --no-cache-dir

COPY . .

WORKDIR /backend/src/backend
COPY /src/backend/. .

CMD gunicorn --bind 0.0.0.0:8000 config.wsgi
17 changes: 9 additions & 8 deletions .env.example → infra/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ ALLOWED_HOSTS=localhost,127.0.0.1,
USE_SQLITE=True

# Для PostgeSQL
# DB_ENGINE=django.db.backends.postgresql
# DB_NAME=
# POSTGRES_USER=
# POSTGRES_PASSWORD=
# DB_HOST=
# DB_PORT=
DB_ENGINE=django.db.backends.postgresql
DB_NAME=
POSTGRES_USER=
POSTGRES_PASSWORD=
DB_HOST=
DB_PORT=

# Переменные для работы с docker.
DOCKERHUB_USERNAME=username
PROJECT_NAME=project_name
DOCKERHUB_USERNAME_FRONT=
DOCKERHUB_USERNAME=
PROJECT_NAME=
14 changes: 4 additions & 10 deletions infra/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
services:

db:
image: postgres:latest
image: postgres:16.2-alpine
restart: always
ports:
- "5432:5432"
env_file: .env
volumes:
- db_value:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=db
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin


backend:
build: ../.
env_file: .env
ports:
- "8000:8000"
volumes:
- static_volume:/backend_static/
- ./.env:/app
depends_on:
- db

nginx:
build: /nginx/.
build: ./nginx/.
ports:
- "80:80"
- "443:443"
Expand Down
25 changes: 16 additions & 9 deletions infra/docker-compose-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,43 @@ volumes:

services:
db:
image: postgres:latest
restart: always
image: postgres:16.2-alpine
restart: unless-stopped
env_file: .env
ports:
- "5432:5432"
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_PASSWORD}"
]
interval: 5s
timeout: 3s
retries: 5
volumes:
- pg_data:/var/lib/postgresql/data

backend:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_backend:latest
restart: always
restart: unless-stopped
env_file: .env
ports:
- "8000:8000"
volumes:
- static_volume:/backend_static/
- media_value:/backend_media/
depends_on:
- db
db:
condition: service_healthy

frontend:
image: ${DOCKERHUB_USERNAME_FRONT}/${PROJECT_NAME}_frontend:latest
command: cp -r out/. /frontend_static/
env_file: .env
ports:
- "3000:3000"
volumes:
- static_volume:/frontend_static
depends_on:
- db
db:
condition: service_healthy

nginx:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_nginx:latest
Expand Down
2 changes: 1 addition & 1 deletion infra/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM nginx:1.25
FROM nginx:1.25.4-alpine-slim
COPY nginx.conf /etc/nginx/templates/default.conf.template
11 changes: 8 additions & 3 deletions infra/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ server {
listen [::]:80;
server_name 89.23.117.80 devcodepet.tw1.ru 89.23.117.168 testcodepet.tw1.ru localhost;

root /staticfiles;

location /api/v1/ {
proxy_set_header Host $http_host;
proxy_pass http://backend:8000/api/v1/;
Expand All @@ -12,8 +14,11 @@ server {
proxy_pass http://backend:8000/admin/;
}
location / {
alias /staticfiles/;
index index.html;
try_files $uri $uri/ /index.html;
try_files $uri $uri.html $uri/ =404;
}

error_page 404 /404.html;
location = /404.html {
internal;
}
}
6 changes: 3 additions & 3 deletions src/backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
DATABASES = {
"default": {
"ENGINE": getenv("DB_ENGINE", default="django.db.backends.postgresql"),
"NAME": getenv("POSTGRES_DB", default="db_test"),
"NAME": getenv("DB_NAME", default="db_test"),
"USER": getenv("POSTGRES_USER", default="admin_test"),
"PASSWORD": getenv("POSTGRES_PASSWORD", default="postgre_admin"),
"HOST": getenv("POSTGRES_HOST", default="db_test"),
"PORT": getenv("POSTGRES_PORT", default=5432),
"HOST": getenv("DB_HOST", default="db_test"),
"PORT": getenv("DB_PORT", default=5432),
}
}

Expand Down

0 comments on commit 061eb2a

Please sign in to comment.