Skip to content

Commit

Permalink
feat: init acrloader
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed May 19, 2023
0 parents commit b479fdc
Show file tree
Hide file tree
Showing 27 changed files with 2,254 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv
acrloader.conf
.coverage
__pycache__/
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: pip
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
64 changes: 64 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
tags:
- 'v*.*.*'
pull_request:

jobs:
python-poetry:
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
RABE_PYPI_TOKEN: ${{ secrets.RABE_PYPI_TOKEN }}
release-container:
uses: radiorabe/actions/.github/workflows/[email protected]
needs:
- python-poetry
with:
image: 'ghcr.io/radiorabe/acrloader'
name: 'acrloader'
display-name: 'RaBe ACR Loader'
tags: 'minimal rhel9 rabe s2i python python311 acr owncloud'
helm-chart:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs:
- release-container
permissions:
actions: none
checks: none
contents: none
deployments: none
issues: none
packages: write
pull-requests: none
repository-projects: none
security-events: none
statuses: none
id-token: none
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare Chart Metadata
id: meta
run: echo version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT

- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.12.0

- name: Package Chart
run: helm package --version ${{ steps.meta.outputs.version }} --app-version ${{ steps.meta.outputs.version }} --destination=dist charts/acrloader

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

- name: Push Chart
run: helm push dist/*.tgz oci://ghcr.io/radiorabe/helm
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:
call-workflow:
uses: radiorabe/actions/.github/workflows/[email protected]
with:
image-ref: 'ghcr.io/radiorabe/acrloader:latest'
13 changes: 13 additions & 0 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Semantic Release

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

jobs:
semantic-release:
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
RABE_ITREAKTION_GITHUB_TOKEN: ${{ secrets.RABE_ITREAKTION_GITHUB_TOKEN }}
59 changes: 59 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test

on:
pull_request:

jobs:
pre-commit:
uses: radiorabe/actions/.github/workflows/[email protected]
python-poetry:
uses: radiorabe/actions/.github/workflows/[email protected]
with:
version: '3.11'
helm-chart:
name: Test Helm Chart
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build dev image
run: |
docker build -t ghcr.io/radiorabe/acrloader:latest -f Dockerfile .
docker save -o /tmp/acrloader.tar ghcr.io/radiorabe/acrloader:latest
- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.12.0

- uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct --config=.github/ct.yaml list-changed)
if [[ -n "$changed" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run chart-testing (lint)
run: ct --config=.github/ct.yaml lint

- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'

- name: Load dev image
run: |
kind load image-archive /tmp/acrloader.tar --name chart-testing
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: ct --config=.github/ct.yaml install
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv
acrloader.conf
.coverage
__pycache__/
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args:
- --py311-plus
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.269"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: local
hooks:
- id: black
name: black
language: system
entry: black
types: [python]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: ^src/api/client.js$
- id: end-of-file-fixer
exclude: ^src/api/client.js$
- id: check-symlinks
- id: check-merge-conflict
- id: check-case-conflict
- id: detect-aws-credentials
args:
- --allow-missing-credentials
- id: detect-private-key
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ghcr.io/radiorabe/s2i-python:2.0.0-alpha.11 AS build

COPY --chown=1001:0 ./ /opt/app-root/src/

RUN python3.11 -mbuild


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

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

RUN microdnf install -y \
python3.11-pip \
&& python3.11 -mpip --no-cache-dir install /tmp/dist/*.whl \
&& microdnf remove -y \
python3.11-pip \
python3.11-setuptools \
&& microdnf clean all \
&& rm -rf /tmp/dist/

USER nobody

CMD ["acrloader"]
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ACR Loader

Loads data from ACRCloud's broadcat monitoring service and stores it
in our ownCloud instance. Runs as a cronjob and is scheduled to run
once per day.

## Usage

```
helm install my-acrloader oci://ghcr.io/radiorabe/helm/acrloader \
--version x.y.z \
--set acr.bearerToken=<token>,acr.projectId=<pid>,streamId=<sid> \
--set oc.url=<url>,oc.user=<user>,oc.pass=<pass>,oc.path=<path>
```

## Development

```
python -mvenv venv
. venv/bin/activate
python -mpip install poetry
poetry install
poetry run pytest
pre-commit run
```

## License
This application is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
Software Foundation, version 3 of the License.

## Copyright
Copyright (c) 2023 [Radio Bern RaBe](http://www.rabe.ch)
12 changes: 12 additions & 0 deletions acrloader.conf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ACRCloud Bearer token
acrcloud-bearer-token=
# ACRCloud project id
acr-project-id=
# ACRCloud stream id
acr-stream-id=
# owncloud URL
oc-url=
# ownCloud user
oc-user=
# ownCloud pass
oc-pass=
13 changes: 13 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: acr-loader
description: Loads data from ACRCloud's broadcast monitoring and stores it in ownCloud.
annotations:
backstage.io/techdocs-ref: dir:.
github.com/project-slug: radiorabe/acr-loader
spec:
type: service
lifecycle: experimental
owner: it-reaktion
23 changes: 23 additions & 0 deletions charts/acrloader/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/acrloader/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: acrloader
description: RaBe ACR Loader
type: application
version: 0.0.0
appVersion: "0.0.0"
2 changes: 2 additions & 0 deletions charts/acrloader/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. The following CronJob was deployed
* {{ include "acrloader.fullname" . }} (schedule: {{ .Values.schedule | quote }})
62 changes: 62 additions & 0 deletions charts/acrloader/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "acrloader.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "acrloader.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "acrloader.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "acrloader.labels" -}}
helm.sh/chart: {{ include "acrloader.chart" . }}
{{ include "acrloader.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "acrloader.selectorLabels" -}}
app.kubernetes.io/name: {{ include "acrloader.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "acrloader.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "acrloader.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit b479fdc

Please sign in to comment.