mirror of
https://github.com/kerberos-io/agent.git
synced 2026-11-27 23:50:54 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
798e17781f | ||
|
|
b7af06a74b |
@@ -8,21 +8,29 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
nightly-build-amd64:
|
||||
# Build one image per architecture. Only architectures we also ship in
|
||||
# releases (amd64 + arm64): the golang/debian trixie base images don't
|
||||
# provide arm/v6, which made every nightly fail since February.
|
||||
nightly-build:
|
||||
# Nightlies always build the latest master: schedules run on the default
|
||||
# branch, and manual runs from any other branch are skipped.
|
||||
if: github.ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
# Let every architecture finish, so one broken build doesn't hide the others.
|
||||
fail-fast: false
|
||||
matrix:
|
||||
architecture: [amd64]
|
||||
architecture: [amd64, arm64]
|
||||
steps:
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
# Check out the triggering commit (master HEAD) so the code matches the
|
||||
# $GITHUB_SHA used in the image tags.
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
@@ -31,32 +39,25 @@ jobs:
|
||||
- name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
- name: Run Buildx
|
||||
run: docker buildx build --build-arg VERSION=$(echo $GITHUB_SHA | cut -c1-7) --platform linux/${{matrix.architecture}} -t kerberos/agent-nightly:arch-$(echo ${{matrix.architecture}} | tr / -)-$(echo $GITHUB_SHA | cut -c1-7) --push .
|
||||
- name: Create new and append to manifest
|
||||
run: docker buildx imagetools create -t kerberos/agent-nightly:$(echo $GITHUB_SHA | cut -c1-7) kerberos/agent-nightly:arch-$(echo ${{matrix.architecture}} | tr / -)-$(echo $GITHUB_SHA | cut -c1-7)
|
||||
nightly-build-other:
|
||||
run: docker buildx build --build-arg VERSION=$(echo $GITHUB_SHA | cut -c1-7) --platform linux/${{matrix.architecture}} -t kerberos/agent-nightly:arch-${{matrix.architecture}}-$(echo $GITHUB_SHA | cut -c1-7) --push .
|
||||
|
||||
# Create the multi-arch manifest once, after all architectures are pushed.
|
||||
# Previously each build job created/appended to it in parallel, so the
|
||||
# result depended on which job finished last.
|
||||
nightly-manifest:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
architecture: [arm64, arm/v7, arm/v6]
|
||||
needs: nightly-build
|
||||
steps:
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
- name: Run Buildx
|
||||
run: docker buildx build --build-arg VERSION=$(echo $GITHUB_SHA | cut -c1-7) --platform linux/${{matrix.architecture}} -t kerberos/agent-nightly:arch-$(echo ${{matrix.architecture}} | tr / -)-$(echo $GITHUB_SHA | cut -c1-7) --push .
|
||||
- name: Create new and append to manifest
|
||||
run: docker buildx imagetools create --append -t kerberos/agent-nightly:$(echo $GITHUB_SHA | cut -c1-7) kerberos/agent-nightly:arch-$(echo ${{matrix.architecture}} | tr / -)-$(echo $GITHUB_SHA | cut -c1-7)
|
||||
- name: Create manifest
|
||||
run: |
|
||||
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
|
||||
docker buildx imagetools create -t kerberos/agent-nightly:$SHORT_SHA \
|
||||
kerberos/agent-nightly:arch-amd64-$SHORT_SHA \
|
||||
kerberos/agent-nightly:arch-arm64-$SHORT_SHA
|
||||
|
||||
@@ -336,7 +336,7 @@ Notes:
|
||||
| `AGENT_AUTO_CLEAN_MIN_FREE_SPACE` | When `AUTO_CLEAN` is enabled and no `MAX_SIZE` is set, keep at least this much free space (in MB) on the recordings disk before deleting the oldest (already-uploaded first) recordings. Defaults to 5% of the disk. | "" |
|
||||
| `AGENT_TIME` | Enable the timetable for Kerberos Agent | "false" |
|
||||
| `AGENT_TIMETABLE` | A (weekly) time table to specify when to make recordings "start1,end1,start2,end2;start1.. | "" |
|
||||
| `AGENT_REGION_POLYGON` | One or more polygons for motion detection. Points are "x,y" separated by ";", polygons are separated by "\|": "x1,y1;x2,y2;x3,y3\|x1,y1;x2,y2;x3,y3". Each polygon needs at least 3 points. | "" |
|
||||
| `AGENT_REGION_POLYGON` | A single polygon set for motion detection: "x1,y1;x2,y2;x3,y3;... | "" |
|
||||
| `AGENT_CAPTURE_IPCAMERA_RTSP` | Full-HD RTSP or RTSPS endpoint for the target camera. | "" |
|
||||
| `AGENT_CAPTURE_IPCAMERA_RTSP_TRANSPORT` | Transport for the RTSP streams: "tcp", "udp" or "auto" (UDP first, falls back to TCP). | "tcp" |
|
||||
| `AGENT_CAPTURE_IPCAMERA_SUB_RTSP` | RTSP or RTSPS sub-stream endpoint used for livestreaming (WebRTC). | "" |
|
||||
|
||||
@@ -308,39 +308,6 @@ func initConfigPointers(config *models.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// parseRegionPolygons parses the AGENT_REGION_POLYGON value into motion
|
||||
// regions. Points are "x,y" pairs separated by ";", and several polygons can
|
||||
// be given separated by "|", e.g. "0,0;10,0;10,10|20,20;30,20;30,30". Each
|
||||
// part becomes its own polygon, with IDs "0", "1", ... assigned in order.
|
||||
// Invalid points are ignored, and empty parts or parts with fewer than 3 valid
|
||||
// points are skipped.
|
||||
func parseRegionPolygons(value string) []models.Polygon {
|
||||
polygons := []models.Polygon{}
|
||||
for _, part := range strings.Split(value, "|") {
|
||||
var coordinates []models.Coordinate
|
||||
for _, pair := range strings.Split(part, ";") {
|
||||
xy := strings.Split(strings.TrimSpace(pair), ",")
|
||||
if len(xy) != 2 {
|
||||
continue
|
||||
}
|
||||
x, errX := strconv.ParseFloat(strings.TrimSpace(xy[0]), 64)
|
||||
y, errY := strconv.ParseFloat(strings.TrimSpace(xy[1]), 64)
|
||||
if errX != nil || errY != nil {
|
||||
continue
|
||||
}
|
||||
coordinates = append(coordinates, models.Coordinate{X: x, Y: y})
|
||||
}
|
||||
if len(coordinates) < 3 {
|
||||
continue
|
||||
}
|
||||
polygons = append(polygons, models.Polygon{
|
||||
ID: strconv.Itoa(len(polygons)),
|
||||
Coordinates: coordinates,
|
||||
})
|
||||
}
|
||||
return polygons
|
||||
}
|
||||
|
||||
// applyAgentEnvVars applies the AGENT_* environment variables (optionally
|
||||
// carrying the given prefix, e.g. "GLOBAL_") onto configuration.Config. When
|
||||
// applyDefaults is true, defaults (such as the signing key) are applied after
|
||||
@@ -536,8 +503,35 @@ func applyAgentEnvVars(configuration *models.Configuration, prefix string, apply
|
||||
break
|
||||
|
||||
case "AGENT_REGION_POLYGON":
|
||||
// One or more polygons: "x,y;x,y;x,y|x,y;x,y;x,y"
|
||||
configuration.Config.Region.Polygon = parseRegionPolygons(value)
|
||||
var coordinates []models.Coordinate
|
||||
|
||||
// Convert value to coordinates array
|
||||
// 0,0;1,1;2,2;3,3
|
||||
coordinatesString := strings.Split(value, ";")
|
||||
for _, coordinateString := range coordinatesString {
|
||||
coordinate := strings.Split(coordinateString, ",")
|
||||
if len(coordinate) == 2 {
|
||||
x, err := strconv.ParseFloat(coordinate[0], 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
y, err := strconv.ParseFloat(coordinate[1], 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
coordinates = append(coordinates, models.Coordinate{
|
||||
X: x,
|
||||
Y: y,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
configuration.Config.Region.Polygon = []models.Polygon{
|
||||
{
|
||||
Coordinates: coordinates,
|
||||
ID: "0",
|
||||
},
|
||||
}
|
||||
break
|
||||
|
||||
/* MQTT settings for bi-directional communication */
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -153,93 +152,3 @@ func TestFactoryConfigRetryableErrors(t *testing.T) {
|
||||
t.Fatal("decode errors should not retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRegionPolygons(t *testing.T) {
|
||||
square := []models.Coordinate{{X: 0, Y: 0}, {X: 10, Y: 0}, {X: 10, Y: 10}, {X: 0, Y: 10}}
|
||||
triangle := []models.Coordinate{{X: 20, Y: 20}, {X: 30, Y: 20}, {X: 30, Y: 30}}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
want []models.Polygon
|
||||
}{
|
||||
{
|
||||
name: "single polygon parses as before",
|
||||
value: "0,0;10,0;10,10;0,10",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}},
|
||||
},
|
||||
{
|
||||
name: "multiple polygons separated by pipe",
|
||||
value: "0,0;10,0;10,10;0,10|20,20;30,20;30,30",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}, {ID: "1", Coordinates: triangle}},
|
||||
},
|
||||
{
|
||||
name: "issue example",
|
||||
value: "64,36;576,36;608,324;32,324|700,40;900,40;900,300",
|
||||
want: []models.Polygon{
|
||||
{ID: "0", Coordinates: []models.Coordinate{{X: 64, Y: 36}, {X: 576, Y: 36}, {X: 608, Y: 324}, {X: 32, Y: 324}}},
|
||||
{ID: "1", Coordinates: []models.Coordinate{{X: 700, Y: 40}, {X: 900, Y: 40}, {X: 900, Y: 300}}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty parts are skipped and ids stay sequential",
|
||||
value: "|0,0;10,0;10,10;0,10||20,20;30,20;30,30|",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}, {ID: "1", Coordinates: triangle}},
|
||||
},
|
||||
{
|
||||
name: "parts with fewer than 3 points are skipped",
|
||||
value: "1,1;2,2|0,0;10,0;10,10;0,10|5,5",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}},
|
||||
},
|
||||
{
|
||||
name: "invalid points are ignored before counting",
|
||||
value: "0,0;x,1;10,0;10;10,10;0,10;",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}},
|
||||
},
|
||||
{
|
||||
name: "whitespace is trimmed",
|
||||
value: " 0, 0 ; 10,0;10 ,10; 0,10 | 20,20; 30,20 ;30,30 ",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: square}, {ID: "1", Coordinates: triangle}},
|
||||
},
|
||||
{
|
||||
name: "decimal coordinates",
|
||||
value: "0.5,0.5;10.25,0;10,10.75",
|
||||
want: []models.Polygon{{ID: "0", Coordinates: []models.Coordinate{{X: 0.5, Y: 0.5}, {X: 10.25, Y: 0}, {X: 10, Y: 10.75}}}},
|
||||
},
|
||||
{name: "empty value", value: "", want: []models.Polygon{}},
|
||||
{name: "only separators", value: "||", want: []models.Polygon{}},
|
||||
{name: "single polygon with too few points", value: "0,0;10,10", want: []models.Polygon{}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := parseRegionPolygons(test.value)
|
||||
if !reflect.DeepEqual(got, test.want) {
|
||||
t.Fatalf("parseRegionPolygons(%q) = %+v, want %+v", test.value, got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyAgentEnvVarsRegionPolygon(t *testing.T) {
|
||||
for _, prefix := range []string{"", "GLOBAL_"} {
|
||||
t.Run("prefix="+prefix, func(t *testing.T) {
|
||||
t.Setenv(prefix+"AGENT_REGION_POLYGON", "0,0;10,0;10,10;0,10|20,20;30,20;30,30")
|
||||
configuration := &models.Configuration{}
|
||||
initConfigPointers(&configuration.Config)
|
||||
|
||||
applyAgentEnvVars(configuration, prefix, false)
|
||||
|
||||
polygons := configuration.Config.Region.Polygon
|
||||
if len(polygons) != 2 {
|
||||
t.Fatalf("got %d polygons, want 2: %+v", len(polygons), polygons)
|
||||
}
|
||||
if polygons[0].ID != "0" || polygons[1].ID != "1" {
|
||||
t.Fatalf("got ids %q, %q, want \"0\", \"1\"", polygons[0].ID, polygons[1].ID)
|
||||
}
|
||||
if len(polygons[0].Coordinates) != 4 || len(polygons[1].Coordinates) != 3 {
|
||||
t.Fatalf("got %d and %d points, want 4 and 3", len(polygons[0].Coordinates), len(polygons[1].Coordinates))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user