diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0789cc0..1106c36 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/agent/config.yaml b/agent/config.yaml index 44e3434..b1d160f 100644 --- a/agent/config.yaml +++ b/agent/config.yaml @@ -1,4 +1,4 @@ -relay_url: "http://localhost:8080/report" +relay_url: "http://relay:8101/report" report_interval: 1 #(seconds) diff --git a/agent/dockerfile b/agent/dockerfile new file mode 100644 index 0000000..5ee9e43 --- /dev/null +++ b/agent/dockerfile @@ -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"] \ No newline at end of file diff --git a/agent/main.go b/agent/main.go index 614f4f2..f54a654 100644 --- a/agent/main.go +++ b/agent/main.go @@ -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") diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..5293c1f --- /dev/null +++ b/compose.yaml @@ -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 + \ No newline at end of file diff --git a/master/config.yaml b/master/config.yaml index c07685f..b6b9f03 100644 --- a/master/config.yaml +++ b/master/config.yaml @@ -1,4 +1,4 @@ -port: 9090 +port: 9101 # Levels-> { "info" , "warn" , "debug" } logging_level: "info" diff --git a/master/dockerfile b/master/dockerfile new file mode 100644 index 0000000..083d0b6 --- /dev/null +++ b/master/dockerfile @@ -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"] \ No newline at end of file diff --git a/master/main.go b/master/main.go index 977f080..434e190 100644 --- a/master/main.go +++ b/master/main.go @@ -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) diff --git a/relay/config.yaml b/relay/config.yaml index 5c06c8d..da71417 100644 --- a/relay/config.yaml +++ b/relay/config.yaml @@ -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" \ No newline at end of file +master_url: "http://master:9101/report" \ No newline at end of file diff --git a/relay/dockerfile b/relay/dockerfile new file mode 100644 index 0000000..5d52309 --- /dev/null +++ b/relay/dockerfile @@ -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"] \ No newline at end of file diff --git a/relay/main.go b/relay/main.go index ec6285c..16ae575 100644 --- a/relay/main.go +++ b/relay/main.go @@ -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() @@ -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() @@ -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