Skip to content

Commit

Permalink
Merge pull request #1 from EatPlace/prod
Browse files Browse the repository at this point in the history
Sync dev with Prod
  • Loading branch information
TimofeyTst authored Oct 8, 2023
2 parents fb7afa8 + 09b2b45 commit f673498
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 32 deletions.
52 changes: 36 additions & 16 deletions .github/workflows/deploy-runners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,46 @@ on:

jobs:
deploy:
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Echo info
run: |
echo "Started deploying..."
- name: checkout repo
uses: actions/checkout@v4

# - name: Make envfile
# uses: SpicyPizza/[email protected]
# with:
# envkey_MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
# envkey_MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }}
# envkey_RABBIT_PASSWORD: ${{ secrets.RABBIT_PASSWORD }}
# envkey_BOT_NAME: ${{ secrets.BOT_NAME }}
# envkey_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
# file_name: .env
# directory: "./"
# fail_on_empty: false
# sort_keys: false
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_JWT_SECRET: ${{ secrets.JWT_SECRET }}
envkey_GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}
envkey_GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}

envkey_AUTH_TOKEN_EXP: ${{ secrets.AUTH_TOKEN_EXP }}
envkey_RESET_PASSWORD_TOKEN_EXP: ${{ secrets.RESET_PASSWORD_TOKEN_EXP }}
envkey_VERIFY_TOKEN_EXP: ${{ secrets.VERIFY_TOKEN_EXP }}

envkey_POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
envkey_POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
envkey_POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
envkey_POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
envkey_POSTGRES_DB: ${{ secrets.POSTGRES_DB }}

envkey_REDIS_HOST: ${{ secrets.REDIS_HOST }}
envkey_REDIS_PORT: ${{ secrets.REDIS_PORT }}
envkey_REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}

envkey_SITE_DOMAIN: ${{ secrets.SITE_DOMAIN }}
envkey_SECURE_COOKIES: ${{ secrets.SECURE_COOKIES }}

envkey_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

envkey_CORS_HEADERS: ${{ secrets.CORS_HEADERS }}
envkey_CORS_ORIGINS: ${{ secrets.CORS_ORIGINS }}

envkey_ENVIRONMENT: PRODUCTION

file_name: .prod.env
directory: "./"
fail_on_empty: false
sort_keys: false

- name: pull images
run: docker-compose -f docker-compose.prod.yml pull
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
# Deploy
Создайте файл .env по шаблону .env.example

## Development
- Подразумевает, что все нужные репозитории отклонированы в одну папку
- Требуется создать файл `.env` по шаблону `.env.example`
- Поддерживает изменения на лету, максимально удобен для разработки
```bash
docker-compose up -d
docker compose exec rest_api migrate
```

## Development pulling
- Нужен только репозиторий deploy
- Сборка dev образов с Docker Hub
```bash
docker-compose -f docker-compose.dev.yml up -d
docker compose exec rest_api migrate
```

## Production pulling
- Нужен только репозиторий deploy
- Сборка prod образов с Docker Hub

```bash
docker-compose -f docker-compose.prod.yml up -d
docker compose exec rest_api migrate
```

## Release
В этом режиме собирается готовый образ для production
- Подразумевает, что все нужные репозитории отклонированы в одну папку
- Требуется создать файл `.prod.env` по шаблону `.env.example`
- В этом режиме собирается готовый compose для production
```bash
docker-compose -f docker-compose.release.yml up -d --build
docker compose exec rest_api migrate
Expand Down
78 changes: 78 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: '3.8'

services:
db:
container_name: db
hostname: db
image: library/postgres:14.1

environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- eat_place_pg_data:/var/lib/postgresql/data
ports:
- "5432:5432"

test_db:
container_name: test_db
hostname: test_db
image: library/postgres:14.1

environment:
- POSTGRES_USER=rest
- POSTGRES_PASSWORD=rest
- POSTGRES_DB=rest
volumes:
- eat_place_test_pg_data:/var/lib/postgresql/data
ports:
- "5433:5432"

redis:
image: redis:6.2-alpine
hostname: redis
container_name: redis
env_file:
- .env
command:
- /bin/sh
- -c
- redis-server --requirepass "$${REDIS_PASSWORD:?REDIS_PASSWORD variable is not set}"
ports:
- 6379:6379


rest_api:
image: timofeytst/eat-place:rest_api_dev
ports:
- "8000:8000"
restart: always

env_file:
- .env
depends_on:
- db
- redis

web_ui:
image: timofeytst/eat-place:web_ui_dev
ports:
- "3000:3000"
restart: always
environment:
REACT_APP_DEV: dev
depends_on:
- rest_api

volumes:
eat_place_pg_data:
driver: "local"

eat_place_test_pg_data:
driver: "local"

networks:
default:
external: true
name: eat_place
45 changes: 31 additions & 14 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
version: '3.8'

services:

web-ui:
image: timofeytst/eat_place:web_ui_prod
ports:
- "3000:80"
restart: always
environment:
REACT_APP_DEV: prod

db:
container_name: db
hostname: db
image: library/postgres:14.1

environment:
- POSTGRES_USER=rest
- POSTGRES_PASSWORD=rest
- POSTGRES_DB=rest
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- eat_place_pg_data:/var/lib/postgresql/data
ports:
Expand All @@ -28,12 +19,38 @@ services:
image: redis:6.2-alpine
hostname: redis
container_name: redis
env_file:
- .prod.env
command:
- 'redis-server'
- '--requirepass myStrongPassword'
- /bin/sh
- -c
- redis-server --requirepass "$${REDIS_PASSWORD:?REDIS_PASSWORD variable is not set}"
ports:
- 6379:6379


rest_api:
image: timofeytst/eat-place:rest_api_prod
ports:
- "9000:9000"
restart: always

env_file:
- .prod.env
depends_on:
- db
- redis

web_ui:
image: timofeytst/eat-place:web_ui_prod
ports:
- "3000:80"
restart: always
environment:
REACT_APP_DEV: prod
depends_on:
- rest_api

volumes:
eat_place_pg_data:
driver: "local"
Expand Down

0 comments on commit f673498

Please sign in to comment.