Skip to content

Commit

Permalink
Made some decent progress on top of Djangolang
Browse files Browse the repository at this point in the history
  • Loading branch information
initialed85 committed Aug 6, 2024
1 parent e53d7ba commit b078ce1
Show file tree
Hide file tree
Showing 48 changed files with 49,139 additions and 290 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,29 @@

# status: not yet working

Intended as the spiritual sucessor to [initialed85/cameranator](https://github.com/initialed85/cameranator)
Intended as the spiritual sucessor to [initialed85/cameranator](https://github.com/initialed85/cameranator), build on [initialed85/djangolang](https://github.com/initialed85/djangolang)

## Usage

```shell
# shell 1
./run-env.sh

# shell 2
./build.sh

# shell 3
POSTGRES_DB=camry POSTGRES_PASSWORD=NoNVR\!11 go run ./cmd/ serve

# shell 4
websocat ws://localhost:7070/__stream | jq

# shell 5
curl -X POST http://localhost:7070/cameras -d '[{"name": "Driveway", "stream_url": "rtsp://192.168.137.31:554/Streaming/Channels/101"}]' | jq

# shell 6
PAGER=cat PGPASSWORD=NoNVR\!11 psql -h localhost -p 5432 -U postgres camry -c 'TRUNCATE TABLE video CASCADE;'

# shell 7
rm -fv *.mp4 *.jpg; ENABLE_PASSTHROUGH=1 CAMERA_NAME=Driveway NET_CAM_URL=rtsp://192.168.137.31:554/Streaming/Channels/101 POSTGRES_DB=camry POSTGRES_PASSWORD=NoNVR\!11 go run ./cmd segment_producer
```
61 changes: 61 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -e

# this block ensures we can invoke this script from anywhere and have it automatically change to this folder first
pushd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1
function teardown() {
popd >/dev/null 2>&1 || true
}
trap teardown exit

# ensure we've got a djangolang executable available (required for templating)
if [[ "${FORCE_UPDATE}" == "1" ]] || ! command -v djangolang >/dev/null 2>&1; then
GOPRIVATE="${GOPRIVATE:-}" go install github.com/initialed85/djangolang@latest
GOPRIVATE="${GOPRIVATE:-}" go get -u github.com/initialed85/djangolang@latest
fi

# we need oapi-codegen to generate the client for use by Go code
if ! command -v oapi-codegen; then
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@main
fi

# we need npm to generate the client for use by the frontend
if ! command -v npm >/dev/null 2>&1; then
echo "error: can't find npm command- you likely need to install node / npm"
exit 1
fi

# ensure the docker compose environment is already running
if ! docker compose ps | grep camry | grep postgres | grep healthy >/dev/null 2>&1; then
echo "error: can't find healthy docker compose environment; ensure to invoke ./run-env.sh in another shell"
exit 1
fi

# introspect the database and generate the Djangolang API
# note: the environment variables are coupled to the environment described in docker-compose.yaml
echo -e "\generating the api..."
DJANGOLANG_PACKAGE_NAME=api POSTGRES_DB=camry POSTGRES_PASSWORD=NoNVR!11 djangolang template

# dump out the OpenAPI v3 schema for the Djangolang API
mkdir -p ./schema
./pkg/api/bin/api dump-openapi-json >./schema/openapi.json

# generate the client for use by the frontend
echo -e "\ngenerating typescript client..."
cd frontend
if [[ "${FORCE_UPDATE}" == "1" ]]; then
npm ci
fi
npm run openapi-typescript
npm run prettier
cd ..

# generate the client for use by Go code
echo -e "\ngenerating go client..."
mkdir -p ./pkg/api_client
oapi-codegen --generate 'types,client,spec' -package api_client -o ./pkg/api_client/client.go ./schema/openapi.json
go mod tidy
goimports -w .
go get ./...
go fmt ./...
21 changes: 17 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@ package main
import (
"log"
"os"
"strings"

"github.com/initialed85/camry/pkg/app/segment_producer"
"github.com/initialed85/camry/pkg/api"
"github.com/initialed85/camry/pkg/segment_producer"
)

func main() {
if len(os.Args) < 2 {
log.Fatal("first arg must be command")
log.Fatal("first arg must be command (one of 'serve', 'dump-openapi-json', 'dump-openapi-yaml', 'segment_producer')")
}
command := os.Args[1]
log.Printf("command: %#+v", command)

command := strings.TrimSpace(strings.ToLower(os.Args[1]))

var err error

switch command {

case "dump-openapi-json":
api.RunDumpOpenAPIJSON()

case "dump-openapi-yaml":
api.RunDumpOpenAPIYAML()

case "serve":
api.RunServeWithEnvironment()

case "segment_producer":
err = segment_producer.Run()

}

if err != nil {
Expand Down
Empty file.
Loading

0 comments on commit b078ce1

Please sign in to comment.