This commit is contained in:
2025-05-19 01:49:56 +04:00
commit e6fec752f9
52 changed files with 4337 additions and 0 deletions

17
cmd/api/Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM golang:1.24-alpine AS builder
WORKDIR /src
COPY go.mod go.sum ./
COPY ../../pkg ./pkg
COPY ../../cmd/api ./cmd/api
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o api ./cmd/api/main.go
FROM gcr.io/distroless/static-debian12:latest
WORKDIR /app
COPY --from=builder /src/api .
ENTRYPOINT ["/app/api"]

30
cmd/api/README.md Normal file
View File

@@ -0,0 +1,30 @@
# API Service
## Overview
The API service is responsible for serving custom Bluesky feeds to clients. It implements the necessary endpoints required by the Bluesky protocol to deliver feed content.
**Pre-Built Docker Image**: `git.aykhans.me/bsky/feedgen-api:latest`
## API Endpoints
- `GET /.well-known/did.json`: DID configuration
- `GET /xrpc/app.bsky.feed.describeFeedGenerator`: Describe the feed generator
- `GET /xrpc/app.bsky.feed.getFeedSkeleton`: Main feed endpoint
## Running the Service
### Docker
```bash
docker build -f cmd/api/Dockerfile -t bsky-feedgen-api .
docker run --env-file config/app/.api.env --env-file config/app/.mongodb.env -p 8421:8421 bsky-feedgen-api
```
### Local Development
```bash
task run-api
# or
make run-api
```

60
cmd/api/main.go Normal file
View File

@@ -0,0 +1,60 @@
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/aykhans/bsky-feedgen/pkg/api"
"github.com/aykhans/bsky-feedgen/pkg/config"
"github.com/aykhans/bsky-feedgen/pkg/feed"
"github.com/aykhans/bsky-feedgen/pkg/logger"
"github.com/aykhans/bsky-feedgen/pkg/storage/mongodb"
"github.com/aykhans/bsky-feedgen/pkg/storage/mongodb/collections"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go listenForTermination(func() { cancel() })
apiConfig, errMap := config.NewAPIConfig()
if errMap != nil {
logger.Log.Error("API ENV error", "error", errMap.ToStringMap())
os.Exit(1)
}
mongoDBConfig, errMap := config.NewMongoDBConfig()
if errMap != nil {
logger.Log.Error("mongodb ENV error", "error", errMap.ToStringMap())
os.Exit(1)
}
client, err := mongodb.NewDB(ctx, mongoDBConfig)
if err != nil {
logger.Log.Error("mongodb connection error", "error", err)
os.Exit(1)
}
feedAzCollection, err := collections.NewFeedAzCollection(client)
if err != nil {
logger.Log.Error(err.Error())
os.Exit(1)
}
feeds := []feed.Feed{
feed.NewFeedAz("AzPulse", apiConfig.FeedgenPublisherDID, feedAzCollection),
}
if err := api.Run(ctx, apiConfig, feeds); err != nil {
logger.Log.Error("API error", "error", err)
}
}
func listenForTermination(do func()) {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan
do()
}