Skip to content

🚀 release: v1.0.0-beta.2 #24

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

Merged
merged 28 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2b91b56
Initial plan for issue
Copilot Jun 21, 2025
23241e1
Add Dockerfile and .dockerignore for containerized deployment
Copilot Jun 21, 2025
a291fa6
Update README with Docker deployment instructions
Copilot Jun 21, 2025
71ab6e2
Streamline .dockerignore to focus on Node.js essentials only
Copilot Jun 21, 2025
65b8834
Initial plan for issue
Copilot Jun 21, 2025
4b1bdd6
Add security notice to Docker section in README.md
Copilot Jun 21, 2025
147c40d
Bump version to 1.0.0-beta.2 for Docker feature addition
Copilot Jun 21, 2025
76e53ec
Merge pull request #23 from wgtechlabs/copilot/fix-beefc49d-d8f9-4185…
warengonzaga Jun 21, 2025
bad476e
Refactor Docker preinstall approach to use environment variables inst…
Copilot Jun 21, 2025
4c232fd
Merge pull request #22 from wgtechlabs/copilot/fix-56e5a116-4122-4aee…
warengonzaga Jun 21, 2025
b7d44f5
📦 new: add docker support
warengonzaga Jun 21, 2025
687bdb9
☕ chore: update redis urls in readme
warengonzaga Jun 21, 2025
d01d68f
☕ chore: remove docker files
warengonzaga Jun 22, 2025
a964225
📦 new: add docker support
warengonzaga Jun 22, 2025
c2ca55d
✨ tweak: refactor Docker setup and enhance documentation for Unthread…
warengonzaga Jun 22, 2025
24473cf
☕ chore: update environment variables
warengonzaga Jun 22, 2025
ef2fa31
📦 new: add workflows and update env
warengonzaga Jun 22, 2025
cfd7ea8
✨ tweak: update docker-compose for server
warengonzaga Jun 22, 2025
9ec4797
🐛 fix: security issues
warengonzaga Jun 22, 2025
1360e34
✨ tweak: update dockerfile and dependencies
warengonzaga Jun 22, 2025
995171d
✨ tweak: update node version and dependencies
warengonzaga Jun 22, 2025
7c0900a
✨ tweak: enhance documentation and security measures
warengonzaga Jun 22, 2025
16aa102
✨ tweak: update sbom generation script
warengonzaga Jun 22, 2025
fc79c45
✨ tweak: update sbom generation script
warengonzaga Jun 22, 2025
5941366
✨ tweak: update sbom generation
warengonzaga Jun 22, 2025
8d2c395
✨ tweak: improve sbom script checks
warengonzaga Jun 22, 2025
a9a8a38
✨ tweak: update sbom script dependencies
warengonzaga Jun 22, 2025
ffbf58b
✨ tweak: update node version
warengonzaga Jun 22, 2025
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
64 changes: 64 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Node.js
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json

# Build output
dist/

# Git
.git/
.gitignore

# Environment files
.env
.env.*
!.env.example

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Logs
logs/
*.log

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm/

# Optional eslint cache
.eslintcache

# Yarn Integrity file
.yarn-integrity

# Test and validation scripts
*-test.js
*-validation.js

# Development container
.devcontainer/

# Documentation
README.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
SECURITY.md
32 changes: 32 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Docker Compose Environment Variables
# Copy this file to .env and fill in your actual values

# Required - Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here

# Required - Unthread API Configuration
UNTHREAD_API_KEY=your_unthread_api_key_here
UNTHREAD_CHANNEL_ID=your_unthread_channel_id_here
UNTHREAD_WEBHOOK_SECRET=your_unthread_webhook_secret_here

# Database Configuration
POSTGRES_URL=postgresql://unthread:unthread_password@postgres:5432/unthread_bot

# Redis Configuration
WEBHOOK_REDIS_URL=redis://redis:6379
PLATFORM_REDIS_URL=redis://redis:6379

# Optional - Webhook Configuration
WEBHOOK_POLL_INTERVAL=1000

# Optional - Company Configuration
COMPANY_NAME=Unthread

# Optional - Environment
NODE_ENV=production

# Database Internal Configuration
POSTGRES_DB=unthread_bot
POSTGRES_USER=unthread
POSTGRES_PASSWORD=unthread_password
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Multi-stage Dockerfile for TypeScript-based Telegram Bot

# Build stage
FROM node:20-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package files
COPY package.json yarn.lock ./

# Install all dependencies (including devDependencies for build)
# Update CA certificates for secure connections
RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates
RUN npm config set registry https://registry.npmjs.org/ && \
DOCKER_BUILD=true yarn install --frozen-lockfile

# Copy source code
COPY src/ ./src/
COPY tsconfig.json ./

# Build TypeScript
RUN yarn build

# Production stage
FROM node:20-alpine AS production

# Set working directory
WORKDIR /app

# Copy package files
COPY package.json yarn.lock ./

# Install only production dependencies
# Update CA certificates for secure connections
RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates
RUN npm config set registry https://registry.npmjs.org/ && \
DOCKER_BUILD=true yarn install --frozen-lockfile --production

# Copy built application from builder stage
COPY --from=builder /app/dist ./dist

# Set the entrypoint
CMD ["node", "dist/index.js"]
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ For webhook server setup instructions, see the [`wgtechlabs/unthread-webhook-ser
- Structured logging with `@wgtechlabs/log-engine` integration
- Auto-setup database schema on first run
- Clean separation of concerns with SDK architecture
- Docker support with multi-stage builds for easy deployment

### **🔧 Flexible Configuration**

Expand All @@ -145,7 +146,7 @@ The bot is designed for easy deployment with minimal configuration. Here's the f

#### **1. Environment Setup**

Create a `.env` file with the following required variables:
Create a `.env` file with the following required variables (you can copy from `.env.example`):

```bash
# Required - Telegram Bot Configuration
Expand All @@ -162,6 +163,7 @@ UNTHREAD_CHANNEL_ID=your_unthread_channel_id
# Requires wgtechlabs/unthread-webhook-server to be deployed and configured
WEBHOOK_REDIS_URL=redis://user:password@host:port
WEBHOOK_POLL_INTERVAL=1000
UNTHREAD_WEBHOOK_SECRET=your_unthread_webhook_secret

# Optional - Platform Redis (for advanced caching)
PLATFORM_REDIS_URL=redis://user:password@host:port
Expand Down Expand Up @@ -193,11 +195,56 @@ That's it! The database schema will be created automatically on first run.

#### **🐳 Docker Support**

##### Option 1: Docker Run (Single Container)

```bash
# Build the Docker image
docker build -t unthread-telegram-bot .

# Run the container with environment variables
docker run -d \
--name unthread-bot \
-e TELEGRAM_BOT_TOKEN=your_bot_token \
-e UNTHREAD_API_KEY=your_api_key \
-e UNTHREAD_CHANNEL_ID=your_channel_id \
-e UNTHREAD_WEBHOOK_SECRET=your_webhook_secret \
-e POSTGRES_URL=your_postgres_url \
unthread-telegram-bot
```

##### Option 2: Docker Compose (Recommended)

Docker Compose provides a complete setup with PostgreSQL and Redis included:

- **Complete Stack**: Automatically sets up the bot, PostgreSQL database, and Redis cache
- **Health Checks**: Ensures services start in the correct order
- **Data Persistence**: Database and Redis data are persisted across restarts
- **Network Isolation**: All services run in a dedicated Docker network
- **Easy Management**: Single command to start/stop the entire stack

```bash
# Coming soon - Docker deployment support
# Copy the Docker environment file
cp .env.docker .env

# Edit .env with your configuration
nano .env

# Start all services (bot, database, redis)
docker-compose up -d

# View logs
docker-compose logs -f unthread-bot

# Stop all services
docker-compose down
```

> [!WARNING]
> **Security Notice**
> Never commit sensitive secrets, credentials, or production environment variables (such as API keys or database URLs) to your repository.
> For production deployments, use Docker secrets, environment variables, or a secure secrets manager to inject sensitive values at runtime.
> This helps keep your application and data safe.

### **Database Requirements**

- **PostgreSQL 12+** (required)
Expand Down Expand Up @@ -346,6 +393,9 @@ createdb unthread_telegram_bot
# Copy example environment file
cp .env.example .env

# For Docker Compose deployment, use the Docker-specific template:
# cp .env.docker .env

# Edit .env with your configuration
nano .env
```
Expand Down
69 changes: 69 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.8'

services:
# Unthread Telegram Bot
unthread-bot:
build: .
container_name: unthread-telegram-bot
restart: unless-stopped
env_file:
- .env.docker
depends_on:
- postgres
- redis
networks:
- unthread-network

# PostgreSQL Database
postgres:
image: postgres:15-alpine
container_name: unthread-postgres
restart: unless-stopped
env_file:
- .env.docker
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_INITDB_ARGS=${POSTGRES_INITDB_ARGS}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U unthread -d unthread_bot"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
networks:
- unthread-network

# Redis Cache (optional but recommended)
redis:
image: redis:7-alpine
container_name: unthread-redis
restart: unless-stopped
command: redis-server --appendonly yes --requirepass unthread_redis_password
volumes:
- redis_data:/data
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "-a", "unthread_redis_password", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 30s
networks:
- unthread-network

volumes:
postgres_data:
driver: local
redis_data:
driver: local

networks:
unthread-network:
driver: bridge
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unthread-telegram-bot",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "A Telegram bot integrated with Unthread API featuring enhanced logging with @wgtechlabs/log-engine",
"main": "dist/index.js",
"type": "module",
Expand All @@ -11,10 +11,10 @@
},
"packageManager": "[email protected]",
"scripts": {
"preinstall": "npx only-allow yarn",
"preinstall": "test \"$DOCKER_BUILD\" = \"true\" || npx only-allow yarn",
"build": "tsc",
"start": "node dist/index.js",
"dev": "nodemon --exec 'npm run build && npm start' src/index.ts",
"dev": "nodemon --exec 'yarn build && yarn start' src/index.ts",
"dev:watch": "concurrently \"tsc --watch\" \"nodemon dist/index.js\"",
"clean": "rm -rf dist"
},
Expand Down