From 2ba2c4f82a271ec3629fc17b1ce7fbdb1906051e Mon Sep 17 00:00:00 2001 From: Alex Proskuriakov Date: Tue, 19 Mar 2024 14:33:23 +0300 Subject: [PATCH 1/2] Add frontend --- .github/workflows/main.yml | 19 ++++++++----------- docker/server.docker-compose.yml | 7 ++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb21e05..34c6498 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,5 @@ name: CI/CD -on: - push: - branches: ["develop"] - pull_request: - branches: ["develop"] - workflow_dispatch: +on: [push] jobs: @@ -37,18 +32,18 @@ jobs: - name: Check out the repo 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 Docker Hub - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: file: ./docker/dev.Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest + tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend:latest server_environment: runs-on: ubuntu-latest @@ -103,6 +98,8 @@ jobs: script: | cd ${{ secrets.PROJECT_NAME }} sudo docker-compose -f server.docker-compose.yml --env-file .env down - sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} + sudo docker rmi \ + ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_frontend \ + ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend sudo systemctl stop nginx sudo docker-compose -f server.docker-compose.yml --env-file .env up -d --quiet-pull diff --git a/docker/server.docker-compose.yml b/docker/server.docker-compose.yml index b6341cb..368b85a 100644 --- a/docker/server.docker-compose.yml +++ b/docker/server.docker-compose.yml @@ -12,7 +12,7 @@ services: - $DB_PORT:$DB_PORT backend: - image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}" + image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}_backend" # command: bash -c "alembic upgrade head && uvicorn app.main:app" command: bash -c "uvicorn app.main:app --host=0.0.0.0" restart: always @@ -23,5 +23,10 @@ services: env_file: - ./.env + frontend: + image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}_frontend" + ports: + - 3000:3000 + volumes: db_data: From 605fb2208288afb74aeba8774be0af44553a8003 Mon Sep 17 00:00:00 2001 From: Alex Proskuriakov Date: Wed, 20 Mar 2024 00:37:55 +0300 Subject: [PATCH 2/2] Add nginx --- .github/workflows/main.yml | 2 +- README.md | 19 +++++++++++++------ docker/docker-compose.yml | 24 ++++++++++++++++++++---- docker/nginx.conf | 19 +++++++++++++++++++ docker/server.docker-compose.yml | 21 ++++++++++++++++----- 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 docker/nginx.conf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34c6498..706a9a0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,7 +80,7 @@ jobs: host: ${{ secrets.HOST }} username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} - source: "docker/server.docker-compose.yml" + source: "docker/server.docker-compose.yml, docker/nginx.conf" target: ${{ secrets.PROJECT_NAME }} overwrite: true strip_components: 1 diff --git a/README.md b/README.md index 3e3a1e3..d70d60e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # hrspace-request-builder-backend [![CI/CD](https://github.com/hrspace-request-builder/hrspace-request-builder-backend/actions/workflows/main.yml/badge.svg)](https://github.com/hrspace-request-builder/hrspace-request-builder-backend/actions/workflows/main.yml) -Проект развернут на удаленном сервере: - - Swagger доступен по адресу http://185.221.162.231:8000/docs - - админ панель доступна по адресу http://185.221.162.231:8000/admin +Проект развернут на удаленном сервере по адресу http://185.221.162.231/hrspace: + - админ панель доступна по адресу http://185.221.162.231/admin + - Swagger доступен по адресу http://185.221.162.231/docs + - Redoc доступен по адресу http://185.221.162.231/redoc + +
## Установка приложения: @@ -35,11 +38,15 @@ nano .env ```bash docker compose -f docker/docker-compose.yml --env-file .env up -d --build ``` - Проект будет развернут в docker-контейнерах по адресу http://127.0.0.1:8000. + Проект будет развернут в docker-контейнерах по адресу http://localhost/hrspace Администрирование приложения может быть осуществлено: - - через Swagger доступный по адресу http://127.0.0.1:8000/docs - - через админ панель по адресу http://127.0.0.1:8000/admin + - через Swagger доступный по адресу http://localhost/docs + - через админ панель по адресу http://localhost/admin + + Техническая документация: + - Swagger доступен по адресу http://localhost/docs + - Redoc доступен по адресу http://localhost/redoc
2. Остановить docker и удалить контейнеры можно командой из корневой директории проекта: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 3d466ed..5dcc6af 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,8 +7,8 @@ services: - db_data:/var/lib/postgresql/data/ environment: - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - ports: - - $DB_PORT:$DB_PORT + expose: + - $DB_PORT healthcheck: test: ["CMD-SHELL", "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB"] interval: 10s @@ -28,10 +28,26 @@ services: depends_on: db: condition: service_healthy - ports: - - 8000:8000 + expose: + - 8000 env_file: - ../.env + frontend: + image: alexpro1972/hrspace_frontend + expose: + - 3000 + + nginx: + image: nginx:1.21.3-alpine + restart: always + depends_on: + - frontend + - backend + ports: + - "80:80" + volumes: + - ./nginx.conf:/etc/nginx/conf.d/default.conf + volumes: db_data: diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..4c23433 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 80; + server_name "$hostname"; + server_tokens off; + + location /hrspace { + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_pass http://frontend:3000; + } + + location / { + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_pass http://backend:8000; + } +} diff --git a/docker/server.docker-compose.yml b/docker/server.docker-compose.yml index 368b85a..f83c90a 100644 --- a/docker/server.docker-compose.yml +++ b/docker/server.docker-compose.yml @@ -8,8 +8,8 @@ services: - db_data:/var/lib/postgresql/data/ environment: - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - ports: - - $DB_PORT:$DB_PORT + expose: + - $DB_PORT backend: image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}_backend" @@ -18,15 +18,26 @@ services: restart: always depends_on: - db - ports: - - 8000:8000 + expose: + - 8000 env_file: - ./.env frontend: image: "${DOCKERHUB_USERNAME}/${PROJECT_NAME}_frontend" + expose: + - 3000 + + nginx: + image: nginx:1.21.3-alpine + restart: always + depends_on: + - frontend + - backend ports: - - 3000:3000 + - "80:80" + volumes: + - ./nginx.conf:/etc/nginx/conf.d/default.conf volumes: db_data: