diff --git a/.gitignore b/.gitignore index 3997bea..adbb97d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.db \ No newline at end of file +data/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ba8df7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# build +FROM golang:1.25.4 AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 go build -o statsys . + +# copy +FROM alpine:latest + +WORKDIR /app +COPY --from=builder /app/statsys . +COPY --from=builder /app/www /app/www + +EXPOSE 8888/tcp +CMD [ "/app/statsys", "-config", "data/config.toml", "-db", "data/status.db" ] \ No newline at end of file diff --git a/README.md b/README.md index 0a89e07..55b5068 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,77 @@

statsys

-TODO: thumbnail +![thumbnail](assets/thumbnail.png) -

The cutest lightweight status page

+

the cutest lightweight status page

view demo | install

+ +## install + +
+docker compose (recommended) +
+ +Create a `docker-compose.yaml` file: + +```yaml +services: + statsys: + container_name: statsys + image: trafficlunar/statsys + restart: unless-stopped + volumes: + - ./data/:/app/data/ + ports: + - 8888:8888 +``` + +Create a new directory called `data` and download the `config.toml` example and edit it: + +```bash +mkdir data && cd data +wget https://raw.githubusercontent.com/trafficlunar/statsys/refs/heads/main/config.toml +``` + +When ready, run: + +```bash +docker compose up -d +``` + +Navigate to `localhost:8888` to view your status page! + +
+ +
+docker quick run +
+ +Create a new directory called `data` and download the `config.toml` example and edit it: + +```bash +mkdir data && cd data +wget https://raw.githubusercontent.com/trafficlunar/statsys/refs/heads/main/config.toml +``` + +Launch the container: + +```bash +docker run -d \ + --name statsys \ + --restart unless-stopped \ + -v "$(pwd)/data:/app/data" \ + -p 8888:8888 \ + trafficlunar/statsys +``` + +Navigate to `localhost:8888` to view your status page! + +
+ +
+manual +
+ +TODO + +
diff --git a/TODO.md b/TODO.md index 233dcb6..4abb399 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,4 @@ - [ ] Accessibility -- [ ] Better mobile support - [ ] View incidents - [ ] Latency graphs? - [ ] README diff --git a/assets/thumbnail.png b/assets/thumbnail.png new file mode 100644 index 0000000..8c46549 Binary files /dev/null and b/assets/thumbnail.png differ diff --git a/internal/config.go b/internal/config.go index 8cfbb18..418e53d 100644 --- a/internal/config.go +++ b/internal/config.go @@ -26,7 +26,7 @@ type Config struct { var config Config func LoadConfig() { - configFile, err := os.ReadFile("config.toml") + configFile, err := os.ReadFile(*ConfigPath) if err != nil { log.Fatalf("failed to load config: %v", err) } @@ -60,5 +60,5 @@ func LoadConfig() { templateData.Services[index] = service } - log.Println("config loaded") + log.Printf("config loaded from '%s'", *ConfigPath) } diff --git a/internal/database.go b/internal/database.go index 88efda1..d3258d9 100644 --- a/internal/database.go +++ b/internal/database.go @@ -15,9 +15,9 @@ var db *sql.DB func InitDatabase() { // open/create database var err error - db, err = sql.Open("sqlite", "status.db") + db, err = sql.Open("sqlite", *DatabasePath) if err != nil { - log.Fatalf("failed to initalise database: %v", err) + log.Fatalf("failed to initalize database: %v", err) } db.SetMaxOpenConns(1) @@ -97,7 +97,7 @@ func InitDatabase() { templateData.Services[index] = service } - log.Println("database initalised") + log.Printf("database initalized at '%s'", *DatabasePath) } func CloseDatabase() { diff --git a/internal/flags.go b/internal/flags.go new file mode 100644 index 0000000..d5ba619 --- /dev/null +++ b/internal/flags.go @@ -0,0 +1,12 @@ +package internal + +import "flag" + +var ConfigPath *string +var DatabasePath *string + +func ParseFlags() { + ConfigPath = flag.String("config", "config.toml", "path to config file") + DatabasePath = flag.String("db", "status.db", "path to database file") + flag.Parse() +} diff --git a/main.go b/main.go index 3f45b66..8461036 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import "statsys/internal" func main() { + internal.ParseFlags() internal.LoadConfig() internal.InitDatabase() defer internal.CloseDatabase()