Skip to content

Commit 4c232fd

Browse files
authored
Merge pull request #22 from wgtechlabs/copilot/fix-56e5a116-4122-4aee-a30e-027bbf52710d
feat: Add Docker support with multi-stage build for easy deployment
2 parents 4548192 + bad476e commit 4c232fd

File tree

4 files changed

+133
-3
lines changed

4 files changed

+133
-3
lines changed

.dockerignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Node.js
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
package-lock.json
7+
8+
# Build output
9+
dist/
10+
11+
# Git
12+
.git/
13+
.gitignore
14+
15+
# Environment files
16+
.env
17+
.env.*
18+
!.env.example
19+
20+
# IDE and editor files
21+
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# OS generated files
28+
.DS_Store
29+
.DS_Store?
30+
._*
31+
.Spotlight-V100
32+
.Trashes
33+
ehthumbs.db
34+
Thumbs.db
35+
36+
# Logs
37+
logs/
38+
*.log
39+
40+
# TypeScript cache
41+
*.tsbuildinfo
42+
43+
# Optional npm cache directory
44+
.npm/
45+
46+
# Optional eslint cache
47+
.eslintcache
48+
49+
# Yarn Integrity file
50+
.yarn-integrity
51+
52+
# Test and validation scripts
53+
*-test.js
54+
*-validation.js
55+
56+
# Development container
57+
.devcontainer/
58+
59+
# Documentation
60+
README.md
61+
CODE_OF_CONDUCT.md
62+
CONTRIBUTING.md
63+
LICENSE
64+
SECURITY.md

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Multi-stage Dockerfile for TypeScript-based Telegram Bot
2+
3+
# Build stage
4+
FROM node:20-alpine AS builder
5+
6+
# Set working directory
7+
WORKDIR /app
8+
9+
# Copy package files
10+
COPY package.json yarn.lock ./
11+
12+
# Install all dependencies (including devDependencies for build)
13+
# Configure npm and yarn for Docker environment
14+
RUN npm config set strict-ssl false && \
15+
npm config set registry http://registry.npmjs.org/ && \
16+
yarn config set strict-ssl false && \
17+
DOCKER_BUILD=true yarn install --frozen-lockfile
18+
19+
# Copy source code
20+
COPY src/ ./src/
21+
COPY tsconfig.json ./
22+
23+
# Build TypeScript
24+
RUN yarn build
25+
26+
# Production stage
27+
FROM node:20-alpine AS production
28+
29+
# Set working directory
30+
WORKDIR /app
31+
32+
# Copy package files
33+
COPY package.json yarn.lock ./
34+
35+
# Install only production dependencies
36+
# Configure npm and yarn for Docker environment
37+
RUN npm config set strict-ssl false && \
38+
npm config set registry http://registry.npmjs.org/ && \
39+
yarn config set strict-ssl false && \
40+
DOCKER_BUILD=true yarn install --frozen-lockfile --production
41+
42+
# Copy built application from builder stage
43+
COPY --from=builder /app/dist ./dist
44+
45+
# Set the entrypoint
46+
CMD ["node", "dist/index.js"]

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ For webhook server setup instructions, see the [`wgtechlabs/unthread-webhook-ser
129129
- Structured logging with `@wgtechlabs/log-engine` integration
130130
- Auto-setup database schema on first run
131131
- Clean separation of concerns with SDK architecture
132+
- Docker support with multi-stage builds for easy deployment
132133

133134
### **🔧 Flexible Configuration**
134135

@@ -194,10 +195,29 @@ That's it! The database schema will be created automatically on first run.
194195
#### **🐳 Docker Support**
195196

196197
```bash
197-
# Coming soon - Docker deployment support
198+
# Build the Docker image
199+
docker build -t unthread-telegram-bot .
200+
201+
# Run the container with environment variables
202+
docker run -d \
203+
--name unthread-bot \
204+
-e TELEGRAM_BOT_TOKEN=your_bot_token \
205+
-e UNTHREAD_API_KEY=your_api_key \
206+
-e UNTHREAD_CHANNEL_ID=your_channel_id \
207+
-e DATABASE_URL=your_postgres_url \
208+
unthread-telegram-bot
209+
210+
# Or use docker-compose (create docker-compose.yml first)
198211
docker-compose up -d
199212
```
200213

214+
> [!WARNING]
215+
> **Security Notice**
216+
>
217+
> Never commit sensitive secrets, credentials, or production environment variables (such as API keys or database URLs) to your repository.
218+
> For production deployments, use Docker secrets, environment variables, or a secure secrets manager to inject sensitive values at runtime.
219+
> This helps keep your application and data safe.
220+
201221
### **Database Requirements**
202222

203223
- **PostgreSQL 12+** (required)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unthread-telegram-bot",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0-beta.2",
44
"description": "A Telegram bot integrated with Unthread API featuring enhanced logging with @wgtechlabs/log-engine",
55
"main": "dist/index.js",
66
"type": "module",
@@ -11,7 +11,7 @@
1111
},
1212
"packageManager": "[email protected]",
1313
"scripts": {
14-
"preinstall": "npx only-allow yarn",
14+
"preinstall": "test \"$DOCKER_BUILD\" = \"true\" || npx only-allow yarn",
1515
"build": "tsc",
1616
"start": "node dist/index.js",
1717
"dev": "nodemon --exec 'npm run build && npm start' src/index.ts",

0 commit comments

Comments
 (0)