generated from yandex-praktikum/client-server-template-with-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
253 changed files
with
16,617 additions
and
1,798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
CLIENT_PORT=3000 | ||
SERVER_PORT=3001 | ||
SERVER_PORT=5000 | ||
POSTGRES_USER=postgres | ||
POSTGRES_PASSWORD=postgres | ||
POSTGRES_DB=postgres | ||
POSTGRES_PORT=5432 | ||
PGADMIN_EMAIL=[email protected] | ||
PGADMIN_PASSWORD=secret | ||
API_ENDPOINT=https://ya-praktikum.tech/api/v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Push To Yandex Cloud CR | ||
|
||
on: | ||
push: | ||
branches: | ||
- deploy | ||
- deploy-test | ||
- task-51-deploy-to-cloud | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Yandex Cloud CR "Login" Action for GitHub Actions | ||
uses: yc-actions/[email protected] | ||
with: | ||
yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }} | ||
|
||
- name: Build, tag, and push image to Yandex Cloud Container Registry | ||
env: | ||
CR_REGISTRY: ${{ secrets.CR_REGISTRY }} | ||
CR_REPOSITORY: bumble | ||
IMAGE_TAG: ${{ github.sha }} | ||
CLIENT_PORT: 3000 | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: postgres | ||
POSTGRES_PORT: 5432 | ||
SERVER_NAME: wordrunners-bumble-20.ya-praktikum.tech | ||
SERVER_PORT: 5000 | ||
run: | | ||
docker compose build | ||
docker tag practicum-client:latest cr.yandex/$CR_REGISTRY/practicum-client:latest | ||
docker push cr.yandex/$CR_REGISTRY/practicum-client:latest | ||
docker tag practicum-server:latest cr.yandex/$CR_REGISTRY/practicum-server:latest | ||
docker push cr.yandex/$CR_REGISTRY/practicum-server:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
ARG NODE_VERSION=16 | ||
ARG SERVER_PORT=5000 | ||
|
||
FROM node:$NODE_VERSION-buster as base | ||
|
||
WORKDIR /app | ||
|
||
FROM base as builder | ||
|
||
COPY package.json yarn.lock | ||
RUN yarn install --frozen-lockfile | ||
|
||
COPY . . | ||
|
||
RUN yarn bootstrap | ||
RUN rm -rf /app/packages/server/dist/ && yarn build --scope=server | ||
|
||
|
||
FROM node:$NODE_VERSION-buster-slim as production | ||
WORKDIR /app | ||
|
||
COPY --from=builder /app/packages/client/ /client/ | ||
COPY --from=builder /app/packages/server/dist/ /app/ | ||
COPY --from=builder /app/packages/server/package.json /app/package.json | ||
COPY --from=builder /app/packages/server/utils/wait-for.sh /app/utils/wait-for.sh | ||
|
||
RUN apt-get -q update && apt-get -qy install netcat | ||
RUN chmod +x /app/utils/wait-for.sh | ||
|
||
RUN sed -i 's/"client": "0.0.0"/"client": "file:..\/client"/g' /app/package.json \ | ||
&& yarn install --production=true | ||
|
||
EXPOSE $SERVER_PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Используя Devtools: | ||
|
||
### Вкладка Memory | ||
|
||
В пункте Select JavaScript VM instance | ||
|
||
Показатель Total JS heap size на страницах: | ||
``` | ||
Start, Forum, LeaderBoard около 11МБ | ||
Game около 13МБ | ||
``` | ||
|
||
При использовании приложения и цикличном повторении переходов по страницам, показатели стабилизируются у начальных значений. | ||
|
||
Созданы моментальные снимки после загрузки страницы, и после использования. Состояние снимков приблизительно одинаковое. | ||
|
||
### Вкладка Recorder | ||
|
||
Сделаны записи с чекбоксом Memory. | ||
|
||
``` | ||
Старт записи: запуск приложения | ||
Окончание записи: после перехода всех страниц | ||
``` | ||
|
||
График с данными о используемой памяти не показывает периодических скачков в памяти или роста. | ||
|
||
### Вывод: | ||
|
||
Утечек в памяти не обнаружено |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,59 @@ | ||
### Как запускать? | ||
## Bumble | ||
|
||
1. Убедитесь что у вас установлен `node` и `docker` | ||
2. Выполните команду `yarn bootstrap` - это обязательный шаг, без него ничего работать не будет :) | ||
3. Выполните команду `yarn dev` | ||
3. Выполните команду `yarn dev --scope=client` чтобы запустить только клиент | ||
4. Выполните команду `yarn dev --scope=server` чтобы запустить только server | ||
Это игра в слова! | ||
|
||
Нужно собрать слово из букв за минуту. | ||
Чем длиннее - тем лучше. | ||
|
||
За каждую букву начисляются победные баллы. | ||
|
||
### Как добавить зависимости? | ||
В этом проекте используется `monorepo` на основе [`lerna`](https://github.com/lerna/lerna) | ||
## Deploy | ||
https://wordrunners-bumble-20.ya-praktikum.tech/ | ||
|
||
Чтобы добавить зависимость для клиента | ||
```yarn lerna add {your_dep} --scope client``` | ||
## Stack: | ||
|
||
Для сервера | ||
```yarn lerna add {your_dep} --scope server``` | ||
TypeScript, Canvas API, React, Redux, nginx, Git, GitHub Actions, Docker, Vite, HTML5, SASS, Express, Node.JS, Postgresql, Sequelize, jest | ||
|
||
И для клиента и для сервера | ||
```yarn lerna add {your_dep}``` | ||
## Основные функции: | ||
- Игра в слова Bumble | ||
- Авторизация / регистрация (по логин/пароль и oAuth) | ||
- Редактирование данных профиля | ||
- Создание тем форума | ||
- Создание сообщений, ответов и добавление реакций в форуме | ||
- Сохранение результата в Лидерборде | ||
- Переключение темы оформления | ||
|
||
## Основные команды | ||
|
||
Если вы хотите добавить dev зависимость, проделайте то же самое, но с флагом `dev` | ||
```yarn lerna add {your_dep} --dev --scope server``` | ||
### Как собрать и запустить Сервер и БД в Docker? | ||
```yarn docker:build``` | ||
|
||
### Как начать разрабатывать в hot-reload режиме с БД в Docker? | ||
По умолчанию запуститься на localhost:5000. После сборки Docker сервисов. В отдельных терминалах: | ||
|
||
### Тесты | ||
```yarn docker:db``` | ||
```yarn dev``` | ||
|
||
Для клиента используется [`react-testing-library`](https://testing-library.com/docs/react-testing-library/intro/) | ||
### Как собрать Клиент с nginx и Сервер в prod? | ||
```yarn docker:prod``` | ||
|
||
### Тесты | ||
Для клиента используется [`react-testing-library`](https://testing-library.com/docs/react-testing-library/intro/) | ||
```yarn test``` | ||
|
||
### Линтинг | ||
|
||
```yarn lint``` | ||
|
||
### Форматирование prettier | ||
|
||
```yarn format``` | ||
|
||
### Production build | ||
|
||
```yarn build``` | ||
|
||
И чтобы посмотреть что получилось | ||
|
||
|
||
`yarn preview --scope client` | ||
`yarn preview --scope server` | ||
|
||
## Хуки | ||
В проекте используется [lefthook](https://github.com/evilmartians/lefthook) | ||
Если очень-очень нужно пропустить проверки, используйте `--no-verify` (но не злоупотребляйте :) | ||
|
||
## Ой, ничего не работает :( | ||
|
||
Откройте issue, я приду :) | ||
|
||
## Автодеплой статики на vercel | ||
Зарегистрируйте аккаунт на [vercel](https://vercel.com/) | ||
Следуйте [инструкции](https://vitejs.dev/guide/static-deploy.html#vercel-for-git) | ||
В качестве `root directory` укажите `packages/client` | ||
|
||
Все ваши PR будут автоматически деплоиться на vercel. URL вам предоставит деплоящий бот | ||
|
||
## Production окружение в докере | ||
### Production окружение в докере | ||
Перед первым запуском выполните `node init.js` | ||
|
||
|
||
`docker compose up` - запустит три сервиса | ||
1. nginx, раздающий клиентскую статику (client) | ||
2. node, ваш сервер (server) | ||
3. postgres, вашу базу данных (postgres) | ||
|
||
Если вам понадобится только один сервис, просто уточните какой в команде | ||
`docker compose up {sevice_name}`, например `docker compose up server` | ||
`docker compose up {sevice_name}`, например `docker compose up server` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
version: '3.9' | ||
|
||
services: | ||
server: | ||
container_name: practicum-server | ||
image: practicum-server | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
args: | ||
SERVER_PORT: ${SERVER_PORT} | ||
restart: always | ||
ports: | ||
- '${SERVER_PORT}:${SERVER_PORT}' | ||
environment: | ||
POSTGRES_HOST: 'postgres' | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | ||
POSTGRES_USER: ${POSTGRES_USER} | ||
POSTGRES_DB: ${POSTGRES_DB} | ||
SERVER_PORT: ${SERVER_PORT} | ||
networks: | ||
- awesome | ||
depends_on: | ||
- postgres | ||
command: | ||
./utils/wait-for.sh postgres:${POSTGRES_PORT} -- node /app/index.js | ||
|
||
postgres: | ||
image: postgres:14 | ||
restart: always | ||
ports: | ||
- '${POSTGRES_PORT}:${POSTGRES_PORT}' | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | ||
POSTGRES_USER: ${POSTGRES_USER} | ||
POSTGRES_DB: ${POSTGRES_DB} | ||
volumes: | ||
- pg-data:/var/lib/postgresql/data | ||
networks: | ||
- awesome | ||
|
||
pgadmin: | ||
image: dpage/pgadmin4:6.19 | ||
env_file: | ||
./.env | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL} | ||
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD} | ||
PGADMIN_LISTEN_PORT: 80 | ||
ports: | ||
- '8080:80' | ||
volumes: | ||
- pgadmin-data:/var/lib/pgadmin | ||
depends_on: | ||
- postgres | ||
networks: | ||
- awesome | ||
|
||
networks: | ||
awesome: | ||
driver: bridge | ||
|
||
volumes: | ||
pg-data: | ||
pgadmin-data: |
Oops, something went wrong.