diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index b03cbe4b..00000000 --- a/.dockerignore +++ /dev/null @@ -1,8 +0,0 @@ -.git/ -assets/ -examples/ - -.dockerignore -config.yaml -Dockerfile -README.md diff --git a/Dockerfile b/Dockerfile index 25346a0b..ffb0aca7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -# https://github.com/hassio-addons/addon-base-python/releases -ARG BASE_VERSION="9.0.1" +# 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.2" +ARG GO_VERSION="1.19.3" # https://hub.docker.com/r/ngrok/ngrok/tags?page=1&name=-alpine ARG NGROK_VERSION="3.1.0" -FROM ghcr.io/hassio-addons/base-python:${BASE_VERSION} AS base +FROM python:${PYTHON_VERSION}-alpine AS base FROM golang:${GO_VERSION}-alpine AS go @@ -20,8 +20,15 @@ FROM go AS build WORKDIR /workspace -COPY . . +# 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 . RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath @@ -30,13 +37,16 @@ FROM scratch AS rootfs COPY --from=build /workspace/go2rtc /usr/local/bin/ COPY --from=ngrok /bin/ngrok /usr/local/bin/ -COPY ./docker/rootfs/ / +COPY ./docker/run.sh /run.sh -# Final stage +# Final image FROM base -# Install ffmpeg -RUN apk add --no-cache ffmpeg +RUN apk add --no-cache bash tini ffmpeg COPY --from=rootfs / / + +ENTRYPOINT ["/sbin/tini", "--"] + +CMD ["/run.sh"] diff --git a/docker/rootfs/etc/services.d/go2rtc/finish b/docker/rootfs/etc/services.d/go2rtc/finish deleted file mode 100755 index f73fe4ba..00000000 --- a/docker/rootfs/etc/services.d/go2rtc/finish +++ /dev/null @@ -1,12 +0,0 @@ -#!/command/with-contenv bashio -# ============================================================================== -# Take down the S6 supervision tree when go2rtc fails -# ============================================================================== -# shellcheck shell=bash - -if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then - bashio::log.warning "go2rtc crashed, halting add-on" - /run/s6/basedir/bin/halt -fi - -bashio::log.info "go2rtc stopped, restarting..." diff --git a/docker/rootfs/etc/services.d/go2rtc/run b/docker/rootfs/etc/services.d/go2rtc/run deleted file mode 100755 index 99fd8fc2..00000000 --- a/docker/rootfs/etc/services.d/go2rtc/run +++ /dev/null @@ -1,23 +0,0 @@ -#!/command/with-contenv bashio -# ============================================================================== -# Runs go2rtc -# ============================================================================== -# shellcheck shell=bash - -bashio::log.info 'Starting go2rtc...' - -declare config_path -declare binary_path - -config_path="/config" - -binary_path="/usr/local/bin/go2rtc" -if [[ -x "${config_path}/go2rtc" ]]; then - binary_path="${config_path}/go2rtc" - bashio::log.warning "Using go2rtc binary from '${binary_path}'" -fi - -# set cwd for go2rtc (for config file, Hass integration, etc) -cd "${config_path}" || bashio::exit.nok "Could not change working directory" - -exec "${binary_path}" diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 00000000..93cbf082 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# ============================================================================== +# Runs go2rtc +# ============================================================================== + +echo 'Starting go2rtc...' >&2 + +readonly config_path="/config" + +if [[ -x "${config_path}/go2rtc" ]]; then + readonly binary_path="${config_path}/go2rtc" + echo "Using go2rtc binary from '${binary_path}' instead of the embedded one" >&2 +else + readonly binary_path="/usr/local/bin/go2rtc" +fi + +# set cwd for go2rtc (for config file, Hass integration, etc) +cd "${config_path}" || echo "Could not change working directory to '${config_path}'" >&2 + +exec "${binary_path}"