Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,26 @@ jobs:

- name: Success
run: echo "✅ All Master checks passed."

docker-build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build all images
run: docker compose build

- name: Start services
run: docker compose up -d

- name: Wait for services to start
run: sleep 10

- name: Check logs for relay/master/agent
run: docker compose logs

- name: Shut down stack
run: docker compose down
2 changes: 1 addition & 1 deletion agent/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
relay_url: "http://localhost:8080/report"
relay_url: "http://relay:8101/report"

report_interval: 1 #(seconds)

Expand Down
22 changes: 22 additions & 0 deletions agent/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:alpine AS build

WORKDIR /app

# ./ is same as /app/ ... as we have set the workdir as /app
COPY go.mod go.sum ./
RUN go mod download

COPY agent/. .
COPY common ./common

RUN go build -o agent ./main.go


FROM alpine:latest

WORKDIR /app

COPY --from=build /app/agent .
COPY agent/config.yaml .

ENTRYPOINT ["./agent"]
4 changes: 1 addition & 3 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ func loadConfig() (*common.AgentConfig, error) {
var config common.AgentConfig
if len(data) == 0 {
// empty config file ... create a default one and read it
config.RelayURL = "http://localhost:8080/report"
config.RelayURL = "http://localhost:8101/report"
config.ReportInterval = 1
config.Thresholds.CPUPercentage = 80.0
config.Thresholds.UsedMemPercentage = 90.0

_, err = yaml.Marshal(&config)
errorCheck(err, "error creating default config file")
Expand Down
26 changes: 26 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
agent:
build:
context: .
dockerfile: agent/dockerfile
volumes:
- ./agent/config.yaml:/app/config.yaml
depends_on:
- relay

relay:
build:
context: .
dockerfile: relay/dockerfile
volumes:
- ./relay/config.yaml:/app/config.yaml
depends_on:
- master

master:
build:
context: .
dockerfile: master/dockerfile
volumes:
- ./master/config.yaml:/app/config.yaml

2 changes: 1 addition & 1 deletion master/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
port: 9090
port: 9101

# Levels-> { "info" , "warn" , "debug" }
logging_level: "info"
Expand Down
22 changes: 22 additions & 0 deletions master/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:alpine AS build

WORKDIR /app

# ./ is same as /app/ ... as we have set the workdir as /app
COPY go.mod go.sum ./
RUN go mod download

COPY master/. .
COPY common ./common

RUN go build -o master ./main.go


FROM alpine:latest

WORKDIR /app

COPY --from=build /app/master .
COPY master/config.yaml .

ENTRYPOINT ["./master"]
2 changes: 1 addition & 1 deletion master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func loadConfig() (*common.ServerConfig, error) {
var config common.ServerConfig
if len(data) == 0 {
// empty config file ... create a default one and read it
config.Port = 9090
config.Port = 9101
config.LogLevel = "info"

_, err = yaml.Marshal(&config)
Expand Down
4 changes: 2 additions & 2 deletions relay/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
port: 8080
port: 8101

# Levels-> { "info" , "warn" , "debug" }
logging_level: "info"

flush_interval: 5 # in seconds

master_url: "http://localhost:9090/report"
master_url: "http://master:9101/report"
22 changes: 22 additions & 0 deletions relay/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:alpine AS build

WORKDIR /app

# ./ is same as /app/ ... as we have set the workdir as /app
COPY go.mod go.sum ./
RUN go mod download

COPY relay/. .
COPY common ./common

RUN go build -o relay ./main.go


FROM alpine:latest

WORKDIR /app

COPY --from=build /app/relay .
COPY relay/config.yaml .

ENTRYPOINT ["./relay"]
7 changes: 4 additions & 3 deletions relay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
jsonBatch, _ := json.Marshal(s)
resp, err := http.Post(conf.MasterUrl, "application/json", bytes.NewReader(jsonBatch))
if err != nil {
fmt.Println("Error encountered while informing MASTER!")
log.Printf("Error encountered while informing MASTER! %v", err)
return
}
resp.Body.Close()
Expand All @@ -52,7 +52,8 @@ func displayReport(respw http.ResponseWriter, req *http.Request) {
http.Error(respw, "Invalid JSON", http.StatusBadRequest)
return
}
fmt.Printf("[RECEIVED] %+v\n", sig)
// fmt.Printf("[RECEIVED] %+v\n", sig)
fmt.Printf("[RECEIVED signal from] %+v\n", sig.HostID)
// fmt.Printf("buffer.signals: %v\n", buffer.signals)

buffer.Lock()
Expand Down Expand Up @@ -102,7 +103,7 @@ func loadConfig() (*common.RelayConfig, error) {
var config common.RelayConfig
if len(data) == 0 {
// empty config file ... create a default one and read it
config.Port = 8080
config.Port = 8101
config.LogLevel = "info"
config.FlushInterval = 5

Expand Down