Compare commits

..

5 Commits

Author SHA1 Message Date
5ec57150b1 docs: update README with additional Docker run command options for shared memory size
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m53s
2025-02-22 23:07:11 +01:00
bd80c1c6cc feat: enhance Docker workflow to support logging in and pushing images to Docker Hub; update README with new run command options
All checks were successful
Build and Push Docker Image / build (push) Successful in 4m11s
2025-02-22 18:34:11 +01:00
9e125bf9f7 feat: include sleep to wait for driver setup logic and remove yaspin
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
2025-02-22 18:21:56 +01:00
a0cf93a6be feat: enhance setupStats function with retry logic and improve error handling; update entrypoint to run main script as PID 1
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m29s
2025-02-21 20:26:03 +01:00
5c92020169 Add convenience functions, update Docker setup, and integrate Webpack for building WebRTC internals exporter (#3)
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m31s
Reviewed-on: #3
Co-authored-by: Mirko Milovanovic <mir_ko@me.com>
Co-committed-by: Mirko Milovanovic <mir_ko@me.com>
2025-02-21 11:21:14 +00:00
4 changed files with 46 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ on:
env: env:
REGISTRY_URL: gitea.kobim.cloud REGISTRY_URL: gitea.kobim.cloud
DOCKERHUB_USERNAME: kobimex
jobs: jobs:
build: build:
@@ -18,20 +19,37 @@ jobs:
- name: Setup Docker Environment - name: Setup Docker Environment
uses: ./.github/actions/setup-docker-environment uses: ./.github/actions/setup-docker-environment
- name: Log in to Docker registry - name: Log in to custom Docker registry
uses: docker/login-action@v3.3.0 uses: docker/login-action@v3.3.0
with: with:
registry: ${{ env.REGISTRY_URL }} registry: ${{ env.REGISTRY_URL }}
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push Docker image - name: Build and push Docker image to custom registry
uses: docker/build-push-action@v6.13.0 uses: docker/build-push-action@v6.13.0
with: with:
context: . context: .
push: true push: true
tags: ${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}-monolith:latest tags: ${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}-monolith:latest
file: ./Monolith.dockerfile file: ./Monolith.dockerfile
platforms: |
linux/amd64
linux/arm64
- name: Log in to Docker Hub
uses: docker/login-action@v3.3.0
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image to Docker Hub
uses: docker/build-push-action@v6.13.0
with:
context: .
push: true
tags: ${{ env.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-monolith:latest
file: ./Monolith.dockerfile
platforms: | platforms: |
linux/amd64 linux/amd64
linux/arm64 linux/arm64

View File

@@ -59,7 +59,13 @@ To stop the Docker containers run: `docker compose down -v`
3. Ajust the firewall settings to allow the necessary ports if needed 3. Ajust the firewall settings to allow the necessary ports if needed
4. Start the Docker container: 4. Start the Docker container:
```sh ```sh
docker run --rm -p 7900:7900 --env-file .env --name peertube-collector gitea.kobim.cloud/kobim/peertube-collector-monolith:latest docker run --rm -p 7900:7900 --env-file .env --name peertube-collector --pull always --shm-size="2g" gitea.kobim.cloud/kobim/peertube-collector-monolith:latest
```
or
```sh
docker run --rm -p 7900:7900 --env-file .env --name peertube-collector --pull always --shm-size="2g" kobimex/peertube-collector-monolith:latest
``` ```

27
main.py
View File

@@ -5,7 +5,7 @@ import socket
import logging import logging
import os import os
import argparse import argparse
from yaspin import yaspin from time import sleep
from functools import partial from functools import partial
from http.server import HTTPServer from http.server import HTTPServer
from utils.PostHandler import Handler from utils.PostHandler import Handler
@@ -50,7 +50,6 @@ def interrupt_handler(signum, driver: webdriver.Remote):
driver.quit() driver.quit()
raise SystemExit raise SystemExit
@yaspin()
def setupChromeDriver(command_executor: str | None, webrtc_internals_path: str) -> webdriver.Remote | webdriver.Chrome: def setupChromeDriver(command_executor: str | None, webrtc_internals_path: str) -> webdriver.Remote | webdriver.Chrome:
logger.log(logging.INFO, 'Setting up Chrome driver.') logger.log(logging.INFO, 'Setting up Chrome driver.')
chrome_options = Options() chrome_options = Options()
@@ -180,20 +179,24 @@ def downloadStats(driver: webdriver.Remote | webdriver.Chrome, peersDict: dict,
def convert_to_bytes(down, downUnit): def convert_to_bytes(down, downUnit):
return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit]) return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit])
@yaspin() def setupStats(driver: webdriver.Remote, url: str, retries: int = 5) -> webdriver.Remote:
def setupStats(driver: webdriver.Remote, url: str):
logger.log(logging.INFO, 'Setting up stats.') logger.log(logging.INFO, 'Setting up stats.')
actions = ActionChains(driver) actions = ActionChains(driver)
wait = WebDriverWait(driver, 30, poll_frequency=0.2) wait = WebDriverWait(driver, 30, poll_frequency=0.2)
sleep(2)
driver.get(url) for attempt in range(retries):
driver.get(url)
try: try:
wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button'))) wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button')))
except Exception: break
logger.error('Timeout while waiting for the big play button to be present.') except Exception:
driver.quit() logger.error(f'Timeout while waiting for the big play button to be present. Attempt {attempt + 1} of {retries}')
raise SystemExit(1) if attempt == retries - 1:
logger.error('Timeout limit reached. Exiting.')
driver.quit()
raise SystemExit(1)
actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform() actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar'))) wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar')))

View File

@@ -48,6 +48,8 @@ done
printf '\n' printf '\n'
# Start the Telegraf agent and the main script # Start the Telegraf agent
telegraf --config ./telegraf.conf & telegraf --config ./telegraf.conf &
./venv/bin/python main.py
# Start the main Python script as PID 1
exec ./venv/bin/python main.py