2 Commits

Author SHA1 Message Date
williamp 991a5f376f new dockerfile for staged yt-dlp/deno/go builds to distroless container 2026-03-05 22:15:34 -05:00
williamp 13bd3b82db minor UX tweaks 2026-03-05 21:42:56 -05:00
4 changed files with 99 additions and 18 deletions
+84 -6
View File
@@ -1,6 +1,84 @@
FROM python:3.14.2-alpine3.22
COPY ./app /app
WORKDIR /app
RUN apk add ffmpeg deno
RUN pip install -r requirements.txt
CMD ["python", "/app/main.py"]
# Portions of this Dockerfile are sourced from GPLv3 licensed `yt-dlp slim` by Henrique Almeida (https://github.com/h3nc4/yt-dlp-slim)
# Derivations to this Dockerfile in this repository following March 3, 2026 should be considered licensed under this project's MIT license (see ../LICENSE) unless otherwise stated
########################################
# Versions
ARG YT_DLP_VERSION="2026.03.03"
################################################################################
# Deno builder stage
FROM denoland/deno:bin-2.6.6@sha256:9f18d20207f2699595ea26d14e0b7e123cd0cd01100a577bc11f8ca5906c2d81 AS deno-builder
################################################################################
# FFmpeg builder stage
FROM debian:13-slim@sha256:1d3c811171a08a5adaa4a163fbafd96b61b87aa871bbc7aa15431ac275d3d430 AS ffmpeg-builder
RUN apt-get update && \
apt-get install -y --no-install-recommends ffmpeg
RUN mkdir -p /rootfs/bin && \
cp /usr/bin/ffmpeg /usr/bin/ffprobe /rootfs/bin/ && \
ldd /usr/bin/ffmpeg | grep "=> /" | awk '{print $3}' | \
xargs -I '{}' cp --parents '{}' /rootfs && \
cp --parents /lib/x86_64-linux-gnu/libdl.so.2 /rootfs && \
cp --parents /lib/x86_64-linux-gnu/libpthread.so.0 /rootfs && \
cp --parents /lib/x86_64-linux-gnu/libutil.so.1 /rootfs && \
cp --parents /lib/x86_64-linux-gnu/librt.so.1 /rootfs && \
cp --parents /lib64/ld-linux-x86-64.so.2 /rootfs
################################################################################
# YT-DLP builder stage
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS yt-dlp-builder
ARG YT_DLP_VERSION
RUN mkdir -p /rootfs/target /rootfs/tmp /rootfs/bin
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/yt-dlp_linux" /yt-dlp_linux
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS" /SHA2-256SUMS
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS.sig" /SHA2-256SUMS.sig
ADD "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xAC0CBBE6848D6A873464AF4E57CF65933B5A7581" "/yt-dlp_pubkey.asc"
RUN apk add --no-cache gnupg && \
gpg --import /yt-dlp_pubkey.asc && \
gpg --verify /SHA2-256SUMS.sig /SHA2-256SUMS && \
grep " yt-dlp_linux$" /SHA2-256SUMS | sha256sum -c -
RUN mv /yt-dlp_linux /rootfs/bin/yt-dlp && \
chmod 755 /rootfs/bin/yt-dlp && \
chmod 1777 /rootfs/tmp
################################################################################
# App builder stage
FROM golang:1.25.8-trixie@sha256:bc16125656839ffe56154c675f7a9662bec2ef7d4060177239914e7c6d2fd8a8 AS app-builder
COPY app/ /opt/app
WORKDIR /opt/app
RUN go get && go build -o out/yt-dlp-bot
################################################################################
# Final squashed image
FROM scratch AS final
# Copy deno, yt-dlp, and ffmpeg binaries
COPY --from=deno-builder /deno /bin/deno
COPY --from=yt-dlp-builder /rootfs /
COPY --from=ffmpeg-builder /rootfs/ /
# Copy yt-dlp-bot app binary
COPY --from=app-builder /opt/app/out/yt-dlp-bot /bin/
# Copy SSL CA's (needed for Discord)
COPY --from=app-builder /etc/ssl/certs /etc/ssl/certs
WORKDIR /target
ENV XDG_CACHE_HOME=/tmp/.cache
ENV YTDLP_BIN=/bin/yt-dlp
ENTRYPOINT ["/bin/yt-dlp-bot"]
LABEL org.opencontainers.image.title="yt-dlp bot" \
org.opencontainers.image.description="A totally overengineered Discord bot to locally download YouTube videos for private use" \
org.opencontainers.image.authors="William Peebles <me@williamtpeebles.com>" \
org.opencontainers.image.vendor="William Peebles" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://git.dubyatp.xyz/williamp/yt-dlp-bot"
+7 -7
View File
@@ -20,7 +20,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
// Handle panic from DownloadVideo
resultChan <- DownloadResult{
Success: false,
Message: fmt.Sprintf("Download failed: %v", r),
Message: fmt.Sprintf("❌ **Download Failed**: %v", r),
URL: url,
Format: fmt.Sprintf("video: %s, audio: %s", videoFormatID, audioFormatID),
Error: fmt.Errorf("%v", r),
@@ -39,7 +39,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
// If we reach here, download was successful
resultChan <- DownloadResult{
Success: true,
Message: "Video Downloaded Successfully!",
Message: "✅ **Successfully Downloaded**",
URL: url,
Format: fmt.Sprintf("video: %s, audio: %s", videoFormatID, audioFormatID),
Error: nil,
@@ -49,7 +49,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
// Handle progress and results asynchronously
go func() {
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: ptr("<a:loading:1479131733910618153> downloading: starting..."),
Content: ptr(fmt.Sprintf("%s **Starting Download**", loading_emoji)),
})
if err != nil {
log.Printf("Error updating interaction: %v", err)
@@ -65,7 +65,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
var content string
if prog.Phase == "post-processing" {
content = "<a:loading:1479131733910618153> post-processing"
content = fmt.Sprintf("%s **Post Processing**", loading_emoji)
} else {
var progressStr string
if prog.DownloadedBytes > 0 {
@@ -73,7 +73,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
} else {
progressStr = "starting..."
}
content = fmt.Sprintf("<a:loading:1479131733910618153> Downloading Video: %s", progressStr)
content = fmt.Sprintf("%s **Downloading Video**: %s", loading_emoji, progressStr)
}
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
@@ -86,7 +86,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
case result := <-resultChan:
if result.Success {
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: ptr("✅ Success"),
Content: ptr("✅ **Successfully Downloaded**"),
})
_, err = s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{
Content: fmt.Sprintf("## Video Downloaded \n**URL**: %s \n**Quality**: %s + %s \n**Requested By**: <@%s> \n", result.URL, videoFormatName, audioFormatName, requester),
@@ -96,7 +96,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, re
}
} else {
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: ptr("❌ Download failed: " + result.Message),
Content: ptr("❌ **Download Failed**: " + result.Message),
})
if err != nil {
log.Printf("Error updating interaction: %v", err)
+2 -4
View File
@@ -13,7 +13,6 @@ import (
)
func main() {
out_dir := os.Getenv("OUT_PATH")
temp_dir := os.Getenv("TEMP_PATH")
bot_token := os.Getenv("DISCORD_TOKEN")
@@ -273,8 +272,7 @@ func main() {
response := ""
if state.URL != "" {
// Respond immediately to prevent timeout
response = fmt.Sprintf("🚀 Starting download...\nURL: %s\nVideo: %s\nAudio: %s\n\nYou'll receive an update when the download completes!",
state.URL, state.VideoFormatID, state.AudioFormatID)
response = fmt.Sprintf("%s **Starting download**", loading_emoji)
// Start async download after responding
go func() {
@@ -327,7 +325,7 @@ func main() {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "🔍 Fetching available formats...",
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
Flags: discordgo.MessageFlagsEphemeral,
},
})
+6 -1
View File
@@ -1,6 +1,11 @@
package main
import "fmt"
import (
"fmt"
"os"
)
var loading_emoji = os.Getenv("LOADING_EMOJI")
// Helper function to create string pointer
func ptr(s string) *string {