- Add multi-stage Dockerfile with Alpine Linux for minimal image size - Include docker-compose.yml for simplified deployment with volume persistence - Add .dockerignore to exclude unnecessary files from build context - Update main.go to support DATABASE_PATH environment variable - Update README to promote Docker as the recommended deployment method - Use non-root user in container for improved security - Final image size ~38MB with all dependencies Docker deployment now available via: docker-compose up -d or docker build -t alpenqueue . docker run -d -p 8080:8080 -v alpenqueue-data:/app/data alpenqueue 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"alpenqueue/pkg/db"
|
|
"alpenqueue/pkg/worker"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// Get database path from environment or use default
|
|
dbPath := os.Getenv("DATABASE_PATH")
|
|
if dbPath == "" {
|
|
dbPath = "./alpenqueue.db"
|
|
}
|
|
|
|
database, err := db.Init(dbPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer database.Close()
|
|
|
|
worker.Start(database)
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("AlpenQueue running!"))
|
|
})
|
|
|
|
http.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
var req struct {
|
|
WebhookURL string `json:"webhook_url"`
|
|
URL string `json:"url"`
|
|
Selector string `json:"selector"`
|
|
FrequencyMinutes int `json:"frequency_minutes"`
|
|
}
|
|
|
|
body, _ := io.ReadAll(r.Body)
|
|
json.Unmarshal(body, &req)
|
|
|
|
id, err := db.CreateJob(database, req.WebhookURL, req.URL, req.Selector, req.FrequencyMinutes)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
fmt.Fprintf(w, "Job %d created\n", id)
|
|
})
|
|
|
|
log.Println("Server starting on :8080")
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|