Skip to content

Commit

Permalink
Remove Prisma and Docker from base template
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed Aug 11, 2023
1 parent 0660424 commit 9c1f7e0
Show file tree
Hide file tree
Showing 60 changed files with 783 additions and 2,002 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

7 changes: 2 additions & 5 deletions .example.bot.env → .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
NODE_ENV=development
LOG_LEVEL=info
CHECKPOINT_DISABLE=1
DATABASE_URL=postgresql://bot:bot@postgres:5432/bot?schema=public
REDIS_URL=redis://redis:6379/0
LOG_LEVEL=debug
BOT_SERVER_HOST=0.0.0.0
BOT_SERVER_PORT=80
BOT_ALLOWED_UPDATES=[]
BOT_TOKEN=123:ABCABCD
BOT_WEBHOOK=https://www.example.com/<BOT_TOKEN>
BOT_TOKEN=123:ABCABCD
BOT_ADMIN_USER_ID=1
4 changes: 0 additions & 4 deletions .example.postgres.env

This file was deleted.

47 changes: 12 additions & 35 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,20 @@ on:
pull_request:
branches: [main]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-docker-image:
build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and Push Versioned Docker Image
id: build-and-push
uses: docker/build-push-action@v4
if: ${{ github.ref != 'refs/heads/main' }}
with:
context: .
push: ${{ !github.event.pull_request.head.repo.fork }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and Push Latest Docker Image
id: build-and-push-latest
uses: docker/build-push-action@v4
if: ${{ github.ref == 'refs/heads/main' }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm run typecheck
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript build
build

# TypeScript cache
*.tsbuildinfo

Expand Down Expand Up @@ -132,4 +135,8 @@ data/
*.env

# Jetbrains IDE
.idea/
.idea/

# Ignore SQLite database
*.db
*.db-journal
42 changes: 0 additions & 42 deletions Dockerfile

This file was deleted.

164 changes: 89 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,146 @@
<h1 align="center">🤖 Telegram Bot Template</h1>

Bot starter template based on [grammY](https://grammy.dev/) bot framework and [Prisma ORM](https://www.prisma.io/).
Uses PostgreSQL for data storage (MySQL, MongoDB, SQL Server, SQLite [are also supported by Prisma](https://www.prisma.io/docs/reference/database-reference/supported-databases)) and Redis for session storage.
<img align="right" width="35%" src="https://github.com/bot-base/telegram-bot-template/assets/26162440/c4371683-3e99-4b1c-ae8e-11ccbea78f4b">

Bot starter template based on [grammY](https://grammy.dev/) bot framework.

## Features

- Scalable structure
- Config loading and validation
- Logger
- Session storage
- Internationalization with language change
- Internationalization, language changing
- Graceful shutdown
- Metrics collection (in [prometheus](https://prometheus.io/) format)
- Fast and low overhead [fastify](https://www.fastify.io/) server
- Ready-to-use Docker setup
- Logger (powered by [pino](https://github.com/pinojs/pino))
- Fast and low overhead server (powered by [fastify](https://github.com/fastify/fastify))
- Ready-to-use deployment setups:
- [Docker](#docker)
- [Vercel](#vercel)
- Examples:
- [Prisma ORM](#prisma-orm)

## Usage

Clone this repo or generate new repo using this template via [link](https://github.com/bot-base/telegram-bot-template/generate)

```bash
git clone https://github.com/bot-base/telegram-bot-template
```

<details>
<summary>Launch</summary>
1. [Create a new repository](https://github.com/bot-base/telegram-bot-template/generate) using this template.

1. Create environment variables file
2. Create an environment variables file:

```bash
cp .example.bot.env .env
cp .env.example .env
```

2. Edit [environment variables](#environment-variables-reference) in `.env`
3. Set BOT_TOKEN [environment variable](#environment-variables) in `.env` file.


3. Launch bot
4. Launch bot

Development mode:

```bash
# install dependencies
# 1. Install dependencies
npm i

# run migrations
npx prisma migrate deploy

# run bot
# 2. Run bot (in watch mode)
npm run dev
```

Production mode:

```bash
# install dependencies
# 1. Install dependencies
npm i --only=prod
# run migrations
npx prisma migrate deploy
# build bot
npm run build
# 2. Set NODE_ENV to production and change BOT_WEBHOOK to the actual URL to receive updates
# run bot
npm start
# 3. Run bot
npm start
# or
npm run start:force # if you want to skip type checking
```

</details>
### List of available commands
- `npm run lint` — Lint source code.
- `npm run format` — Format source code.
- `npm run typecheck` — Runs type checking.
- `npm run dev` — Starts the bot in development mode.
- `npm run start` — Starts the bot.
- `npm run start:force` — Starts the bot without type checking.

<details>
<summary>Launch using Docker</summary>
## Deploy

1. Create development and production environment variables files
### Docker

```bash
# development
cp .example.bot.env docker-compose.dev.bot.env
cp .example.postgres.env docker-compose.dev.postgres.env
Branch:
[deploy/docker-compose](https://github.com/bot-base/telegram-bot-template/tree/deploy/docker-compose)
([open diff](https://github.com/bot-base/telegram-bot-template/compare/deploy/docker-compose))

# production
cp .example.bot.env docker-compose.prod.bot.env
cp .example.postgres.env docker-compose.prod.postgres.env
```
Use in your project:

2. Edit [environment variables](#environment-variables-reference) in `docker-compose.dev.bot.env` and `docker-compose.prod.bot.env`
1. Add the template repository as a remote

3. Launch bot
```sh
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
```

Development mode:
2. Merge deployment setup

```bash
# install dependencies
npm i
```sh
git merge template/deploy/docker-compose -X theirs --no-commit --allow-unrelated-histories
```

# run migrations
docker compose run bot npx prisma migrate deploy
### Vercel

# run bot
docker compose up
```
Branch:
[deploy/vercel](https://github.com/bot-base/telegram-bot-template/tree/deploy/vercel)
([open diff](https://github.com/bot-base/telegram-bot-template/compare/deploy/vercel))

Production mode:
Use in your project:

```bash
# run migrations
docker compose -f docker-compose.yml -f docker-compose.prod.yml run bot npx prisma migrate deploy
1. Add the template repository as a remote

# run bot
docker compose -f docker-compose.yml -f docker-compose.prod.yml up
```
```sh
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
```

2. Merge deployment setup

</details>
```sh
git merge template/deploy/vercel -X theirs --no-commit --allow-unrelated-histories
```

## Examples

- [Conversations](https://github.com/bot-base/telegram-bot-template/compare/examples/conversations)
- [Queues](https://github.com/bot-base/telegram-bot-template/compare/examples/queues)
### Prisma ORM

Branch:
[example/prisma](https://github.com/bot-base/telegram-bot-template/tree/example/prisma)
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/prisma))

Use in your project:

1. Add the template repository as a remote

```sh
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
```

2. Merge example

```sh
git merge template/example/prisma -X theirs --no-commit --allow-unrelated-histories
```

## Environment variables reference
## Environment Variables

| Variable | Description |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NODE_ENV | Node environment |
| NODE_ENV | Node environment (development or production) |
| LOG_LEVEL | Log level |
| CHECKPOINT_DISABLE | [Prisma Telemetry](https://www.prisma.io/docs/concepts/more/telemetry) |
| DATABASE_URL | Database URL |
| REDIS_URL | Redis URL |
| BOT_SERVER_HOST | Server address |
| BOT_SERVER_PORT | Server port |
| BOT_SERVER_HOST | Server address (default 0.0.0.0) |
| BOT_SERVER_PORT | Server port (default 80) |
| BOT_ALLOWED_UPDATES | List of [update types](https://core.telegram.org/bots/api#update) to receive |
| BOT_TOKEN | Token, get it from [@BotFather](https://t.me/BotFather) |
| BOT_WEBHOOK | <details><summary>Webhook endpoint</summary>Used for setup a webhook in production mode.</details> |
| BOT_ADMIN_USER_ID | <details><summary>Administrator user ID</summary>Commands, such as `/stats` or `/setcommands`, will only be available to the user with this ID.</details> |
| BOT_WEBHOOK | <details><summary>Webhook endpoint</summary>Will be used to setup webhook in production mode.</details> |
| BOT_ADMIN_USER_ID | <details><summary>Administrator user ID</summary>Commands, such as `/setcommands`, will only be available to the user with this ID.</details> |
26 changes: 0 additions & 26 deletions docker-compose.override.yml

This file was deleted.

Loading

0 comments on commit 9c1f7e0

Please sign in to comment.