diff --git a/Dockerfile b/.github/ci/Dockerfile similarity index 66% rename from Dockerfile rename to .github/ci/Dockerfile index 4c56d50..490cedc 100644 --- a/Dockerfile +++ b/.github/ci/Dockerfile @@ -5,11 +5,12 @@ FROM ${DOCKER_ARCH}debian:${DEBIAN_VERSION} as build_env # Default packages RUN apt-get -y update && apt-get -y install gnupg2 build-essential xxd cmake ccache git-core pkg-config \ libavformat-dev libavutil-dev libavcodec-dev libssl-dev v4l-utils +RUN apt-get -y install debhelper # Add RPI packages ARG DEBIAN_VERSION -ARG BUILD_TYPE="non-rpi" -RUN [ "$BUILD_TYPE" != "rpi" ] || \ +ARG BUILD_TYPE="generic" +RUN [ "$BUILD_TYPE" != "raspi" ] || \ ( \ echo "deb http://archive.raspberrypi.org/debian/ $DEBIAN_VERSION main" > /etc/apt/sources.list.d/raspi.list && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 82B129927FA3303E && \ @@ -17,12 +18,21 @@ RUN [ "$BUILD_TYPE" != "rpi" ] || \ apt-get -y install libcamera-dev liblivemedia-dev \ ) -FROM scratch as build -COPY --from=build_env / . - +FROM build_env as build ADD / /src WORKDIR /src RUN git clean -ffdx RUN git submodule update --init --recursive --recommend-shallow RUN git submodule foreach --recursive git clean -ffdx -RUN make -j$(nproc) + +FROM build as deb_make +ARG GIT_VERSION +ARG BUILD_TYPE="generic" +ENV DEB_BUILD_PROFILES="$BUILD_TYPE" + +RUN apt-get build-dep -y $PWD +RUN . /etc/os-release && \ + export RELEASE_SUFFIX="$VERSION_CODENAME" && \ + dpkg-buildpackage -us -uc -b + +RUN mkdir -p /deb && mv ../*.deb /deb/ diff --git a/build-env b/.github/ci/build-env similarity index 79% rename from build-env rename to .github/ci/build-env index 7d390db..508bb19 100755 --- a/build-env +++ b/.github/ci/build-env @@ -14,13 +14,14 @@ docker_arch="" [[ -n "$2" ]] && docker_arch="$2/" && docker_image="${docker_image}_${2}" PWD=$(pwd) -ROOT=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +ROOT=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd) set -xeo pipefail docker build -t "$docker_image" \ --build-arg "DOCKER_ARCH=$docker_arch" \ --build-arg "DEBIAN_VERSION=$debian_version" \ - --target build_env - < Dockerfile + --build-arg BUILD_TYPE \ + --target build_env - < .github/ci/Dockerfile exec docker run --rm -it -u "$UID" -v "$ROOT:$ROOT" -w "$ROOT" "$docker_image" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 2b2fb6b..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,26 +0,0 @@ -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - debian_version: [buster, bullseye] - docker_arch: [amd64, arm32v7, arm64v8] - build_type: ["non-rpi", "rpi"] - exclude: - - docker_arch: amd64 - build_type: rpi - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Build Dockerfile - run: docker build --build-arg DOCKER_ARCH --build-arg DEBIAN_VERSION --build-arg BUILD_TYPE . - env: - DEBIAN_VERSION: ${{ matrix.debian_version }} - DOCKER_ARCH: ${{ matrix.docker_arch }}/ - BUILD_TYPE: ${{ matrix.build_type }} diff --git a/.github/workflows/build_release.yaml b/.github/workflows/build_release.yaml new file mode 100644 index 0000000..0d3e69a --- /dev/null +++ b/.github/workflows/build_release.yaml @@ -0,0 +1,61 @@ +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + strategy: + matrix: + debian_version: [bullseye] + docker_arch: [amd64, arm32v7, arm64v8] + build_type: [generic, raspi] + exclude: + - docker_arch: amd64 + build_type: raspi + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + - name: Set GIT_VERSION + shell: bash + run: | + majorVer=$(cat VERSION) + lastVer=$(git tag --sort version:refname --list "v$majorVer.*" | tail -n1) + if [[ -n "$lastVer" ]]; then + newVer=(${lastVer//./ }) + newVer[-1]="$((${newVer[-1]}+1))" + nextVer="${newVer[*]}" + nextVer="${nextVer// /.}" + else + nextVer="$majorVer.0" + fi + echo "MajorVer=$majorVer LastVer=$lastVer NextVer=$nextVer" + echo "GIT_VERSION=$nextVer" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Build Dockerfile + run: docker build --target deb_make --tag deb_make --file .github/ci/Dockerfile --build-arg GIT_VERSION --build-arg DOCKER_ARCH --build-arg DEBIAN_VERSION --build-arg BUILD_TYPE . + env: + DEBIAN_VERSION: ${{ matrix.debian_version }} + DOCKER_ARCH: ${{ matrix.docker_arch }}/ + BUILD_TYPE: ${{ matrix.build_type }} + - name: Create container + run: docker create --name deb_make deb_make + - name: Copy files + run: 'docker cp deb_make:/deb/. deb/' + - name: 'Release debian files' + uses: ncipollo/release-action@v1 + with: + tag: ${{ env.GIT_VERSION }} + artifacts: "deb/*.deb" + allowUpdates: true + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + updateOnlyUnreleased: true + prerelease: true + generateReleaseNotes: true + bodyFile: RELEASE.md diff --git a/.github/workflows/build_test.yaml b/.github/workflows/build_test.yaml new file mode 100644 index 0000000..de5fba1 --- /dev/null +++ b/.github/workflows/build_test.yaml @@ -0,0 +1,44 @@ +on: + push: + paths-ignore: + - '.github/workflows/build_test.yaml' + - 'RELEASE.md' + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + debian_version: [buster, bullseye] + docker_arch: [amd64, arm32v7, arm64v8] + build_type: [generic, raspi] + exclude: + - docker_arch: amd64 + build_type: raspi + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + - name: Set GIT_VERSION + run: echo "GIT_VERSION=$(git describe --tags)" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Build Dockerfile + run: docker build --target deb_make --tag deb_make --file .github/ci/Dockerfile --build-arg GIT_VERSION --build-arg DOCKER_ARCH --build-arg DEBIAN_VERSION --build-arg BUILD_TYPE . + env: + DEBIAN_VERSION: ${{ matrix.debian_version }} + DOCKER_ARCH: ${{ matrix.docker_arch }}/ + BUILD_TYPE: ${{ matrix.build_type }} + - name: Create container + run: docker create --name deb_make deb_make + - name: Copy files + run: docker cp deb_make:/deb/. deb/ + - name: 'Upload debian files' + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.debian_version }}-${{ matrix.docker_arch }}-${{ matrix.build_type }}.zip + path: deb/ + retention-days: 14 diff --git a/.gitignore b/.gitignore index eef4e2f..719c2d0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,10 @@ tmp/ .vscode/ /Procfile* /version.h + +/debian/.debhelper +/debian/debhelper-build-stamp +/debian/*.substvars +/debian/files +/debian/*.log +/debian/camera-streamer*/ diff --git a/Makefile b/Makefile index 03363b6..ed6b107 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ endif LIBDATACHANNEL_PATH ?= third_party/libdatachannel +USE_HW_H264 ?= 1 USE_FFMPEG ?= $(shell pkg-config libavutil libavformat libavcodec && echo 1) USE_LIBCAMERA ?= $(shell pkg-config libcamera && echo 1) USE_RTSP ?= $(shell pkg-config live555 && echo 1) @@ -24,6 +25,10 @@ ifeq (1,$(DEBUG)) CFLAGS += -g endif +ifeq (1,$(USE_HW_H264)) +CFLAGS += -DUSE_HW_H264 +endif + ifeq (1,$(USE_FFMPEG)) CFLAGS += -DUSE_FFMPEG LDLIBS += -lavcodec -lavformat -lavutil @@ -72,7 +77,7 @@ version: $(CCACHE) $(CXX) $(CFLAGS) -o $@ $(filter-out cmd/%, $^) $(filter $ Fri, 26 May 2023 13:15:22 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +10 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..2f40383 --- /dev/null +++ b/debian/control @@ -0,0 +1,37 @@ +Source: camera-streamer +Section: unknown +Priority: optional +Maintainer: Kamil Trzciński +Build-Depends: + debhelper, + libavformat-dev, + libavutil-dev, + libavcodec-dev, + libcamera-dev , + liblivemedia-dev , + v4l-utils, + pkg-config, + xxd, + build-essential, + cmake, + libssl-dev +Standards-Version: 4.5.1 +Homepage: https://github.com/ayufan/camera-streamer +Vcs-Browser: https://github.com/ayufan/camera-streamer +Vcs-Git: https://github.com/ayufan/camera-streamer.git +Rules-Requires-Root: no + +Package: camera-streamer-raspi +Provides: camera-streamer +Build-Profiles: +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: camera-streamer with CSI and USB camera, + RTSP, WebRTC, and H264 support + +Package: camera-streamer-generic +Provides: camera-streamer +Build-Profiles: +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: camera-streamer with USB camera support diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..e5ae475 --- /dev/null +++ b/debian/rules @@ -0,0 +1,62 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + +export USE_FFMPEG ?= 1 +#export GIT_VERSION ?= $(shell git describe --tags) +export DEB_VERSION ?= $(GIT_VERSION:v%=%)$(addprefix ~,$(RELEASE_SUFFIX)) + +ifneq ($(filter raspi,$(DEB_BUILD_PROFILES)),) +export USE_HW_H264 = 1 +export USE_LIBDATACHANNEL = 1 +export USE_LIBCAMERA = 1 +export USE_RTSP = 1 +else ifneq ($(filter generic,$(DEB_BUILD_PROFILES)),) +export USE_HW_H264 = 0 +export USE_LIBCAMERA = 0 +else +$(error Use DEB_BUILD_PROFILES=raspi or DEB_BUILD_PROFILES=generic) +endif + +%: + dh $@ + +.PHONY: override_dh_auto_install +override_dh_auto_install: + +.PHONY: override_dh_gencontrol +override_dh_gencontrol: + dh_gencontrol -- $(addprefix -v,$(DEB_VERSION)) + +.PHONY: override_dh_strip +override_dh_strip: + dh_strip --keep-debug + +.PHONY: override_dh_shlibdeps +override_dh_shlibdeps: + dh_shlibdeps + + # Make libcamera0 to be exact + sed -i "s/libcamera0 (>=[^)]*)/libcamera0 (= $$(dpkg -s libcamera0 | grep Version | cut -d" " -f2))/g" debian/camera-streamer*.substvars + +.PHONY: override_dh_install +override_dh_install: + dh_install + sed -i "s|/usr/local/bin/camera-streamer|/usr/bin/camera-streamer|g" debian/camera-streamer*/usr/share/camera-streamer/examples/*.service + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- \ +# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native)