Skip to content

Commit b7a5424

Browse files
authored
Merge pull request #8 from makoni/develop
2.1.0
2 parents c90c7dc + fde8ed0 commit b7a5424

File tree

6 files changed

+128
-180
lines changed

6 files changed

+128
-180
lines changed

Dockerfile

Lines changed: 0 additions & 89 deletions
This file was deleted.

Package.resolved

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The Release Informer Bot provides a comprehensive subscription system for iOS ap
3232
- `Shared`: Common models and database management
3333
- **Robust Monitoring**: Automated release checking with intelligent rate limiting and error handling
3434
- **Scalable Storage**: CouchDB integration with optimized views for efficient queries
35-
- **Production Ready**: Comprehensive logging, error handling, and Docker support
35+
- **Production Ready**: Comprehensive logging and error handling
3636
- **Real-time Notifications**: Instant notifications with rich formatting including release notes
3737
- **Resource Management**: Intelligent memory management with version history limits (5 versions per app)
3838

@@ -42,7 +42,7 @@ The Release Informer Bot provides a comprehensive subscription system for iOS ap
4242
- **Concurrency**: Swift's native actor system for thread-safe operations
4343
- **Database**: CouchDB with custom views for efficient data access
4444
- **External APIs**: iTunes Search/Lookup API for app metadata
45-
- **Deployment**: Docker containers with multi-stage builds for production
45+
- **Deployment**: Flexible for local development and production
4646

4747
## Dependencies
4848

@@ -60,11 +60,11 @@ The project uses carefully selected, production-grade dependencies:
6060
## Deployment Instructions
6161

6262
### Prerequisites
63-
- Swift 6.0+ or Docker
63+
- Swift 6.0+
6464
- CouchDB instance (local or remote)
6565
- Telegram Bot Token (from [@BotFather](https://t.me/botfather))
6666

67-
### Option 1: Swift Package Manager (Development)
67+
### Swift Package Manager (Development)
6868

6969
1. **Clone the repository**:
7070
```bash
@@ -88,32 +88,6 @@ The project uses carefully selected, production-grade dependencies:
8888
swift test
8989
```
9090

91-
### Option 2: Docker (Recommended for Production)
92-
93-
1. **Build the Docker image**:
94-
```bash
95-
docker build -t releaseinformerbot .
96-
```
97-
98-
2. **Run with Docker**:
99-
```bash
100-
docker run -e apiKey="YOUR_TELEGRAM_BOT_TOKEN" -p 8080:8080 releaseinformerbot
101-
```
102-
103-
### Option 3: Docker Compose (Complete Setup)
104-
105-
1. **Start services**:
106-
```bash
107-
docker compose up -d
108-
```
109-
110-
2. **Set your bot token**:
111-
```bash
112-
# Edit docker-compose.yml or set environment variable
113-
export apiKey="YOUR_TELEGRAM_BOT_TOKEN"
114-
docker compose up app
115-
```
116-
11791
### Production Configuration
11892

11993
For production deployments, ensure:
@@ -124,7 +98,15 @@ For production deployments, ensure:
12498

12599
## CouchDB Setup
126100

127-
The bot requires the following CouchDB views for efficient data access:
101+
The bot will automatically create the required CouchDB database (`release_bot`) and design document with the necessary views on startup.
102+
103+
**Automatic Setup:**
104+
105+
- The `DBManager` includes a `setupIfNeed()` method that checks for the existence of the database and required views, and creates them if they do not exist. No manual setup is required for most users—just ensure your CouchDB instance is running and credentials are configured in `DBManager.swift`.
106+
107+
**Manual Setup (optional):**
108+
109+
If you prefer to create the database and design document manually, use the following JSON for the design document:
128110

129111
```json
130112
{

Sources/ReleaseInformerBot/configure.swift

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,53 @@ import Vapor
22
import Shared
33
import ReleaseWatcher
44
@preconcurrency import SwiftTelegramSdk
5+
import Logging
6+
7+
fileprivate let logger = Logger(label: "configure")
58

69
let dbManager = DBManager()
710
let releaseWatcher = ReleaseWatcher(dbManager: dbManager)
811

912
// configures your application
1013
public func configure(_ app: Application) async throws {
11-
let bot: TGBot = try await .init(
12-
connectionType: .longpolling(limit: nil, timeout: nil, allowedUpdates: nil),
13-
dispatcher: nil,
14-
tgClient: AsyncHttpTGClient(),
15-
tgURI: TGBot.standardTGURL,
16-
botId: ProcessInfo.processInfo.environment["apiKey"] ?? "",
17-
log: app.logger
18-
)
14+
do {
15+
try await dbManager.setupIfNeed()
16+
} catch {
17+
logger.error("Database setup failed: \(error.localizedDescription)")
18+
try await Task.sleep(for: .seconds(10))
19+
exit(1)
20+
}
21+
22+
let bot: TGBot
23+
do {
24+
bot = try await .init(
25+
connectionType: .longpolling(limit: nil, timeout: nil, allowedUpdates: nil),
26+
dispatcher: nil,
27+
tgClient: AsyncHttpTGClient(),
28+
tgURI: TGBot.standardTGURL,
29+
botId: ProcessInfo.processInfo.environment["apiKey"] ?? "",
30+
log: app.logger
31+
)
32+
} catch {
33+
logger.error("Could not initialize bot: \(error)")
34+
try await Task.sleep(for: .seconds(10))
35+
exit(1)
36+
}
1937

2038
let botActor: BotActor = .init()
2139

2240
await botActor.setBot(bot)
2341
await BotHandlers.addHandlers(bot: botActor.bot)
24-
try await botActor.bot.start()
2542

26-
await releaseWatcher.setBot(botActor.bot)
43+
do {
44+
try await botActor.bot.start()
45+
} catch {
46+
logger.error("Could not start bot: \(error.localizedDescription)")
47+
try await Task.sleep(for: .seconds(10))
48+
exit(1)
49+
}
2750

51+
await releaseWatcher.setBot(botActor.bot)
2852
await releaseWatcher.start()
2953

3054
// uncomment to serve files from /Public folder

0 commit comments

Comments
 (0)