Skip to content

Commit

Permalink
fix publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored May 12, 2023
1 parent fb72e7f commit 2ccc3df
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Linting
on: [pull_request]

jobs:
lint:
if: "!contains(github.event.pull_request.title, 'WIP!')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Install Dependencies
run: npm ci
- name: Run Eslint
run: npm run lint
104 changes: 104 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build image and push to Docker Hub

on:
release:
types: [released]

jobs:
upload_artifacts:
name: Upload artifacts to release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Upload docker-compose.yml
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./docker-compose.yml
asset_name: docker-compose.yml
asset_content_type: text/plain

push_dockerhub:
name: Push image to Docker Hub
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Repo metadata
- name: Repo metadata
id: repo
uses: actions/github-script@v3
with:
script: |
const repo = await github.repos.get(context.repo)
return repo.data
# Prepare variables
- name: Prepare
id: prep
run: |
REG=ghcr.io
IMAGE=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
DOCKER_IMAGE=${REG}/${IMAGE}
VERSION=nool
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=latest
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
# Set up Buildx env
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build image and push to registry
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }}
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).html_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}
#

#
169 changes: 169 additions & 0 deletions src/plugins/plugin_barker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import {
IAssetManager,
IChannelManager,
VodRequest,
VodResponse,
Channel,
ChannelProfile,
IStreamSwitchManager,
Schedule
} from 'eyevinn-channel-engine';
import { ScheduleStreamType } from 'eyevinn-channel-engine/dist/engine/server';
import fetch from 'node-fetch';
import { BasePlugin, PluginInterface } from './interface';

import {
generateId,
getDefaultChannelAudioProfile,
getDefaultChannelVideoProfile
} from './utils';

class BarkerAssetManager implements IAssetManager {
private fallbackVodToLoop: URL;

constructor(fallbackVodToLoop: URL) {
this.fallbackVodToLoop = fallbackVodToLoop;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getNextVod(vodRequest: VodRequest): Promise<VodResponse> {
const vodResponse = {
id: 'loop',
title: 'VOD on Loop',
uri: this.fallbackVodToLoop.toString()
};
return vodResponse;
}
}

class BarkerChannelManager implements IChannelManager {
private channelId: string;
private useDemuxedAudio: boolean;

constructor(channelId: string, useDemuxedAudio = false) {
this.channelId = channelId;
this.useDemuxedAudio = useDemuxedAudio;
console.log(
`Barker channel available at /channels/${this.channelId}/master.m3u8`
);
}

getChannels(): Channel[] {
const channel: Channel = {
id: this.channelId,
profile: this._getProfile()
};
if (this.useDemuxedAudio) {
channel.audioTracks = getDefaultChannelAudioProfile();
}
const channelList = [channel];
return channelList;
}

_getProfile(): ChannelProfile[] {
return getDefaultChannelVideoProfile();
}
}

class BarkerStreamSwitchManager implements IStreamSwitchManager {
private schedule: Schedule[] = [];
private liveStreams: URL[] = [];
private startOffset = -1;
private liveStreamListUrl: URL;
private switchIntervalMs: number = 60 * 1000;

constructor(liveStreamListUrl: URL, switchIntervalMs?: number) {
this.liveStreamListUrl = liveStreamListUrl;
if (switchIntervalMs) {
this.switchIntervalMs = switchIntervalMs;
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getSchedule(channelId: string): Promise<Schedule[]> {
if (this.liveStreams.length === 0) {
console.log(
'Fetching live stream list from ' + this.liveStreamListUrl.toString()
);
const response = await fetch(this.liveStreamListUrl.toString());
if (response.ok) {
const body = await response.text();
this.liveStreams = body
.split(/\r?\n/)
.filter((l) => l !== '')
.map((l) => new URL(l.trim()));
}
}

const streamDuration = this.switchIntervalMs;
const tsNow = Date.now();
if (this.startOffset === -1) {
this.startOffset = tsNow;
}

this.schedule = this.schedule.filter((obj) => obj.end_time >= tsNow);
if (this.schedule.length === 0) {
this.schedule.push({
eventId: generateId(),
assetId: generateId(),
title: 'Live source A',
type: ScheduleStreamType.LIVE,
start_time: this.startOffset,
end_time: this.startOffset + streamDuration,
uri: this.liveStreams[
Math.floor(Math.random() * this.liveStreams.length)
].toString()
});
this.startOffset += streamDuration;
this.schedule.push({
eventId: generateId(),
assetId: generateId(),
title: 'Live source B',
type: ScheduleStreamType.LIVE,
start_time: this.startOffset,
end_time: this.startOffset + streamDuration,
uri: this.liveStreams[
Math.floor(Math.random() * this.liveStreams.length)
].toString()
});
this.startOffset += streamDuration;
}
return this.schedule;
}
}

export class BarkerPlugin extends BasePlugin implements PluginInterface {
constructor() {
super('Barker');
}

newAssetManager(): IAssetManager {
const vodToLoop = new URL(
'https://lab.cdn.eyevinn.technology/sto-slate.mp4/manifest.m3u8'
);
return new BarkerAssetManager(vodToLoop);
}

newChannelManager(useDemuxedAudio: boolean): IChannelManager {
return new BarkerChannelManager(
process.env.BARKER_CHANNEL_NAME
? process.env.BARKER_CHANNEL_NAME
: 'barker',
useDemuxedAudio
);
}

newStreamSwitchManager(): IStreamSwitchManager {
const liveStreamListUrl = process.env.BARKERLIST_URL
? process.env.BARKERLIST_URL
: 'https://testcontent.eyevinn.technology/fast/barkertest.txt';
const switchIntervalMs = process.env.SWITCH_INTERVAL_SEC
? parseInt(process.env.SWITCH_INTERVAL_SEC) * 1000
: undefined;

return new BarkerStreamSwitchManager(
new URL(liveStreamListUrl),
switchIntervalMs
);
}
}
Loading

0 comments on commit 2ccc3df

Please sign in to comment.