Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
82 changes: 82 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build output
dist/
build/

# 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

# Runtime data
pids/
*.pid
*.seed
*.pid.lock

# Coverage directory
coverage/
*.lcov

# Temporary folders
tmp/
temp/

# Documentation
docs/
ai_context/
README.md
CONTRIBUTING.md
CODE_OF_CONDUCT.md
LICENSE
SECURITY.md

# Package manager files
package-lock.json
.yarn-integrity
.yarn/

# TypeScript
*.tsbuildinfo

# Cache
.cache/
.parcel-cache/
.eslintcache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Testing
test/
tests/
__tests__/
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
NODE_ENV=development
PORT=3000
TARGET_PLATFORM=telegram
# For local development use: redis://localhost:6379
# For Docker Compose, this gets overridden automatically to: redis://redis:6379
REDIS_URL=redis://localhost:6379
UNTHREAD_WEBHOOK_SECRET=your_signing_secret_here
TARGET_PLATFORM=telegram
UNTHREAD_WEBHOOK_SECRET=your_webhook_secret_here
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ ai_context/

# Enforce Yarn usage - ignore npm lockfile
package-lock.json

# Environment files with sensitive data
.env
.env.local
.env.*.local
.env.production
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Multi-stage build for Unthread Webhook Server

# Build stage
FROM node:20-alpine AS builder

# Set working directory
WORKDIR /app

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

# Install all dependencies (including devDependencies for building)
RUN yarn install --frozen-lockfile --ignore-scripts

# Copy source code and build configuration
COPY src/ ./src/
COPY tsconfig.json ./

# Build the TypeScript application
RUN yarn build

# Production stage
FROM node:20-alpine AS production

# Set working directory
WORKDIR /app

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

# Set environment to production
ENV NODE_ENV=production
# Install only production dependencies
RUN yarn install --frozen-lockfile --production --ignore-scripts && \
yarn cache clean

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

# Copy environment example (for reference)
COPY .env.example ./

# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001

# Change ownership of the app directory to nodejs user
RUN chown -R nodejs:nodejs /app
USER nodejs

# Expose the port the app runs on
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"

# Start the application
CMD ["node", "dist/app.js"]
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ Server runs on `http://localhost:3000` with endpoints:
- `GET /health` - Health check
- `POST /unthread-webhook` - Webhook endpoint

## 🐳 Docker Setup

```bash
# 1. Copy environment template
cp .env.example .env
# Edit .env with your webhook secret

# 2. Start with Docker Compose
docker-compose up -d

# 3. Check status
docker-compose ps

# 4. View logs
docker-compose logs -f

# 5. Stop services
docker-compose down
```

**Environment Files:**

- `.env` - Single config file for both local development and Docker
- `.env.example` - Template (Redis URL gets overridden automatically for Docker)

## ⚙️ Configuration

### Environment Variables
Expand Down
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3.8'

services:
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 3s
retries: 3
start_period: 30s
webhook-server:
image: wgtechlabs/unthread-webhook-server:latest
container_name: docker-unthread-webhook-server
ports:
- "3000:3000"
env_file:
- .env
environment:
- REDIS_URL=redis://redis:6379
depends_on:
redis:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s

volumes:
redis_data:
driver: local

networks:
default:
name: unthread-integration-network
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unthread-webhook-server",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "A Node.js server application that receives webhook events from Unthread.io and queues them for processing.",
"license": "GPL-3.0",
"private": true,
Expand Down