Skip to content

Commit

Permalink
Merge pull request #26 from mfreeman451/25-sqlite-integration
Browse files Browse the repository at this point in the history
25 sqlite integration
  • Loading branch information
mfreeman451 authored Jan 17, 2025
2 parents 3a77355 + 531f3a0 commit 2c5e8eb
Show file tree
Hide file tree
Showing 10 changed files with 884 additions and 292 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build HomeMon Packages

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc libc6-dev libsqlite3-dev
- name: Build packages
run: |
./buildAll.sh
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: homemon-packages
path: release-artifacts/*.deb
27 changes: 27 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM --platform=linux/amd64 golang:1.23-bullseye

# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get update \
&& apt-get install -y \
gcc \
libc6-dev \
libsqlite3-dev \
make \
nodejs \
&& rm -rf /var/lib/apt/lists/*

# Verify installations
RUN node --version && npm --version

WORKDIR /build

# Copy go mod files first for better caching
COPY go.mod go.sum ./
RUN go mod download

# Copy the rest of the source
COPY . .

# Default command - but we'll override this in build.sh
CMD ["./setup-deb-cloud.sh"]
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# Build the builder image
docker build -t homemon-builder -f Dockerfile.build .

# Run just the cloud package build in the container
docker run --rm -v $(pwd):/build homemon-builder ./setup-deb-cloud.sh

echo "Build completed. Check release-artifacts/ directory for the cloud package."
52 changes: 52 additions & 0 deletions db/homemon-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- Node information
CREATE TABLE IF NOT EXISTS nodes (
node_id TEXT PRIMARY KEY,
first_seen TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_seen TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_healthy BOOLEAN NOT NULL DEFAULT 0
);

-- Node status history
CREATE TABLE IF NOT EXISTS node_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
node_id TEXT NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_healthy BOOLEAN NOT NULL DEFAULT 0,
FOREIGN KEY (node_id) REFERENCES nodes(node_id) ON DELETE CASCADE
);

-- Service status
CREATE TABLE IF NOT EXISTS service_status (
id INTEGER PRIMARY KEY AUTOINCREMENT,
node_id TEXT NOT NULL,
service_name TEXT NOT NULL,
service_type TEXT NOT NULL,
available BOOLEAN NOT NULL DEFAULT 0,
details TEXT,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (node_id) REFERENCES nodes(node_id) ON DELETE CASCADE
);

-- Service history
CREATE TABLE IF NOT EXISTS service_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
service_status_id INTEGER NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
available BOOLEAN NOT NULL DEFAULT 0,
details TEXT,
FOREIGN KEY (service_status_id) REFERENCES service_status(id) ON DELETE CASCADE
);

-- Indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_node_history_node_time
ON node_history(node_id, timestamp);
CREATE INDEX IF NOT EXISTS idx_service_status_node_time
ON service_status(node_id, timestamp);
CREATE INDEX IF NOT EXISTS idx_service_status_type
ON service_status(service_type);
CREATE INDEX IF NOT EXISTS idx_service_history_status_time
ON service_history(service_status_id, timestamp);

-- Enable WAL mode for better concurrent access
PRAGMA journal_mode=WAL;
PRAGMA foreign_keys=ON;
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.4
require (
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/mattn/go-sqlite3 v1.14.24
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.36.2
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
Expand Down
1 change: 0 additions & 1 deletion pkg/cloud/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (s *APIServer) getSystemStatus(w http.ResponseWriter, _ *http.Request) {
status.TotalNodes, status.HealthyNodes, status.LastUpdate.Format(time.RFC3339))

w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(status); err != nil {
log.Printf("Error encoding system status: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
Expand Down
Loading

0 comments on commit 2c5e8eb

Please sign in to comment.