Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split compose & caddy files #395

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SERVER_DOMAIN=orbitar.local
API_DOMAIN=api.orbitar.local
REDIS_PASSWORD=orbitar

TLS_CERT_FILE=orbitar.crt
TLS_KEY_FILE=orbitar.key

VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_CONTACT=
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backup-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
echo $MYSQL_ROOT_PASSWORD | docker compose -f /orbitar/docker-compose.ssl.local.yml \
echo $MYSQL_ROOT_PASSWORD | docker compose -f /orbitar/docker-compose.yml -f docker-compose.deploy.yml \
exec -T mysql mysqldump --default-character-set=utf8mb4 --single-transaction --add-drop-database \
--databases orbitar_db activity_db -u root -p > ${{ env.backupFileName }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backup-media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
environment: StagingRO
runs-on: [self-hosted, stage]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: media_backup_src
- name: Run backup
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/build-caddy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Validate Caddyfile
on:
push:
branches:
- dev
- main
pull_request:
paths:
- .github/workflows/build-caddy.yml
- caddy/**/*
workflow_dispatch:

jobs:
validate-caddyfile:
runs-on: ubuntu-latest
container: caddy
env:
SERVER_DOMAIN: orbitar.test
BACKEND_DOMAIN: orbitar.backend
TLS_CERT_PATH: '{}'
TLS_KEY_PATH:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate Caddyfile
env:
SERVER_HOST: http://orbitar.test
API_HOST: http://api.orbitar.test
run: caddy validate --config caddy/Caddyfile
- name: Switch to deploy-frontend
run: |
rm caddy/dev.frontend.Caddyfile
mv caddy/deploy-frontend.Caddyfile caddy/deploy.frontend.Caddyfile
- name: Validate Caddyfile with deploy-frontend
env:
SERVER_HOST: https://orbitar.test
API_HOST: https://api.orbitar.test
run: caddy validate --config caddy/Caddyfile

42 changes: 20 additions & 22 deletions .github/workflows/build-docker-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-docker
name: Build Docker
on:
push:
branches:
Expand All @@ -7,40 +7,38 @@ on:
pull_request:
paths:
- .github/workflows/build-docker-dev.yml
- docker-compose.dev.yml
- docker-compose.local.yml
- docker-compose.ssl.dev.yml
- docker-compose.ssl.local.yml
- docker-compose.yml
- docker-compose.override.yml
- docker-compose.dev.ssl.yml
- docker-compose.deploy.yml
- docker-compose.deploy.nonssl.yml
- docker-compose.deploy.ssl.yml
workflow_dispatch:

jobs:
build-docker:
runs-on: ubuntu-latest
strategy:
matrix:
dc-file: [docker-compose.ssl.local.yml, docker-compose.local.yml]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build backend & frontend
run: docker compose -f ${{ matrix.dc-file }} build --no-cache backend frontend feed
- name: Build backend, frontend & feed
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml build --no-cache backend frontend feed

validate-docker-compose:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Validate docker-compose.dev.yml
run: docker compose -f docker-compose.dev.yml config
uses: actions/checkout@v4

- name: Validate docker-compose.ssl.dev.yml
run: docker compose -f docker-compose.ssl.dev.yml config
- name: Validate docker-compose
run: docker compose config

- name: Validate docker-compose.local.yml
run: docker compose -f docker-compose.local.yml config
- name: Validate docker-compose.dev.ssl.yml
run: docker compose -f docker-compose.yml -f docker-compose.dev.ssl.yml config

- name: Validate docker-compose.ssl.local.yml
run: docker compose -f docker-compose.ssl.local.yml config
- name: Validate docker-compose.deploy.yml with SSL
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.ssl.yml config

- name: Validate docker-compose.deploy.yml with NoSSL
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.nonssl.yml config
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
matrix:
module: [backend, frontend]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18"
- name: Cache dependencies
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/deploy-universal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
environment: ${{ github.event.inputs.environment == 'stage' && 'Staging' || 'Production' }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Verify environment
run: |
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
env:
# replace None with an empty string
BUILD_FLAG: ${{ github.event.inputs.build-flag != 'None' && github.event.inputs.build-flag || '' }}
run: docker compose -f docker-compose.ssl.local.yml build $BUILD_FLAG
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml build $BUILD_FLAG

- name: Download DB dump
id: get-db
Expand All @@ -136,18 +136,18 @@ jobs:
- name: Delete volumes
if: github.event.inputs.delete-volumes == 'true'
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml down -v
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.ssl.yml down -v

- name: Restore DB
if: github.event.inputs.restore-db == 'true'
working-directory: /orbitar
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
docker compose -f docker-compose.ssl.local.yml stop backend
docker compose -f docker-compose.ssl.local.yml up -d mysql --wait
docker compose -f docker-compose.yml -f docker-compose.deploy.yml stop backend
docker compose -f docker-compose.yml -f docker-compose.deploy.yml up -d mysql --wait

docker compose -f docker-compose.ssl.local.yml exec -T mysql /usr/bin/mysql \
docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -T mysql /usr/bin/mysql \
-u root --password=$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 \
< ${{ steps.get-db.outputs.db-dump-file }}

Expand All @@ -158,10 +158,10 @@ jobs:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
set -ex
docker compose -f docker-compose.ssl.local.yml stop backend
docker compose -f docker-compose.ssl.local.yml up -d mysql --wait
docker compose -f docker-compose.yml -f docker-compose.deploy.yml stop backend
docker compose -f docker-compose.yml -f docker-compose.deploy.yml up -d mysql --wait

docker compose -f docker-compose.ssl.local.yml exec -T mysql /usr/bin/mysql \
docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -T mysql /usr/bin/mysql \
-u root --password=$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 orbitar_db \
< ${{ github.event.inputs.manual-sql }}

Expand All @@ -171,23 +171,23 @@ jobs:
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
docker compose -f docker-compose.ssl.local.yml up -d mysql --wait
docker compose -f docker-compose.yml -f docker-compose.deploy.yml up -d mysql --wait
echo "update orbitar_db.content_source set indexed = 0;" | \
docker compose -f docker-compose.ssl.local.yml exec -T mysql /usr/bin/mysql -u root --password=$MYSQL_ROOT_PASSWORD
docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -T mysql /usr/bin/mysql -u root --password=$MYSQL_ROOT_PASSWORD

- name: Flush redis
if: github.event.inputs.flush-redis == 'true'
working-directory: /orbitar
env:
REDIS_PASSWORD: orbitar
run: |
docker compose -f docker-compose.ssl.local.yml stop backend
docker compose -f docker-compose.ssl.local.yml up -d redis --wait
docker compose -f docker-compose.ssl.local.yml exec -e REDISCLI_AUTH=$REDIS_PASSWORD redis redis-cli FLUSHALL
docker compose -f docker-compose.yml -f docker-compose.deploy.yml stop backend
docker compose -f docker-compose.yml -f docker-compose.deploy.yml up -d redis --wait
docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -e REDISCLI_AUTH=$REDIS_PASSWORD redis redis-cli FLUSHALL

- name: Deploy
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml up -d
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.ssl.yml up -d

- name: Purge Cloudflare Cache
env:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/restore-sanitized-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download DB backup
id: get-db
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Load DB
run: cat ${{ steps.get-db.outputs.db-dump-file }} | /usr/bin/mysql -h 127.0.0.1 -u root -p$MYSQL_ROOT_PASSWORD

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Remove PII
run: |
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
environment: Staging
runs-on: [self-hosted, stage]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download DB backup
uses: ./.github/actions/get-db
Expand All @@ -82,23 +82,23 @@ jobs:

- name: Stop backend
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml stop backend
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml stop backend

- name: Restore backup
working-directory: /orbitar
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
run: |
docker compose -f docker-compose.ssl.local.yml exec -T mysql /usr/bin/mysql \
docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -T mysql /usr/bin/mysql \
-u root --password=$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 \
< ${{ steps.get-db.outputs.db-dump-file }}

- name: Flush Redis cache
working-directory: /orbitar
env:
REDIS_PASSWORD: orbitar
run: docker compose -f docker-compose.ssl.local.yml exec -e REDISCLI_AUTH=$REDIS_PASSWORD redis redis-cli FLUSHALL
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml exec -e REDISCLI_AUTH=$REDIS_PASSWORD redis redis-cli FLUSHALL

- name: Restart backend
working-directory: /orbitar
run: docker compose -f docker-compose.ssl.local.yml start backend
run: docker compose -f docker-compose.yml -f docker-compose.deploy.yml start backend
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.idea
.DS_Store
/tmp
/docker-compose.yml
/backup
/.env
node_modules
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Orbitar
# Orbitar

Прототип коллективного блога.

Expand All @@ -7,33 +7,34 @@
**ДИСКЛЕЙМЕР**: целью было быстро сделать прототип. Писалось всё быстро и на коленке, код дурно пахнет и на 100% подлежит переписыванию.

## Разработка

### Настройка

Файл `.env.sample` необходимо скопировать в `.env` и заполнить или скорректировать необходимые значения.

В hosts добавить:
```

```hosts
127.0.0.1 orbitar.local api.orbitar.local
```
Можно дополнить списком подсайтов по вкусу (опционально)
```
127.0.0.1 idiod.orbitar.local
```

### Особенности

* [Локальный запуск в дебаг режиме](docs/local-development.md)
* [Организация .env переменных](docs/environment.md)


### Запуск production-сборки полностью в контейнере

Пересборка фронта и бэка (если необходимо):

```sh
docker compose -p orbitar -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.nonssl.yml build --no-cache frontend backend
```
docker compose -p orbitar -f docker-compose.local.yml build --no-cache frontend backend
```

Запуск:
```
docker compose -p orbitar -f docker-compose.local.yml up

```sh
docker compose -p orbitar -f docker-compose.yml -f docker-compose.deploy.yml -f docker-compose.deploy.nonssl.yml up
```

## Утилиты
Expand All @@ -46,15 +47,20 @@ docker compose -p orbitar -f docker-compose.local.yml up

(в папке `backend`, перед первым запуском выполнить `npm install`)

npm run generate-dummy-content -- --help

```sh
npm run generate-dummy-content -- --help
```

Например:

npm run generate-dummy-content -- -u 10 -s 8 -p 20 -c 100

Для генерации осмысленных текстов используйте параметр `-f 1`, например:

npm run generate-dummy-content -- -u 10 -s 8 -p 20 -c 100 -f 1
```sh
npm run generate-dummy-content -- -u 10 -s 8 -p 20 -c 100
```

Для генерации осмысленных текстов используйте параметр `-f 1`, например:

```sh
npm run generate-dummy-content -- -u 10 -s 8 -p 20 -c 100 -f 1
```

Для генерации осмысленных текстов используется API https://fish-text.ru/, соответственно, нужно интернет-соединение.
Loading
Loading