Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mfreeman451 committed Feb 24, 2025
1 parent 7ea340c commit e2797ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
20 changes: 15 additions & 5 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
defaultBaseImage: cgr.dev/chainguard/static:latest

builds:
- id: serviceradar-agent
- id: agent
dir: ./cmd/agent
main: ./cmd/agent
env:
- CGO_ENABLED=0
flags:
- -tags=containers
ldflags:
- -s -w -X main.version={{.Env.VERSION}}

- id: serviceradar-poller
- id: poller
dir: ./cmd/poller
main: ./cmd/poller
env:
- CGO_ENABLED=0
flags:
- -tags=containers
ldflags:
- -s -w -X main.version={{.Env.VERSION}}

- id: serviceradar-cloud
- id: cloud
dir: ./cmd/cloud
main: ./cmd/cloud
env:
- CGO_ENABLED=0
flags:
- -tags=containers
ldflags:
- -s -w -X main.version={{.Env.VERSION}}

- id: serviceradar-dusk-checker
- id: dusk-checker
dir: ./cmd/checkers/dusk
main: ./cmd/checkers/dusk
env:
- CGO_ENABLED=0
flags:
- -tags=containers
ldflags:
- -s -w -X main.version={{.Env.VERSION}}

- id: serviceradar-snmp-checker
- id: snmp-checker
dir: ./cmd/checkers/snmp
main: ./cmd/checkers/snmp
env:
- CGO_ENABLED=0
flags:
- -tags=containers
ldflags:
- -s -w -X main.version={{.Env.VERSION}}
32 changes: 10 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,20 @@ kodata-prep: build-web ## Prepare kodata directories
.PHONY: container-build
container-build: kodata-prep ## Build container images with ko
@echo "$(COLOR_BOLD)Building container images with ko$(COLOR_RESET)"
@GOFLAGS="-tags=containers" KO_DOCKER_REPO=$(KO_DOCKER_REPO) ko build \
--platform=$(PLATFORMS) \
--base-import-paths \
--tags=$(VERSION) \
--bare \
--image-refs=image-refs.txt \
./cmd/agent \
./cmd/poller \
./cmd/cloud \
./cmd/checkers/dusk \
./cmd/checkers/snmp
@cd cmd/agent && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION) .
@cd cmd/poller && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION) .
@cd cmd/cloud && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION) .
@cd cmd/checkers/dusk && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION) .
@cd cmd/checkers/snmp && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION) .

.PHONY: container-push
container-push: kodata-prep ## Build and push container images with ko
@echo "$(COLOR_BOLD)Building and pushing container images with ko$(COLOR_RESET)"
@GOFLAGS="-tags=containers" KO_DOCKER_REPO=$(KO_DOCKER_REPO) ko build \
--platform=$(PLATFORMS) \
--base-import-paths \
--tags=$(VERSION),latest \
--bare \
--image-refs=image-refs.txt \
./cmd/agent \
./cmd/poller \
./cmd/cloud \
./cmd/checkers/dusk \
./cmd/checkers/snmp
@cd cmd/agent && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION),latest .
@cd cmd/poller && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION),latest .
@cd cmd/cloud && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION),latest .
@cd cmd/checkers/dusk && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION),latest .
@cd cmd/checkers/snmp && KO_DOCKER_REPO=$(KO_DOCKER_REPO) GOFLAGS="-tags=containers" ko build --bare --platform=$(PLATFORMS) --tags=$(VERSION),latest .

# Build Debian packages
.PHONY: deb-agent
Expand Down
28 changes: 26 additions & 2 deletions pkg/cloud/api/static_serve_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,32 @@

package api

import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/mfreeman451/serviceradar/pkg/cloud/api/web"
)

// configureStaticServing sets up static file serving for container mode
func (s *APIServer) configureStaticServing() {
// Use Ko's approach for containers
s.setupContainerStaticFileServing()
staticFilesPath := web.GetStaticFilesPath()
fileServer := http.FileServer(http.Dir(staticFilesPath))

s.router.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check if file exists
path := filepath.Join(staticFilesPath, r.URL.Path)
_, err := os.Stat(path)

// If file doesn't exist or is a directory (and not root), serve index.html
if os.IsNotExist(err) || (r.URL.Path != "/" && strings.HasSuffix(r.URL.Path, "/")) {
http.ServeFile(w, r, filepath.Join(staticFilesPath, "index.html"))
return
}

// Otherwise serve the requested file
fileServer.ServeHTTP(w, r)
})
}

0 comments on commit e2797ce

Please sign in to comment.