diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 060ce67..0906af5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,4 +14,5 @@ jobs: run: | docker login ghcr.io --username $GITHUB_ACTOR --password ${{ secrets.CR_TOKEN }} docker build . --file Dockerfile --tag ghcr.io/alfg/ffmpegd:${GITHUB_REF/refs\/tags\//} + docker push ghcr.io/alfg/ffmpegd:latest docker push ghcr.io/alfg/ffmpegd:${GITHUB_REF/refs\/tags\//} \ No newline at end of file diff --git a/README.md b/README.md index b6e0e43..9865efc 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,11 @@ A Docker image is available with [alfg/ffmpeg](https://github.com/alfg/docker-ff $ docker run -it -p 8080:8080 -v /tmp/:/home alfg/ffmpegd ``` +Or via GitHub Container Registry: +``` +$ docker run -it -p 8080:8080 -v /tmp/:/home ghcr.io/alfg/ffmpegd +``` + Or using the `docker-compose` example: ``` $ docker-compose up ffmpegd @@ -94,7 +99,6 @@ go build -v cmd/ffmpegd.go ``` ## TODO -* More CLI flags for server, ports, cwd and daemon mode. * Logging levels and output * More error handling * API documentation diff --git a/cmd/ffmpegd.go b/cmd/ffmpegd.go index 20f2684..f0c89f0 100644 --- a/cmd/ffmpegd.go +++ b/cmd/ffmpegd.go @@ -23,22 +23,24 @@ const ( ██╔══╝ ██╔══╝ ██║╚██╔╝██║██╔═══╝ ██╔══╝ ██║ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ██║██║ ███████╗╚██████╔╝██████╔╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ - v0.0.5 + v0.0.6 ` - version = "0.0.5" + version = "ffmpegd version 0.0.6" description = "[\u001b[32mffmpegd\u001b[0m] - websocket server for \u001b[33mffmpeg-commander\u001b[0m.\n" usage = ` Usage: - ffmpegd [port] - ffmpegd version -- This version. + ffmpegd Run server. + ffmpegd [port] Run server on port. + ffmpegd version Print version. + ffmpegd help This help text. ` progressInterval = time.Second * 1 ) var ( + port = "8080" allowedOrigins = []string{ - "http://localhost:8080", - "http://localhost:8081", + "http://localhost:" + port, "https://alfg.github.io", } clients = make(map[*websocket.Conn]bool) @@ -85,6 +87,8 @@ type file struct { } func Run() { + parseArgs() + // CLI Banner. printBanner() @@ -100,6 +104,27 @@ func Run() { startServer() } +func parseArgs() { + args := os.Args + + // Use defaults if no args are set. + if len(args) == 1 { + return + } + + // Print version, help or set port. + if args[1] == "version" || args[1] == "-v" { + fmt.Println(version) + os.Exit(1) + } else if args[1] == "help" || args[1] == "-h" { + fmt.Println(usage) + os.Exit(1) + } else if _, err := strconv.Atoi(args[1]); err == nil { + port = args[1] + } + +} + func printBanner() { fmt.Println(logo) fmt.Println(description) @@ -113,12 +138,12 @@ func startServer() { // Handles incoming WS messages from client. go handleMessages() - fmt.Println(" Server started on port \u001b[33m:8080\u001b[0m.") + fmt.Println(" Server started on port \u001b[33m:" + port + "\u001b[0m.") fmt.Println(" - Go to \u001b[33mhttps://alfg.github.io/ffmpeg-commander\u001b[0m to connect!") fmt.Println(" - \u001b[33mffmpegd\u001b[0m must be enabled in ffmpeg-commander options.") fmt.Println("") fmt.Printf("Waiting for connection...") - err := http.ListenAndServe(":8080", nil) + err := http.ListenAndServe(":"+port, nil) if err != nil { fmt.Println("ListenAndServe: ", err) }