Refactoring CI

This commit is contained in:
Alexey Khit
2022-12-17 23:15:30 +03:00
parent a6057a2eca
commit c1fac66329
3 changed files with 25 additions and 33 deletions

View File

@@ -7,9 +7,6 @@ on:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'
jobs:
build-and-push:

View File

@@ -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"]

5
docker/run.sh → build/docker/run.sh Executable file → Normal file
View File

@@ -1,11 +1,8 @@
#!/bin/bash
# ==============================================================================
# Runs go2rtc
# ==============================================================================
set -euo pipefail
echo 'Starting go2rtc...' >&2
echo "Starting go2rtc..." >&2
readonly config_path="/config"