Skip to content

Commit

Permalink
feat: Python3.11+Poetry on EL9
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Jul 2, 2023
1 parent 5c1d7ba commit c3e09df
Show file tree
Hide file tree
Showing 31 changed files with 2,261 additions and 260 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.eggs/
dist/
.mypy_cache/
venv/
26 changes: 6 additions & 20 deletions .github/workflows/lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@ on:
- main
- gh-pages
pull_request:
branches:
- main

jobs:
call-workflow:
uses: radiorabe/actions/.github/workflows/test-pre-commit.yaml@main
pre-commit:
uses: radiorabe/actions/.github/workflows/[email protected]
test-python-poetry:
uses: radiorabe/actions/.github/workflows/[email protected]
with:
requirements: black isort flake8
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.x', '3.9' ]
name: Test python ${{ matrix.python-version }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- run: pip install -r requirements-dev.txt

- run: pytest --cov-fail-under=100
34 changes: 0 additions & 34 deletions .github/workflows/pypi.yaml

This file was deleted.

86 changes: 17 additions & 69 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,74 +1,22 @@
name: Publish Container Images
name: Release

on:
push:
tags:
- 'v*.*.*'
pull_request:
push:
branches: [main]
release:
types: [created]

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3

- name: Prepare additional Metadata
id: addtional_meta
run: |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Prepare Image Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/radiorabe/nowplaying
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
name=${{ github.event.repository.name }}
summary=${{ github.event.repository.description }}
description=The RaBe nowplaying daemon is used to send ticker information for several broadcast vectors.
url=${{ github.event.repository.html_url }}
vcs-ref=${{ github.sha }}
revision=${{ github.sha }}
release=${{ github.sha }}
build-date=${{ steps.addtional_meta.outputs.created }}
io.k8s.display-name=${{ github.event.repository.name }}
io.k8s.description=${{ github.event.repository.description }}
io.openshift.tags=minimal rhel8 rabe python nowplaying
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
version=${{ steps.meta.outputs.version }}
release-container:
uses: radiorabe/actions/.github/workflows/[email protected]
with:
image: 'ghcr.io/radiorabe/nowplaying'
name: nowplaying
display-name: RaBe nowplaying daemon.
tags: minimal rhel9 rabe python nowplaying

python-poetry:
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
RABE_PYPI_TOKEN: ${{ secrets.RABE_PYPI_TOKEN }}
12 changes: 12 additions & 0 deletions .github/workflows/schedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Scheduled tasks

on:
schedule:
- cron: '13 12 * * *'
workflow_dispatch:

jobs:
schedule-trivy:
uses: radiorabe/actions/.github/workflows/[email protected]
with:
image-ref: 'ghcr.io/radiorabe/nowplaying:latest'
21 changes: 5 additions & 16 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
name: Run semantic-release
name: Semantic Release

on:
push:
branches:
- main
- master
- develop
- release/*

jobs:
semantic-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run go-semantic-release
id: semrel
uses: go-semantic-release/action@v1
with:
github-token: ${{ secrets.RABE_ITREAKTION_GITHUB_TOKEN }}
allow-initial-development-versions: true
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
RABE_ITREAKTION_GITHUB_TOKEN: ${{ secrets.RABE_ITREAKTION_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
dist/
*.egg-info/
htmlcov/
venv/
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ repos:
hooks:
- id: pyupgrade
args:
- --py39-plus
- --py311-plus
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.275"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: local
hooks:
- id: black
name: black
language: system
entry: black
types: [python]
- id: isort
name: isort
language: system
entry: isort
types: [python]
- id: flake8
name: flake8
- id: black
name: black
language: system
entry: flake8
entry: black
types: [python]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
Expand Down
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
FROM ghcr.io/radiorabe/s2i-python:1.1.0 AS build
FROM ghcr.io/radiorabe/s2i-python:2.0.0 AS build

COPY ./ /opt/app-root/src

RUN python3 setup.py bdist_wheel
RUN python -mbuild


FROM ghcr.io/radiorabe/python-minimal:1.0.3 AS app
FROM ghcr.io/radiorabe/python-minimal:2.0.0 AS app

COPY --from=build /opt/app-root/src/dist/*.whl /tmp/dist/

# update pip first because --use-feature=2020-resolver is now default (and needed so otel doesn't pull protobuf>3)
RUN python3 -mpip --no-cache-dir install --upgrade pip \
&& python3 -mpip --no-cache-dir install /tmp/dist/*.whl \
&& python3 -mpip --no-cache-dir uninstall --yes pip \
RUN microdnf install -y \
python3.11-pip \
&& python -mpip --no-cache-dir install /tmp/dist/*.whl \
&& microdnf remove -y \
python3.11-pip \
python3.11-setuptools \
&& microdnf clean all \
&& rm -rf /tmp/dist/

# update pip first because --use-feature=2020-resolver is now default (and needed so otel doesn't pull protobuf>3)
#RUN python3 -mpip --no-cache-dir install --upgrade pip \
# && python3 -mpip --no-cache-dir install /tmp/dist/*.whl \
# && python3 -mpip --no-cache-dir uninstall --yes pip \
# && rm -rf /tmp/dist/

# make requests use os ca certs that contain the RaBe root CA
ENV REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

Expand Down
3 changes: 2 additions & 1 deletion nowplaying/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
This module is the entrypoint for the nowplaying module.
You can run it via `python3 -mnowplaying` or after installation using the `nowplaying` command.
You can run it via `python3 -mnowplaying` or after installation using the
`nowplaying` command.
"""
from .main import NowPlaying

Expand Down
5 changes: 3 additions & 2 deletions nowplaying/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class NowPlayingDaemon:
"""The daemon part of the nowplaying app runs at all time and coordinates the input and output."""
"""The daemon of nowplaying runs at all time and coordinates the i/o."""

"""initialize last_input to a know value."""
last_input = 1
Expand Down Expand Up @@ -106,7 +106,8 @@ def get_track_handler(self): # pragma: no cover
[
handler.register_observer(
IcecastTrackObserver(
# TODO v3 remove uername and password because we mandate specifying via url
# TODO v3 remove uername and password
# because we mandate specifying via url
options=IcecastTrackObserver.Options(
url=url,
username="source",
Expand Down
22 changes: 14 additions & 8 deletions nowplaying/input/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ def event(self, event: CloudEvent): # pragma: no coverage


class KlangbeckenInputObserver(InputObserver):
"""Observe cases where Sämu Box says Klangbecken is running and we can consume now-playing.xml input."""
"""Observe when Sämu Box says Klangbecken we have now-playing.xml input."""

def __init__(
self, current_show_url: str, input_file: str = None
): # pragma: no coverage
# TODO test once input file is replaced with api
if input_file:
warnings.warn(
"The now-playing.xml format from Loopy/Klangbecken will be replaced in the future",
"The now-playing.xml format from Loopy/Klangbecken "
"will be replaced in the future",
PendingDeprecationWarning,
)
self.input_file = input_file
Expand All @@ -84,7 +85,8 @@ def __init__(
super().__init__(current_show_url)

def handles(self, event: CloudEvent) -> bool:
# TODO v3-prep call :meth:`handle_id` from here (needs saemubox_id compat workaround)
# TODO v3-prep call :meth:`handle_id` from here
# needs saemubox_id compat workaround
# TODO v3 remove call to :meth:`handle_id`
# TODO make magic string configurable
# TODO check if source is currently on-air
Expand All @@ -110,8 +112,10 @@ def handle(self, event: CloudEvent = None):
def _handle(self, event: CloudEvent = None):
"""Handle actual RaBe CloudEevent.
TODO v3: move into :meth:`event` once :meth:`handle` and :meth:`handle_id` have been yeeted
TODO v3: remove all refs to input_file and it's modify time once we use event handlers
TODO v3: move into :meth:`event`
once :meth:`handle` and :meth:`handle_id` have been yeeted
TODO v3: remove all refs to input_file and it's modify time
once we use event handlers
"""
if not event:
# @TODO: replace the stat method with inotify
Expand All @@ -136,7 +140,8 @@ def _handle(self, event: CloudEvent = None):
logger.info("First run: %s" % self.first_run)

if not self.first_run: # pragma: no coverage
# TODO test once i don't have to care about mtime/inotify because it's an api
# TODO test once we don't have to care about
# mtime/inotify because it's an api
logger.info("calling track_finished")
self.track_handler.track_finished(self.track)

Expand Down Expand Up @@ -256,7 +261,7 @@ def parse_event(self, event: CloudEvent) -> Track:


class NonKlangbeckenInputObserver(InputObserver):
"""Observer for input that doesn't originate from klangbecken and therefore misses the track information.
"""Observer for input not from klangbecken ie. w/o track information.
Uses the show's name instead of the actual track infos
"""
Expand All @@ -265,7 +270,8 @@ def handles(self, event: CloudEvent) -> bool: # pragma: no coverage
"""Do not handle events yet.
TODO implement this method
TODO v3-prep call :meth:`handle_id` from here (needs saemubox_id compat workaround)
TODO v3-prep call :meth:`handle_id` from here
(needs saemubox_id compat workaround)
TODO v3 remove call to :meth:`handle_id`:
"""
return False
Expand Down
5 changes: 4 additions & 1 deletion nowplaying/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def __init__(self):
self.__args.add_argument(
"--input-file",
dest="inputFile",
help="XML 'now-playing' input file location, may be disabled by passing an empty string, ie. --input-file=''",
help=(
"XML 'now-playing' input file location, "
"disable input by passing empty string, ie. --input-file=''"
),
default="/home/endlosplayer/Eingang/now-playing.xml",
)
self.__args.add_argument(
Expand Down
Loading

0 comments on commit c3e09df

Please sign in to comment.