Skip to content

feat: Add Docker support with multi-stage build for easy deployment #22

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 10 commits into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
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
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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)
# Configure npm and yarn for Docker environment
RUN npm config set strict-ssl false && \
npm config set registry http://registry.npmjs.org/ && \
yarn config set strict-ssl false && \
sed -i 's/"preinstall": "npx only-allow yarn",/"preinstall": "",/' package.json && \
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
# Configure npm and yarn for Docker environment
RUN npm config set strict-ssl false && \
npm config set registry http://registry.npmjs.org/ && \
yarn config set strict-ssl false && \
sed -i 's/"preinstall": "npx only-allow yarn",/"preinstall": "",/' package.json && \
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"]
15 changes: 14 additions & 1 deletion 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 Down Expand Up @@ -194,7 +195,19 @@ That's it! The database schema will be created automatically on first run.
#### **🐳 Docker Support**

```bash
# Coming soon - Docker deployment support
# 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 DATABASE_URL=your_postgres_url \
unthread-telegram-bot

# Or use docker-compose (create docker-compose.yml first)
docker-compose up -d
```

Expand Down