mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
Refactor docker image
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
||||
.git/
|
||||
assets/
|
||||
examples/
|
||||
|
||||
.dockerignore
|
||||
config.yaml
|
||||
Dockerfile
|
||||
README.md
|
8
.github/workflows/builder.yml
vendored
8
.github/workflows/builder.yml
vendored
@@ -30,22 +30,22 @@ jobs:
|
||||
- name: Build amd64
|
||||
uses: home-assistant/builder@master
|
||||
with:
|
||||
args: --amd64 --target build/hassio --version $TAG-amd64 --no-latest --docker-hub-check
|
||||
args: --amd64 --target . --version $TAG-amd64 --no-latest --docker-hub-check
|
||||
|
||||
- name: Build i386
|
||||
uses: home-assistant/builder@master
|
||||
with:
|
||||
args: --i386 --target build/hassio --version $TAG-i386 --no-latest --docker-hub-check
|
||||
args: --i386 --target . --version $TAG-i386 --no-latest --docker-hub-check
|
||||
|
||||
- name: Build aarch64
|
||||
uses: home-assistant/builder@master
|
||||
with:
|
||||
args: --aarch64 --target build/hassio --version $TAG-aarch64 --no-latest --docker-hub-check
|
||||
args: --aarch64 --target . --version $TAG-aarch64 --no-latest --docker-hub-check
|
||||
|
||||
- name: Build armv7
|
||||
uses: home-assistant/builder@master
|
||||
with:
|
||||
args: --armv7 --target build/hassio --version $TAG-armv7 --no-latest --docker-hub-check
|
||||
args: --armv7 --target . --version $TAG-armv7 --no-latest --docker-hub-check
|
||||
|
||||
- name: Docker manifest
|
||||
run: |
|
||||
|
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
||||
# https://github.com/hassio-addons/addon-base-python/releases
|
||||
ARG BASE_VERSION="9.0.1"
|
||||
# https://hub.docker.com/_/golang/tags?page=1&name=-alpine
|
||||
ARG GO_VERSION="1.19.2"
|
||||
# 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 golang:${GO_VERSION}-alpine AS go
|
||||
|
||||
|
||||
FROM ngrok/ngrok:${NGROK_VERSION}-alpine AS ngrok
|
||||
|
||||
|
||||
# Build go2rtc binary
|
||||
FROM go AS build
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath
|
||||
|
||||
|
||||
# Collect all files
|
||||
FROM scratch AS rootfs
|
||||
|
||||
COPY --from=build /workspace/go2rtc /usr/local/bin/
|
||||
COPY --from=ngrok /bin/ngrok /usr/local/bin/
|
||||
COPY ./docker/rootfs/ /
|
||||
|
||||
|
||||
# Final stage
|
||||
FROM base
|
||||
|
||||
# Install ffmpeg
|
||||
RUN apk add --no-cache ffmpeg
|
||||
|
||||
COPY --from=rootfs / /
|
@@ -1,41 +0,0 @@
|
||||
ARG BUILD_FROM
|
||||
|
||||
FROM $BUILD_FROM as build
|
||||
|
||||
# 1. Build go2rtc
|
||||
RUN apk add --no-cache git go
|
||||
|
||||
RUN git clone https://github.com/AlexxIT/go2rtc \
|
||||
&& cd go2rtc \
|
||||
&& CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath
|
||||
|
||||
# 2. Download ngrok
|
||||
ARG BUILD_ARCH
|
||||
|
||||
# https://github.com/home-assistant/docker-base/blob/master/alpine/Dockerfile
|
||||
RUN if [ "${BUILD_ARCH}" = "aarch64" ]; then BUILD_ARCH="arm64"; \
|
||||
elif [ "${BUILD_ARCH}" = "armv7" ]; then BUILD_ARCH="arm"; fi \
|
||||
&& cd go2rtc \
|
||||
&& curl $(curl -s "https://raw.githubusercontent.com/ngrok/docker-ngrok/main/releases.json" | jq -r ".${BUILD_ARCH}.url") -o ngrok.zip \
|
||||
&& unzip ngrok
|
||||
|
||||
|
||||
|
||||
# https://devopscube.com/reduce-docker-image-size/
|
||||
FROM $BUILD_FROM
|
||||
|
||||
# 3. Copy go2rtc and ngrok to release
|
||||
COPY --from=build /go2rtc/go2rtc /usr/local/bin
|
||||
COPY --from=build /go2rtc/ngrok /usr/local/bin
|
||||
|
||||
# 4. Install ffmpeg
|
||||
# apk base OK: 22 MiB in 40 packages
|
||||
# ffmpeg OK: 113 MiB in 110 packages
|
||||
# python3 OK: 161 MiB in 114 packages
|
||||
RUN apk add --no-cache ffmpeg python3
|
||||
|
||||
# 5. Copy run to release
|
||||
COPY run.sh /
|
||||
RUN chmod a+x /run.sh
|
||||
|
||||
CMD [ "/run.sh" ]
|
@@ -1,14 +0,0 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
set +e
|
||||
|
||||
# set cwd for go2rtc (for config file, Hass integration, etc)
|
||||
cd /config
|
||||
|
||||
# add the feature to override go2rtc binary from Hass config folder
|
||||
export PATH="/config:$PATH"
|
||||
|
||||
while true; do
|
||||
go2rtc
|
||||
sleep 5
|
||||
done
|
12
docker/rootfs/etc/services.d/go2rtc/finish
Executable file
12
docker/rootfs/etc/services.d/go2rtc/finish
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/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..."
|
23
docker/rootfs/etc/services.d/go2rtc/run
Executable file
23
docker/rootfs/etc/services.d/go2rtc/run
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/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}"
|
Reference in New Issue
Block a user