diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..77a365a --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..76fbbce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# 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 && \ + 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 +# 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 && \ + 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"] \ No newline at end of file diff --git a/README.md b/README.md index 8d08159..cefe205 100644 --- a/README.md +++ b/README.md @@ -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** @@ -194,10 +195,29 @@ 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 ``` +> [!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) diff --git a/package.json b/package.json index 6577536..eb7ccaf 100644 --- a/package.json +++ b/package.json @@ -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", @@ -11,7 +11,7 @@ }, "packageManager": "yarn@1.22.22", "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",