Skip to content

Commit ef2fa31

Browse files
committed
📦 new: add workflows and update env
1 parent 24473cf commit ef2fa31

File tree

6 files changed

+262
-6
lines changed

6 files changed

+262
-6
lines changed

‎.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ UNTHREAD_SLACK_CHANNEL_ID=your_unthread_slack_channel_id_here
1111
UNTHREAD_WEBHOOK_SECRET=your_unthread_webhook_secret_here
1212

1313
# ======= Infrastructure =======
14+
# Database Credentials (CHANGE THESE IN PRODUCTION!)
15+
POSTGRES_USER=postgres
16+
POSTGRES_PASSWORD=your_secure_password_here
17+
1418
# Local: redis://localhost:6379, redis://localhost:6380
1519
# Docker: redis://redis-platform:6379, redis://redis-webhook:6379
1620
PLATFORM_REDIS_URL=redis://localhost:6379
1721
WEBHOOK_REDIS_URL=redis://localhost:6380
1822

1923
# Local: postgresql://postgres:postgres@localhost:5432/unthread_telegram_bot
20-
# Docker: postgresql://postgres:postgres@postgres-platform:5432/unthread_telegram_bot
21-
POSTGRES_URL=postgresql://postgres:postgres@localhost:5432/unthread_telegram_bot
24+
# Docker: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres-platform:5432/unthread_telegram_bot
25+
POSTGRES_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/unthread_telegram_bot
2226

2327
# ======= Application Settings =======
2428
NODE_ENV=development

‎.github/workflows/build.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
7+
env:
8+
REGISTRY_DOCKERHUB: wgtechlabs/unthread-telegram-bot
9+
REGISTRY_GHCR: ghcr.io/wgtechlabs/unthread-telegram-bot
10+
11+
jobs:
12+
build-dev:
13+
name: Build Development Images
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Login to Docker Hub
24+
uses: docker/login-action@v3
25+
with:
26+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
27+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
28+
29+
- name: Login to GitHub Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata
37+
id: meta
38+
run: |
39+
echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
40+
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
41+
42+
- name: Build and push development images
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: .
46+
push: true
47+
platforms: linux/amd64
48+
tags: |
49+
${{ env.REGISTRY_DOCKERHUB }}:dev
50+
${{ env.REGISTRY_DOCKERHUB }}:dev-${{ steps.meta.outputs.short_sha }}
51+
${{ env.REGISTRY_GHCR }}:dev
52+
${{ env.REGISTRY_GHCR }}:dev-${{ steps.meta.outputs.short_sha }}
53+
labels: |
54+
org.opencontainers.image.title=Unthread Telegram Bot
55+
org.opencontainers.image.description=Turn private Telegram groups into real-time support ticket hubs — powered by Unthread.io.
56+
org.opencontainers.image.version=dev-${{ steps.meta.outputs.short_sha }}
57+
org.opencontainers.image.created=${{ steps.meta.outputs.build_date }}
58+
org.opencontainers.image.revision=${{ github.sha }}
59+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
60+
org.opencontainers.image.licenses=GPL-3.0
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max
63+
64+
- name: Development build summary
65+
run: |
66+
echo "## 🔨 Development Build Complete" >> $GITHUB_STEP_SUMMARY
67+
echo "**Images built and pushed:**" >> $GITHUB_STEP_SUMMARY
68+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:dev\`" >> $GITHUB_STEP_SUMMARY
69+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:dev-${{ steps.meta.outputs.short_sha }}\`" >> $GITHUB_STEP_SUMMARY
70+
echo "- \`${{ env.REGISTRY_GHCR }}:dev\`" >> $GITHUB_STEP_SUMMARY
71+
echo "- \`${{ env.REGISTRY_GHCR }}:dev-${{ steps.meta.outputs.short_sha }}\`" >> $GITHUB_STEP_SUMMARY
72+
echo "**Test the dev image:**" >> $GITHUB_STEP_SUMMARY
73+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
74+
echo "docker pull ${{ env.REGISTRY_DOCKERHUB }}:dev" >> $GITHUB_STEP_SUMMARY
75+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

‎.github/workflows/release.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
REGISTRY_DOCKERHUB: wgtechlabs/unthread-telegram-bot
9+
REGISTRY_GHCR: ghcr.io/wgtechlabs/unthread-telegram-bot
10+
11+
jobs:
12+
build-production:
13+
name: Build Production Images
14+
runs-on: ubuntu-latest
15+
if: startsWith(github.ref, 'refs/tags/')
16+
permissions:
17+
contents: read
18+
packages: write
19+
security-events: write
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Login to Docker Hub
26+
uses: docker/login-action@v3
27+
with:
28+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
29+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
30+
31+
- name: Setup Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
with:
34+
driver: cloud
35+
endpoint: "wgtechlabs/unthread-bot-builder"
36+
install: true
37+
38+
- name: Login to GitHub Container Registry
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Extract version from package.json
46+
id: version
47+
run: |
48+
VERSION=$(node -p "require('./package.json').version")
49+
echo "version=$VERSION" >> $GITHUB_OUTPUT
50+
echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
51+
echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT
52+
echo "patch=$(echo $VERSION | cut -d. -f1-3)" >> $GITHUB_OUTPUT
53+
echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
54+
55+
- name: Generate Docker tags
56+
id: tags
57+
run: |
58+
VERSION="${{ steps.version.outputs.version }}"
59+
MAJOR="${{ steps.version.outputs.major }}"
60+
MINOR="${{ steps.version.outputs.minor }}"
61+
PATCH="${{ steps.version.outputs.patch }}"
62+
63+
# Docker Hub tags (no 'v' prefix)
64+
DOCKERHUB_TAGS="${{ env.REGISTRY_DOCKERHUB }}:latest"
65+
DOCKERHUB_TAGS="$DOCKERHUB_TAGS,${{ env.REGISTRY_DOCKERHUB }}:$VERSION"
66+
DOCKERHUB_TAGS="$DOCKERHUB_TAGS,${{ env.REGISTRY_DOCKERHUB }}:$PATCH"
67+
DOCKERHUB_TAGS="$DOCKERHUB_TAGS,${{ env.REGISTRY_DOCKERHUB }}:$MINOR"
68+
DOCKERHUB_TAGS="$DOCKERHUB_TAGS,${{ env.REGISTRY_DOCKERHUB }}:$MAJOR"
69+
70+
# GitHub Container Registry tags (with 'v' prefix)
71+
GHCR_TAGS="${{ env.REGISTRY_GHCR }}:latest"
72+
GHCR_TAGS="$GHCR_TAGS,${{ env.REGISTRY_GHCR }}:v$VERSION"
73+
GHCR_TAGS="$GHCR_TAGS,${{ env.REGISTRY_GHCR }}:v$PATCH"
74+
GHCR_TAGS="$GHCR_TAGS,${{ env.REGISTRY_GHCR }}:v$MINOR"
75+
GHCR_TAGS="$GHCR_TAGS,${{ env.REGISTRY_GHCR }}:v$MAJOR"
76+
77+
# Combine all tags
78+
ALL_TAGS="$DOCKERHUB_TAGS,$GHCR_TAGS"
79+
echo "tags=$ALL_TAGS" >> $GITHUB_OUTPUT
80+
81+
- name: Build and push production images
82+
uses: docker/build-push-action@v5
83+
with:
84+
context: .
85+
push: true
86+
platforms: linux/amd64,linux/arm64
87+
tags: ${{ steps.tags.outputs.tags }}
88+
labels: |
89+
org.opencontainers.image.title=Unthread Telegram Bot
90+
org.opencontainers.image.description=Turn private Telegram groups into real-time support ticket hubs — powered by Unthread.io.
91+
org.opencontainers.image.version=${{ steps.version.outputs.version }}
92+
org.opencontainers.image.created=${{ steps.version.outputs.build_date }}
93+
org.opencontainers.image.revision=${{ github.sha }}
94+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
95+
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
96+
org.opencontainers.image.licenses=GPL-3.0
97+
cache-from: type=gha
98+
cache-to: type=gha,mode=max
99+
100+
- name: Run Trivy vulnerability scanner
101+
uses: aquasecurity/[email protected]
102+
continue-on-error: true
103+
with:
104+
image-ref: ${{ env.REGISTRY_DOCKERHUB }}:${{ steps.version.outputs.version }}
105+
format: 'sarif'
106+
output: 'trivy-results.sarif'
107+
108+
- name: Upload Trivy scan results to GitHub Security tab
109+
uses: github/codeql-action/upload-sarif@v3
110+
if: always() && hashFiles('trivy-results.sarif') != ''
111+
with:
112+
sarif_file: 'trivy-results.sarif'
113+
114+
- name: Production release summary
115+
run: |
116+
echo "## 🚀 Production Release Complete" >> $GITHUB_STEP_SUMMARY
117+
echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
118+
echo "**Release:** \`${{ github.event.release.tag_name }}\`" >> $GITHUB_STEP_SUMMARY
119+
echo "" >> $GITHUB_STEP_SUMMARY
120+
echo "**Docker Hub Images:**" >> $GITHUB_STEP_SUMMARY
121+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:latest\`" >> $GITHUB_STEP_SUMMARY
122+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
123+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:${{ steps.version.outputs.patch }}\`" >> $GITHUB_STEP_SUMMARY
124+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:${{ steps.version.outputs.minor }}\`" >> $GITHUB_STEP_SUMMARY
125+
echo "- \`${{ env.REGISTRY_DOCKERHUB }}:${{ steps.version.outputs.major }}\`" >> $GITHUB_STEP_SUMMARY
126+
echo "" >> $GITHUB_STEP_SUMMARY
127+
echo "**GitHub Container Registry Images:**" >> $GITHUB_STEP_SUMMARY
128+
echo "- \`${{ env.REGISTRY_GHCR }}:latest\`" >> $GITHUB_STEP_SUMMARY
129+
echo "- \`${{ env.REGISTRY_GHCR }}:v${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
130+
echo "- \`${{ env.REGISTRY_GHCR }}:v${{ steps.version.outputs.patch }}\`" >> $GITHUB_STEP_SUMMARY
131+
echo "- \`${{ env.REGISTRY_GHCR }}:v${{ steps.version.outputs.minor }}\`" >> $GITHUB_STEP_SUMMARY
132+
echo "- \`${{ env.REGISTRY_GHCR }}:v${{ steps.version.outputs.major }}\`" >> $GITHUB_STEP_SUMMARY
133+
echo "" >> $GITHUB_STEP_SUMMARY
134+
echo "**Deploy with:**" >> $GITHUB_STEP_SUMMARY
135+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
136+
echo "docker pull ${{ env.REGISTRY_DOCKERHUB }}:latest" >> $GITHUB_STEP_SUMMARY
137+
echo "# OR" >> $GITHUB_STEP_SUMMARY
138+
echo "docker pull ${{ env.REGISTRY_GHCR }}:latest" >> $GITHUB_STEP_SUMMARY
139+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

‎.github/workflows/validate.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Validate
2+
3+
on:
4+
pull_request:
5+
branches: [dev, main]
6+
7+
jobs:
8+
validate:
9+
name: Validate Changes
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'yarn'
21+
22+
- name: Install dependencies
23+
run: yarn install --frozen-lockfile
24+
25+
- name: Type checking
26+
run: yarn type-check
27+
28+
- name: Build TypeScript
29+
run: yarn build
30+
31+
- name: Test Docker build (no push)
32+
run: |
33+
echo "Testing Docker build..."
34+
docker build -t test-build .
35+
echo "Build successful, cleaning up..."
36+
docker image rm test-build
37+
echo "✅ Docker build test completed"

‎docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ services:
7575
restart: always
7676
environment:
7777
POSTGRES_DB: unthread_telegram_bot # Database name
78-
POSTGRES_USER: postgres # Username
79-
POSTGRES_PASSWORD: postgres # Password (change in production!)
78+
POSTGRES_USER: ${POSTGRES_USER} # Username from .env file
79+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Password from .env file (secure!)
8080
ports:
8181
- "5432:5432" # Expose for external connections (optional)
8282
volumes:
8383
- postgres_data:/var/lib/postgresql/data # Persistent data storage
8484
healthcheck:
85-
test: ["CMD-SHELL", "pg_isready -U postgres"]
85+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
8686
interval: 10s
8787
timeout: 5s
8888
retries: 5

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unthread-telegram-bot",
33
"version": "1.0.0-beta.2",
4-
"description": "A Telegram bot integrated with Unthread API featuring enhanced logging with @wgtechlabs/log-engine",
4+
"description": "Turn private Telegram groups into real-time support ticket hubs — powered by Unthread.io.",
55
"keywords": [
66
"telegram",
77
"bot"
@@ -22,6 +22,7 @@
2222
"preinstall": "npx only-allow yarn",
2323
"clean": "rm -rf dist",
2424
"build": "tsc",
25+
"type-check": "tsc --noEmit",
2526
"start": "node dist/index.js",
2627
"dev": "nodemon --exec \"yarn build && yarn start\" src/index.ts",
2728
"dev:watch": "concurrently \"tsc --watch\" \"nodemon dist/index.js\"",

0 commit comments

Comments
 (0)