diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de602701..461f6c13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,9 +7,6 @@ on: - 'master' tags: - 'v*' - pull_request: - branches: - - 'master' jobs: build-and-push: diff --git a/Dockerfile b/Dockerfile index aa148243..02e1ada1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,57 +1,55 @@ -# https://hub.docker.com/_/python/tags?page=1&name=-alpine -ARG PYTHON_VERSION="3.10.8" -# https://hub.docker.com/_/golang/tags?page=1&name=-alpine -ARG GO_VERSION="1.19.3" -# https://hub.docker.com/r/ngrok/ngrok/tags?page=1&name=-alpine -ARG NGROK_VERSION="3.1.0" - +# 0. Prepare images +ARG PYTHON_VERSION="3.11" +ARG GO_VERSION="1.19" +ARG NGROK_VERSION="3" FROM python:${PYTHON_VERSION}-alpine AS base - - FROM golang:${GO_VERSION}-alpine AS go - - FROM ngrok/ngrok:${NGROK_VERSION}-alpine AS ngrok -# Build go2rtc binary +# 1. Build go2rtc binary FROM go AS build -WORKDIR /workspace +WORKDIR /build # Cache dependencies COPY go.mod go.sum ./ RUN go mod download -# Build binary -COPY cmd cmd -COPY pkg pkg -COPY www www -COPY main.go . +COPY . . RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -RUN mkdir -p /config -# Collect all files +# 2. Collect all files FROM scratch AS rootfs -COPY --from=build /workspace/go2rtc /usr/local/bin/ -# Ensure an empty /config folder exists so that the container can be run without a volume -COPY --from=build /config /config +COPY --from=build /build/go2rtc /usr/local/bin/ COPY --from=ngrok /bin/ngrok /usr/local/bin/ -COPY ./docker/run.sh /run.sh +COPY ./build/docker/run.sh / -# Final image +# 3. Final image FROM base # Install ffmpeg, bash (for run.sh), tini (for signal handling), # and other common tools for the echo source. -RUN apk add --no-cache ffmpeg bash tini curl jq +RUN apk add --no-cache tini ffmpeg bash curl jq + +# Hardware Acceleration for Intel CPU (+50MB) +ARG TARGETARCH + +RUN if [ "${TARGETARCH}" = "amd64" ]; then apk add --no-cache libva-intel-driver intel-media-driver; fi + +# Hardware: AMD and NVidia VAAPI (not sure about this) +# RUN libva-glx mesa-va-gallium +# Hardware: AMD and NVidia VDPAU (not sure about this) +# RUN libva-vdpau-driver mesa-vdpau-gallium (+150MB total) COPY --from=rootfs / / +RUN chmod a+x /run.sh && mkdir -p /config + ENTRYPOINT ["/sbin/tini", "--"] CMD ["/run.sh"] diff --git a/docker/run.sh b/build/docker/run.sh old mode 100755 new mode 100644 similarity index 69% rename from docker/run.sh rename to build/docker/run.sh index f9211d17..ca544747 --- a/docker/run.sh +++ b/build/docker/run.sh @@ -1,11 +1,8 @@ #!/bin/bash -# ============================================================================== -# Runs go2rtc -# ============================================================================== set -euo pipefail -echo 'Starting go2rtc...' >&2 +echo "Starting go2rtc..." >&2 readonly config_path="/config"