diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 34d853a..93b097e 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -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 @@ -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 @@ -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: diff --git a/.github/workflows/qa_deploy.yaml b/.github/workflows/qa_deploy.yaml index 4a86c70..538a3c5 100644 --- a/.github/workflows/qa_deploy.yaml +++ b/.github/workflows/qa_deploy.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile index af07588..31928ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/.env.example b/infra/.env.example similarity index 67% rename from .env.example rename to infra/.env.example index c72ea28..83a9a78 100644 --- a/.env.example +++ b/infra/.env.example @@ -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= diff --git a/infra/docker-compose-dev.yaml b/infra/docker-compose-dev.yaml index 338e099..4d22fbb 100644 --- a/infra/docker-compose-dev.yaml +++ b/infra/docker-compose-dev.yaml @@ -1,22 +1,16 @@ 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 @@ -24,7 +18,7 @@ services: - db nginx: - build: /nginx/. + build: ./nginx/. ports: - "80:80" - "443:443" diff --git a/infra/docker-compose-prod.yaml b/infra/docker-compose-prod.yaml index 055fc6a..5758814 100644 --- a/infra/docker-compose-prod.yaml +++ b/infra/docker-compose-prod.yaml @@ -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 diff --git a/infra/nginx/Dockerfile b/infra/nginx/Dockerfile index f525310..1a461de 100644 --- a/infra/nginx/Dockerfile +++ b/infra/nginx/Dockerfile @@ -1,2 +1,2 @@ -FROM nginx:1.25 +FROM nginx:1.25.4-alpine-slim COPY nginx.conf /etc/nginx/templates/default.conf.template diff --git a/infra/nginx/nginx.conf b/infra/nginx/nginx.conf index e7e42ae..3e6f234 100644 --- a/infra/nginx/nginx.conf +++ b/infra/nginx/nginx.conf @@ -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/; @@ -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; } } diff --git a/src/backend/config/settings/base.py b/src/backend/config/settings/base.py index 190385c..e1343a7 100644 --- a/src/backend/config/settings/base.py +++ b/src/backend/config/settings/base.py @@ -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), } }