File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ .git
2+ .idea
3+ .env
4+ Dockerfile
5+ docker-compose.yml
6+ ** /* .md
Original file line number Diff line number Diff line change 1- # Build Stage
1+ # Build stage
22FROM golang:1.26.3-alpine AS builder
33
4- # Install build dependencies
5- RUN apk add --no-cache git ca-certificates
6-
74WORKDIR /app
85
9- # Cache dependencies
6+ # Install git and ca-certificates
7+ RUN apk add --no-cache git ca-certificates tzdata
8+
9+ # Copy go mod and sum files
1010COPY go.mod go.sum ./
11+
12+ # Download all dependencies
1113RUN go mod download
1214
13- # Copy source and build
15+ # Copy the source code
1416COPY . .
15- RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o bot cmd/bot/main.go
1617
17- # Final Stage
18- FROM alpine:latest
18+ # Build the application
19+ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tg-githubbot cmd/bot/main.go
1920
20- # Security: Run as non-root user
21- RUN adduser -D -u 10001 botuser
21+ # Final stage
22+ FROM alpine:latest
2223
2324WORKDIR /app
2425
25- # Essential runtime dependencies
26- RUN apk --no-cache add ca-certificates tzdata
26+ # Copy the CA certificates from builder
27+ COPY --from=builder /etc/ssl/certs/ ca-certificates.crt /etc/ssl/certs/
2728
28- # Copy binary from builder
29- COPY --from=builder /app/bot .
29+ # Copy the built binary
30+ COPY --from=builder /app/tg-githubbot .
3031
31- # Use non-root user
32- USER botuser
32+ # Expose the webhook port (default 8080)
33+ EXPOSE 8080
3334
34- ENTRYPOINT ["./bot" ]
35+ # Command to run the executable
36+ CMD ["./tg-githubbot" ]
Original file line number Diff line number Diff line change 66 "fmt"
77 "github-webhook/internal/bot/middleware"
88 "log"
9+ "log/slog"
910 "net"
1011 "net/http"
1112 "os"
@@ -31,6 +32,9 @@ import (
3132)
3233
3334func main () {
35+ logger := slog .New (slog .NewJSONHandler (os .Stdout , nil ))
36+ slog .SetDefault (logger )
37+
3438 if err := run (); err != nil {
3539 log .Fatalf ("Application stopped: %v" , err )
3640 }
Original file line number Diff line number Diff line change 1+ version : ' 3.8'
2+
13services :
2- github- bot :
4+ bot :
35 build : .
4- restart : always
5- env_file : .env
6+ container_name : tg_githubbot
7+ restart : unless-stopped
8+ ports :
9+ - " 8080:8080"
10+ environment :
11+ - TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
12+ - GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
13+ - GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
14+ - MONGODB_URI=mongodb://mongo:27017
15+ - MONGODB_DB=${MONGODB_DB:-github_bot}
16+ - ENCRYPTION_KEY=${ENCRYPTION_KEY}
17+ - BASE_URL=${BASE_URL}
18+ - PORT=8080
619 depends_on :
720 - mongo
8- ports :
9- - " ${PORT:-8080}:${PORT:-8080}"
1021
1122 mongo :
12- image : mongo:7
13- restart : always
23+ image : mongo:latest
24+ container_name : tg_githubbot_mongo
25+ restart : unless-stopped
26+ ports :
27+ - " 27017:27017"
1428 volumes :
15- - mongo-data :/data/db
29+ - mongodb_data :/data/db
1630
1731volumes :
18- mongo-data :
32+ mongodb_data :
Original file line number Diff line number Diff line change @@ -61,6 +61,13 @@ func (d *DB) createIndexes() error {
6161 return err
6262 }
6363
64+ _ , err = d .Chats .Indexes ().CreateOne (ctx , mongo.IndexModel {
65+ Keys : bson.D {{Key : "links.webhook_id" , Value : 1 }},
66+ })
67+ if err != nil {
68+ return err
69+ }
70+
6471 return nil
6572}
6673
You can’t perform that action at this time.
0 commit comments