Skip to content

Commit

Permalink
Merge pull request #12 from games-on-whales/docker
Browse files Browse the repository at this point in the history
Docker build
  • Loading branch information
ABeltramo authored Jan 30, 2023
2 parents f8e2c4b + 69a9f92 commit f79fb94
Show file tree
Hide file tree
Showing 49 changed files with 1,780 additions and 844 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Start by removing everything and add just the things we need
*

!src
!cmake
!CMakeLists.txt
!.clang-format
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
time: "00:00"
target-branch: "nightly"
open-pull-requests-limit: 10

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "00:00"
target-branch: "nightly"
open-pull-requests-limit: 10
118 changes: 118 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Docker build

on:
push:
# TODO: enable workflow_run when merged into master
# workflow_run:
# workflows: [ "Linux build and test" ]
# types:
# - completed

jobs:
buildx:
# Only run this when tests are passing, see: https://github.com/orgs/community/discussions/26238
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# Set derived configuration variables:
# - images: images to build (docker and/or github)
# - push: if images need to be uploaded to repository (when secrets available)
# - has_docker_token
# - has_github_token
# - cache_from: image tag to use for imported cache
# - cache_to: image tag to use for exported cache
# - github_server_url: reference to source code repository
- name: Prepare
id: prep
run: |
IMAGES=""
PUSH=false
if [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
IMAGES="gameonwhales/wolf"
PUSH=true
echo "has_docker_token=true" >> $GITHUB_OUTPUT
fi
if [ -n "${{ secrets.GHCR_TOKEN }}" ]; then
REGISTRY_IMAGE="ghcr.io/${{ github.repository_owner }}/wolf"
if [ "$IMAGES" = "" ]; then
IMAGES="ghcr.io/${REGISTRY_IMAGE}"
else
IMAGES="$IMAGES,ghcr.io/${REGISTRY_IMAGE}"
fi
PUSH=true
echo "has_github_token=true" >> $GITHUB_OUTPUT
echo "cache_from=type=registry,ref=${REGISTRY_IMAGE}:buildcache" >> $GITHUB_OUTPUT
echo "cache_to=type=registry,ref=${REGISTRY_IMAGE}:buildcache,mode=max" >> $GITHUB_OUTPUT
else
echo "cache_from=type=registry,ref=${REGISTRY_IMAGE}:buildcache" >> $GITHUB_OUTPUT
echo "cache_to=" >> $GITHUB_OUTPUT
fi
echo "images=${IMAGES}" >> $GITHUB_OUTPUT
echo "push=${PUSH}" >> $GITHUB_OUTPUT
echo "github_server_url=${GITHUB_SERVER_URL}" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: ${{ steps.prep.outputs.images }}
# generate Docker tags based on the following events/attributes
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=edge,branch=master
type=ref,event=branch
type=raw,value=alpha
type=sha
flavor: latest=false # let's not produce a :latest tag

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
version: latest
driver-opts: image=moby/buildkit:master

- name: Login to DockerHub
if: steps.prep.outputs.has_docker_token != '' # secrets not available in PRs
uses: docker/login-action@v2
with:
username: abeltramo
password: ${{ secrets.DOCKERHUB_TOKEN }}


- name: Login to GitHub Container Registry
if: steps.prep.outputs.has_github_token != '' # secrets not available in PRs
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build Gstreamer
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: docker
file: docker/gstreamer.Dockerfile
push: true
tags: ghcr.io/${{ github.repository_owner }}/gstreamer:1.20.3,gameonwhales/gstreamer:1.20.3 # TODO: set gstreamer version as param
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/gstreamer:buildcache-1.20.3
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/gstreamer:buildcache-1.20.3,mode=max

- name: Build Wolf
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: Dockerfile
push: ${{ steps.prep.outputs.push }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
IMAGE_SOURCE=${{ steps.prep.outputs.github_server_url }}/${{ github.repository }}
cache-from: ${{ steps.prep.outputs.cache_from }}
cache-to: ${{ steps.prep.outputs.cache_to }}
3 changes: 0 additions & 3 deletions .github/workflows/linux-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on: [ push, pull_request ]

jobs:
build:
name: ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
Expand All @@ -30,8 +29,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Prepare environment
# ubuntu-latest breaks without libunwind-dev,
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/mirror-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Pushes the contents of the repo to the Codeberg mirror
name: Repo Mirror
on: [ push ]
jobs:
codeberg:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pixta-dev/repository-mirroring-action@v1
with:
target_repo_url: "[email protected]:games-on-whales/wolf.git"
ssh_private_key: ${{ secrets.CODEBERG_SSH }}
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

# Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)

# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(BUILD_SHARED_LIBS ON)
option(BUILD_SHARED_LIBS "Build libs as shared" ON)
# set(Boost_USE_STATIC_LIBS ON)

# Testing only available if this is the main app
Expand Down
123 changes: 123 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
########################################################
FROM ubuntu:22.04 AS wolf-builder

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
ca-certificates \
ninja-build \
cmake \
ccache \
git \
clang \
libboost-thread-dev libboost-filesystem-dev libboost-log-dev libboost-stacktrace-dev \
libssl-dev \
libgstreamer1.0-dev \
libevdev-dev \
libunwind-dev \
&& rm -rf /var/lib/apt/lists/*

COPY src /wolf/src
COPY cmake /wolf/cmake
COPY CMakeLists.txt /wolf/CMakeLists.txt
WORKDIR /wolf

# TODO: link with gstreamer from gameonwhales/gstreamer:1.20.3

ENV CCACHE_DIR=/cache/ccache
ENV CMAKE_BUILD_DIR=/cache/cmake-build
RUN --mount=type=cache,target=/cache/ccache \
--mount=type=cache,target=/cache/cmake-build \
cmake -B$CMAKE_BUILD_DIR \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_EXTENSIONS=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DBoost_USE_STATIC_LIBS=ON \
-DBUILD_TESTING=OFF \
-G Ninja && \
ninja -C $CMAKE_BUILD_DIR && \
# We have to copy out the built executable because this will only be available inside the buildkit cache
cp $CMAKE_BUILD_DIR/src/wolf/wolf /wolf/wolf

########################################################
FROM rust:1.66-slim AS gst-plugin-wayland

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
git ca-certificates pkg-config \
libwayland-dev libwayland-server0 libudev-dev libinput-dev libxkbcommon-dev libgbm-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
&& rm -rf /var/lib/apt/lists/*

ARG SUNRISE_SHA=eb5b07d79c42a69e700ca5666ce1710f9c8f4ef0
ENV SUNRISE_SHA=$SUNRISE_SHA
RUN git clone https://github.com/Drakulix/sunrise.git && \
cd sunrise && \
git checkout $SUNRISE_SHA

WORKDIR /sunrise/gst-plugin-wayland-display

RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release


########################################################
FROM gameonwhales/gstreamer:1.20.3 AS runner
ENV DEBIAN_FRONTEND=noninteractive

# Wolf runtime dependencies
# curl only used by plugin curlhttpsrc (remote video play)
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
ca-certificates libcurl4 \
tini \
libssl3 \
libevdev2 \
va-driver-all \
&& rm -rf /var/lib/apt/lists/*

# gst-plugin-wayland runtime dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
libwayland-server0 libinput10 libxkbcommon0 libgbm1 \
libglvnd0 libgl1 libglx0 libegl1 libgles2 \
&& rm -rf /var/lib/apt/lists/*

# TODO: avoid running as root

COPY --from=wolf-builder /wolf/wolf /wolf/wolf
COPY --from=gst-plugin-wayland /sunrise/gst-plugin-wayland-display/target/release/libgstwaylanddisplay.so $GST_PLUGIN_PATH/libgstwaylanddisplay.so

# Here is where the dinamically created wayland sockets will be stored
ENV XDG_RUNTIME_DIR=/wolf/run/
RUN mkdir $XDG_RUNTIME_DIR

WORKDIR /wolf

ARG WOLF_CFG_FOLDER=/wolf/cfg
ENV WOLF_CFG_FOLDER=$WOLF_CFG_FOLDER
RUN mkdir $WOLF_CFG_FOLDER

ENV LOG_LEVEL=INFO
ENV CFG_FILE=$WOLF_CFG_FOLDER/config.toml
ENV PRIVATE_KEY_FILE=$WOLF_CFG_FOLDER/key.pem
ENV PRIVATE_CERT_FILE=$WOLF_CFG_FOLDER/cert.pem
VOLUME $WOLF_CFG_FOLDER

# HTTPS
EXPOSE 47984/tcp
# HTTP
EXPOSE 47989/tcp
# Video
EXPOSE 47998/udp
# Control
EXPOSE 47999/udp
# Audio
EXPOSE 48000/udp
# RTSP
EXPOSE 48010/tcp

ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/wolf/wolf"]
2 changes: 2 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Start by removing everything and add just the things we need
*
Loading

0 comments on commit f79fb94

Please sign in to comment.