diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5837a..cbf497f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Show version in web UI - Fixes and improvements to capturing output info and showing it in the UI - Improve index page (show URL of queued downloads instead of nothing) +- Add docker support ## [v0.5.5] - 2022-04-09 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9fd5af1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# Start from golang base image +FROM golang:1.18.2-alpine3.15 as builder + +# Install git. (alpine image does not have git in it) +RUN apk update && apk add --no-cache git curl + +# Set current working directory +WORKDIR /app + +RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /app/yt-dlp +RUN chmod a+x /app/yt-dlp + +# Note here: To avoid downloading dependencies every time we +# build image. Here, we are caching all the dependencies by +# first copying go.mod and go.sum files and downloading them, +# to be used every time we build the image if the dependencies +# are not changed. + +# Copy go mod and sum files +COPY go.mod ./ +COPY go.sum ./ + +# Download all dependencies. +RUN go mod download + +# Now, copy the source code +COPY . . + +# Note here: CGO_ENABLED is disabled for cross system compilation +# It is also a common best practise. + +# Build the application. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/gropple . + +# Finally our multi-stage to build a small image +# Start a new stage from scratch +FROM alpine:3.15.4 + +# Copy the Pre-built binary file +COPY --from=builder /app/bin/gropple . +COPY --from=builder /app/yt-dlp /bin/ + +# Install things we need to support yt-dlp +RUN apk update && apk add --no-cache python3 ffmpeg + +# Run executable +CMD ["./gropple", "--config-path", "/config/gropple.json"] diff --git a/config/config.go b/config/config.go index 137b7f4..c9cb663 100644 --- a/config/config.go +++ b/config/config.go @@ -61,13 +61,13 @@ func (cs *ConfigService) LoadTestConfig() { func (cs *ConfigService) LoadDefaultConfig() { defaultConfig := Config{} - stdProfile := DownloadProfile{Name: "standard video", Command: "youtube-dl", Args: []string{ + stdProfile := DownloadProfile{Name: "standard video", Command: "yt-dlp", Args: []string{ "--newline", "--write-info-json", "-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best", }} - mp3Profile := DownloadProfile{Name: "standard mp3", Command: "youtube-dl", Args: []string{ + mp3Profile := DownloadProfile{Name: "standard mp3", Command: "yt-dlp", Args: []string{ "--newline", "--write-info-json", "--extract-audio", @@ -79,7 +79,7 @@ func (cs *ConfigService) LoadDefaultConfig() { defaultConfig.Server.Port = 6123 defaultConfig.Server.Address = "http://localhost:6123" - defaultConfig.Server.DownloadPath = "./" + defaultConfig.Server.DownloadPath = "/downloads" defaultConfig.UI.PopupWidth = 500 defaultConfig.UI.PopupHeight = 500 diff --git a/main.go b/main.go index 2023764..a4c6655 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "embed" "encoding/json" + "flag" "fmt" "html/template" "io" @@ -43,8 +44,17 @@ type errorResponse struct { func main() { log.Printf("Starting gropple %s - https://github.com/tardisx/gropple", versionInfo.GetInfo().CurrentVersion) + var configPath string + flag.StringVar(&configPath, "config-path", "", "path to config file") + flag.Parse() + configService = &config.ConfigService{} - configService.DetermineConfigDir() + if configPath != "" { + configService.ConfigPath = configPath + } else { + configService.DetermineConfigDir() + } + exists, err := configService.ConfigFileExists() if err != nil { log.Fatal(err)