From 67bd04cafd00bba33122fe7ca3ec9dc6cc4c65be Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Tue, 23 May 2023 21:52:00 -0400 Subject: [PATCH] Fix env vars and update chart --- Dockerfile | 17 ++++++++++++----- charts/ytdl-web/Chart.yaml | 4 ++-- charts/ytdl-web/values.yaml | 6 ++---- cmd/root.go | 6 +++--- config/config.go | 14 +++++++++----- ytdl/ytdl.go | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94c50bd..502e4e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ -ARG ALPINE_VERSION="3.17" +ARG YTDLP_VERSION="2023.03.04" -FROM alpine:${ALPINE_VERSION} +# trunk-ignore(hadolint/DL3007): Chainguard recommends latest +FROM cgr.dev/chainguard/static:latest WORKDIR /app -RUN apk add --no-cache yt-dlp ffmpeg +# Install yt-dlp +ARG YTDLP_VERSION=2023.03.04 +ADD https://github.com/yt-dlp/yt-dlp/releases/download/{YTDLP_VERSION}/yt-dlp /usr/local/bin/ + +# Install ffmpeg +COPY --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/ +COPY --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/ COPY ytdl-web ./ EXPOSE 8080 -ENV YTDL_PORT=8080 \ - YTDL_LISTEN=0.0.0.0 +ENV YTDL_HTTP_PORT=8080 \ + YTDL_HTTP_LISTEN=0.0.0.0 ENTRYPOINT [ "./ytdl-web" ] \ No newline at end of file diff --git a/charts/ytdl-web/Chart.yaml b/charts/ytdl-web/Chart.yaml index b9c8a69..a89598d 100644 --- a/charts/ytdl-web/Chart.yaml +++ b/charts/ytdl-web/Chart.yaml @@ -1,10 +1,10 @@ apiVersion: v2 description: A web-based frontend for yt-dlp name: ytdl-web -version: 1.0.5 +version: 1.0.6 kubeVersion: ">=1.22.0-0" type: application -appVersion: 1.0.4 +appVersion: 1.0.5 maintainers: - name: fifitido email: me@fifitido.net diff --git a/charts/ytdl-web/values.yaml b/charts/ytdl-web/values.yaml index 9980e50..8b83a91 100644 --- a/charts/ytdl-web/values.yaml +++ b/charts/ytdl-web/values.yaml @@ -10,7 +10,7 @@ env: # YTDL_ENV: Production # YTDL_BINARY_PATH: yt-dlp YTDL_HTTP_LISTEN: 0.0.0.0 - YTDL_HTTP_PORT: 80 + YTDL_HTTP_PORT: 8080 # YTDL_HTTP_BASEPATH: /example # YTDL_HTTP_TRUSTED_PROXIES: 127.0.0.1 10.0.0.0/8 # YTDL_CACHE_TTL: 1h @@ -22,7 +22,7 @@ service: main: ports: http: - port: 80 + port: 8080 persistence: config: @@ -37,5 +37,3 @@ ingress: paths: - path: / pathType: Prefix - service: - port: http diff --git a/cmd/root.go b/cmd/root.go index 08cf0b5..d5e4b67 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -44,10 +44,10 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $XDG_CONFIG_HOME/ytdl-web/config.yml)") - rootCmd.PersistentFlags().IntP("port", "p", 8080, "port to listen on") - rootCmd.PersistentFlags().StringP("listen", "l", "127.0.0.1", "address to listen on") + rootCmd.PersistentFlags().IntP("port", "p", 0, "port to listen on") + rootCmd.PersistentFlags().StringP("listen", "l", "", "address to listen on") rootCmd.PersistentFlags().StringP("base-path", "b", "", "the base path, used when behind reverse proxy") - rootCmd.PersistentFlags().StringP("ytdlp-path", "y", "yt-dlp", "the path to the yt-dlp binary, used when it is not in $PATH") + rootCmd.PersistentFlags().StringP("ytdlp-path", "y", "", "the path to the yt-dlp binary, used when it is not in $PATH") rootCmd.PersistentFlags().BoolP("cookies-enabled", "C", false, "whether cookies are enabled") rootCmd.PersistentFlags().StringP("cookies", "c", "", "the path to the cookies file") diff --git a/config/config.go b/config/config.go index aef70fa..cd8d3ac 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "strings" "time" "github.com/spf13/viper" @@ -39,9 +40,9 @@ type ConfigCache struct { } type ConfigCookies struct { - Enabled bool `mapstructure:"enabled"` - FilePath string `mapstructure:"filePath"` - FromBrowser *ConfigCookiesFromBrowser `mapstructure:"fromBrowser"` + Enabled bool `mapstructure:"enabled"` + FilePath string `mapstructure:"filePath"` + FromBrowser ConfigCookiesFromBrowser `mapstructure:"fromBrowser"` } type ConfigCookiesFromBrowser struct { @@ -66,7 +67,7 @@ func DefaultConfig() *Config { Cookies: ConfigCookies{ Enabled: false, FilePath: "./cookies.txt", - FromBrowser: nil, + FromBrowser: ConfigCookiesFromBrowser{}, }, } } @@ -75,6 +76,7 @@ func LoadConfig(paths ...string) (*Config, error) { v := viper.New() v.SetEnvPrefix("YTDL") + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) v.AutomaticEnv() v.SetConfigName("config") @@ -92,7 +94,9 @@ func LoadConfig(paths ...string) (*Config, error) { } if err := v.ReadInConfig(); err != nil { - return nil, err + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + return nil, err + } } config := DefaultConfig() diff --git a/ytdl/ytdl.go b/ytdl/ytdl.go index 72c2c62..cd3f2a4 100644 --- a/ytdl/ytdl.go +++ b/ytdl/ytdl.go @@ -37,7 +37,7 @@ func (y *ytdlImpl) baseOptions(url string) []Option { } if y.cfg.Cookies.Enabled { - if y.cfg.Cookies.FromBrowser != nil { + if y.cfg.Cookies.FromBrowser.Browser != "" { options = append(options, WithBrowserCookies( y.cfg.Cookies.FromBrowser.Browser, y.cfg.Cookies.FromBrowser.Keyring,