Compare commits

...
60 Commits
Author SHA1 Message Date
brb 9ad983cc1c added code to extract version number
Docker / Test (push) Successful in 38s
Docker / Publish (push) Failing after 5s
2023-07-12 10:27:41 +02:00
brb 10821f94df added code to extract version number
Docker / Test (push) Successful in 40s
Docker / Publish (push) Failing after 4s
2023-07-12 10:24:43 +02:00
brb 550551c4a0 updated to only run when tag is provided
Docker / Test (push) Successful in 40s
Docker / Publish (push) Failing after 6s
2023-07-12 10:08:13 +02:00
brb 5709c7152a updated to only run when tag is provided to release branch
pipeline / Test (push) Successful in 52s
Docker / Test (push) Successful in 38s
Docker / Publish (push) Failing after 6s
2023-07-11 18:41:05 +02:00
brb a8b27d8f21 ignored pushes to release branch without tag
pipeline / Test (push) Successful in 39s
2023-07-11 18:33:15 +02:00
brb 2cd449e130 renamed workflow file
Docker / Publish (push) Failing after 6s
Docker / Test (push) Successful in 39s
2023-07-11 18:24:06 +02:00
brb 91b22a781c renamed workflow file 2023-07-11 18:23:37 +02:00
brb 6f7201054b ignored branch release 2023-07-11 18:22:23 +02:00
brb 697973a454 added automatic detection of version number
Docker / Test (push) Successful in 41s
Docker / Publish (push) Failing after 5s
pipeline / Test (push) Successful in 39s
2023-07-11 18:11:52 +02:00
brb 77c749cfb8 renamed workflow
Docker / Test (push) Successful in 41s
Docker / Publish (push) Successful in 8s
pipeline / Test (push) Successful in 39s
2023-07-11 18:04:56 +02:00
brb aa358bd361 added workflow to build and publish container image
pipeline / Test (push) Successful in 39s
2023-07-11 18:01:31 +02:00
brb 3ecea06979 commented out publishing steps 2023-07-11 18:01:07 +02:00
brb 6a48b900c8 updated publish step commands
pipeline / Test (push) Successful in 38s
pipeline / Publish (push) Successful in 6s
2023-07-11 17:36:02 +02:00
brb 4fff9100e2 updated publish step commands
pipeline / Test (push) Successful in 38s
pipeline / Publish (push) Successful in 5s
2023-07-11 17:33:51 +02:00
brb a8dae35cd0 updated build step
pipeline / Test (push) Successful in 39s
pipeline / Publish (push) Successful in 6s
2023-07-11 17:27:47 +02:00
brb b62fb0c4fa removed unused step 2023-07-11 17:26:03 +02:00
brb 2d9b06be5d updated build step
pipeline / Show Gitea.ref (push) Successful in 4s
pipeline / Test (push) Successful in 38s
pipeline / Publish (push) Failing after 4s
2023-07-11 17:25:28 +02:00
brb 5280cd1d8b updated version number
pipeline / Show Gitea.ref (push) Successful in 4s
pipeline / Test (push) Successful in 37s
pipeline / Publish (push) Successful in 6s
2023-07-11 17:19:29 +02:00
brb e0ac9bb0cc changed publish workflow
pipeline / Show Gitea.ref (push) Successful in 4s
pipeline / Publish (push) Failing after 10s
pipeline / Test (push) Successful in 38s
2023-07-11 17:14:15 +02:00
brb c3203f024b added echo cmd
pipeline / Test (push) Successful in 39s
pipeline / Publish (push) Has been skipped
pipeline / Show Gitea.ref (push) Successful in 4s
2023-07-11 17:04:05 +02:00
brb 65621ed484 updated deploy job steps
pipeline / Deploy (push) Has been skipped
pipeline / Test (push) Successful in 38s
2023-07-11 16:46:51 +02:00
brb 29dd4543c3 updated deploy job steps
pipeline / Test (push) Successful in 1m2s
pipeline / Deploy (push) Failing after 5s
2023-07-11 16:39:49 +02:00
brb ef416de1a7 updated deploy job steps
pipeline / Deploy (push) Failing after 6s
pipeline / Test (push) Successful in 38s
2023-07-11 16:35:21 +02:00
brb d16c9aa5bc changed command
pipeline / Test (push) Successful in 39s
pipeline / Deploy (push) Successful in 5s
2023-07-11 15:55:38 +02:00
brb 455d82d0f0 removed comment
pipeline / demo (push) Successful in 6s
pipeline / Test (push) Successful in 39s
pipeline / Deploy (push) Successful in 49s
2023-07-11 15:41:15 +02:00
brb 182a2f70b6 added docker build command
pipeline / demo (push) Successful in 6s
pipeline / Test (push) Successful in 38s
pipeline / Deploy (push) Successful in 3s
2023-07-11 15:37:35 +02:00
brb a81e2a89c9 added demo job
pipeline / demo (push) Successful in 6s
pipeline / Test (push) Successful in 38s
pipeline / Deploy (push) Has been skipped
2023-07-11 15:33:24 +02:00
brb 2041d42e76 changed indentation
pipeline / Deploy (push) Has been skipped
pipeline / Test (push) Successful in 39s
2023-07-11 15:30:01 +02:00
brb c7c3631d8d added command
pipeline / Test (push) Successful in 38s
pipeline / Deploy (push) Successful in 4s
2023-07-11 15:23:27 +02:00
brb 2cdc184a1b added definition
pipeline / Test (push) Successful in 39s
pipeline / Deploy (push) Has been skipped
2023-07-11 15:08:54 +02:00
brb 2394bb856d updated script
pipeline / Test (push) Successful in 38s
pipeline / Deploy (push) Successful in 2s
2023-07-11 15:04:45 +02:00
brb 65a693706a updated deploy workflow
pipeline / Test (push) Successful in 39s
pipeline / Deploy (push) Successful in 3s
2023-07-11 15:02:55 +02:00
brb 1f716aeb21 updated flake8 outputs
pipeline / Test (push) Successful in 38s
pipeline / Deploy (push) Has been skipped
2023-07-11 14:32:29 +02:00
brb 2889601bc3 removed unused lines
pipeline / Test (push) Successful in 42s
pipeline / Deploy (push) Has been skipped
2023-07-11 14:22:14 +02:00
brb 1341fc5597 added runs-on
Python application / Test (push) Successful in 40s
Python application / Deploy (push) Has been skipped
2023-07-11 14:01:38 +02:00
brb 0b4413ce9c updated build step
Python application / Deploy (push) Successful in 2s
Python application / Test (push) Successful in 39s
2023-07-11 13:42:23 +02:00
brb a387e5894f included deploy step for release branch
Python application / Test (push) Successful in 38s
Python application / Deploy (push) Successful in 2s
2023-07-11 12:51:35 +02:00
brb 9668646a05 renamed run name
Python application / test (push) Successful in 39s
2023-07-11 11:27:07 +02:00
brb e6f0242775 added type checking 2023-07-11 11:25:00 +02:00
brb 35e40d7b98 added use of default values 2023-07-11 11:24:33 +02:00
brb 0a2fc865b1 updated default values 2023-07-11 11:08:17 +02:00
brb 212f8179d5 added use of default values 2023-07-11 11:08:05 +02:00
brb 7d5d2f52bd removed unused variable 2023-07-11 10:44:49 +02:00
brb ed70b9808b removed unused imports 2023-07-11 10:43:15 +02:00
brb cf1aab7caf added use of default values 2023-07-11 10:43:05 +02:00
brb e39c85327f added default values 2023-07-11 10:42:49 +02:00
brb 3f6e15c6e1 added mypy config 2023-07-11 10:21:40 +02:00
brb 3c1d93726e updated workflow
Python application / build (push) Successful in 31s
2023-07-11 10:04:06 +02:00
brb 4ccb357f7c fixed linting 2023-07-11 10:03:49 +02:00
brb cfbf544110 fixed linting 2023-07-11 10:00:44 +02:00
brb 5e5fb31767 removed unused imports 2023-07-11 09:59:34 +02:00
brb d4e5728015 added logging 2023-07-11 09:59:24 +02:00
brb a9818001d5 corrected linting 2023-07-11 09:58:09 +02:00
brb b51460b696 added logging 2023-07-11 09:57:38 +02:00
brb 056fe85d7c changed linting function call
Python application / build (push) Failing after 30s
2023-07-11 09:47:59 +02:00
brb 19de6354c5 specified image
Python application / build (push) Successful in 1m29s
2023-07-10 19:43:25 +02:00
brb 71946eab59 specified ubuntu version
Python application / build (push) Failing after 6s
2023-07-10 19:41:42 +02:00
brb e7073c03bd specified platform version
Python application / build (push) Failing after 6s
2023-07-10 19:40:11 +02:00
brb 3dc18eb8bd specified python version
Python application / build (push) Failing after 5s
2023-07-10 19:33:35 +02:00
brb f928346bda changed dependency to go directly to github
Python application / build (push) Failing after 20s
2023-07-10 19:31:58 +02:00
9 changed files with 214 additions and 78 deletions
+52
View File
@@ -0,0 +1,52 @@
name: pipeline
run-name: ${{ gitea.actor }} is running script
runs-on: ubuntu-latest
on:
push:
branches-ignore:
- "release"
image: python:3.10
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: https://github.com/actions/setup-python@v3
with:
python-version: "3.10"
architecture: "x64"
- name: Install Packages
run: |
python -m pip install --upgrade pip
pip install flake8 mypy pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: PEP8 check
run: flake8 ./code --benchmark --exit-zero
- name: Type check
run: mypy ./code
# publish:
# name: Publish
# runs-on: ubuntu-latest
# needs: [test]
# if: gitea.ref == 'refs/heads/release'
# env:
# repository_host: 192.168.1.2:5000
# repository_name: ${{ gitea.repository }}
# repository_version: v1.0
# steps:
# - uses: actions/checkout@v3
# - name: Build
# run: |
# echo "> docker build . --file Dockerfile --tag ${repository_name}:${repository_version}"
# docker build . --file Dockerfile --tag ${repository_name}:${repository_version}
# - name: Tag
# run: |
# echo "> docker tag ${repository_name}:${repository_version} ${repository_host}/${repository_name}:${repository_version}"
# docker tag ${repository_name}:${repository_version} ${repository_host}/${repository_name}:${repository_version}
# - name: Push
# run: |
# echo "> docker push ${repository_host}/${repository_name}:${repository_version}"
# docker push ${repository_host}/${repository_name}:${repository_version}
-24
View File
@@ -1,24 +0,0 @@
name: Python application
run-name: ${{ gitea.actor }} is building the application
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ./code --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 ./code --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
+44
View File
@@ -0,0 +1,44 @@
name: Docker
run-name: Build and Publish Service
runs-on: ubuntu-latest
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: https://github.com/actions/setup-python@v3
with:
python-version: "3.10"
architecture: "x64"
- name: Install Packages
run: |
python -m pip install --upgrade pip
pip install flake8 mypy pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: PEP8 check
run: flake8 ./code --benchmark --exit-zero
- name: Type check
run: mypy ./code
publish:
name: Publish
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v3
-
name: Get Version
id: get_version
run: echo ::set-output name=VERSION::${gitea.ref_name/refs\/tags\//}
-
name: Push Image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: 192.168.1.2:5000/${{gitea.repository}}:${{steps.get_version.outputs.VERSION}}
+2 -1
View File
@@ -1,6 +1,6 @@
from speedtest import Speedtest from speedtest import Speedtest
from dotenv import load_dotenv from dotenv import load_dotenv
from typing import List import logging
def measure(): def measure():
@@ -13,6 +13,7 @@ def measure():
s.download(threads=None) s.download(threads=None)
s.upload(threads=None) s.upload(threads=None)
s.results.share() s.results.share()
logging.debug('finished')
return s.results.dict() return s.results.dict()
+16 -12
View File
@@ -1,27 +1,31 @@
from pymongo import MongoClient from pymongo import MongoClient
from dotenv import load_dotenv from dotenv import load_dotenv
from configparser import ConfigParser
from pathlib import Path
import logging import logging
import os
# load default values
config = ConfigParser()
config.read(Path(__file__).parent / 'defaults.ini')
DB_IP_ADDRESS = config.get('database', 'db_ip_address')
DB_NAME = config.get('database', 'db_name')
DB_COLLECTION_NAME = config.get('database', 'db_collection_name')
def connect( def connect(
ip_addr: str | None = None, ip_addr: str = DB_IP_ADDRESS,
db_name: str | None = None, db_name: str = DB_NAME,
collection_name: str | None = None collection_name: str = DB_COLLECTION_NAME
): ):
""" """
Connect to MongoDB database and return collection. Connect to MongoDB database and return collection.
""" """
# ensure variables are set
if ip_addr is None:
ip_addr = os.getenv('DB_IP_ADDRESS')
if db_name is None:
db_name = os.getenv('DB_NAME')
if collection_name is None:
collection_name = os.getenv('DB_COLLECTION_NAME')
# connect to database # connect to database
client = MongoClient(ip_addr) client: MongoClient = MongoClient(ip_addr)
db = client[db_name] db = client[db_name]
collection = db[collection_name] collection = db[collection_name]
logging.debug('finished')
return collection return collection
+15
View File
@@ -0,0 +1,15 @@
[main]
logger_level=info
user_id=0
replicates=3
trigger_interval_seconds=60
[database]
db_ip_address=192.168.1.2
db_name=bandwidth_probing
db_collection_name=data
[discord]
webhook_url=https://discord.com/api/webhooks/1127970367047225354/wNkoRex4OncMw11OCJg6atR_xgHS2VhLrku4jYIUw81Kr4sutdD3Tt-XAltG0UQy14rZ
service_name=bandwidth_probing
logger_level=warning
+40 -30
View File
@@ -1,53 +1,63 @@
from discord_logging.handler import DiscordHandler from discord_logging.handler import DiscordHandler
from dotenv import load_dotenv from dotenv import load_dotenv
from configparser import ConfigParser
from pathlib import Path
import logging import logging
import os import os
def initialise_app(): # load default values
config = ConfigParser()
config.read(Path(__file__).parent / 'defaults.ini')
LOGGER_LEVEL = config.get('main', 'logger_level')
DISCORD_SERVICE_NAME = config.get('discord', 'service_name')
DISCORD_WEBHOOK_URL = config.get('discord', 'webhook_url')
DISCORD_LOGGER_LEVEL = config.get('discord', 'logger_level')
def initialise_app(
logger_level: str = LOGGER_LEVEL,
discord_service_name: str = DISCORD_SERVICE_NAME,
discord_webhook_url: str = DISCORD_WEBHOOK_URL,
discord_logger_level: str = DISCORD_LOGGER_LEVEL
):
""" """
Convienience function that ensures eveything is ready before running main loop. Convienience function that ensures eveything is ready
before running the main loop.
""" """
# load environment variables from file # load environment variables
load_dotenv() load_dotenv()
logger_level = os.getenv(
'LOGGER_LEVEL',
default=LOGGER_LEVEL
)
discord_service_name = os.getenv(
'DISCORD_SERVICE_NAME',
default=DISCORD_SERVICE_NAME
)
discord_webhook_url = os.getenv(
'DISCORD_WEBHOOK_URL',
default=DISCORD_WEBHOOK_URL
)
discord_logger_level = os.getenv(
'DISCORD_LOGGER_LEVEL',
default=DISCORD_LOGGER_LEVEL
)
# setup logging # setup logging
fmt = '|%(asctime)s| %(levelname)s %(filename)s:%(funcName)s:%(message)s' fmt = '|%(asctime)s| %(levelname)s %(filename)s:%(funcName)s:%(message)s'
datefmt = '%Y-%m-%d %H:%M:%S' datefmt = '%Y-%m-%d %H:%M:%S'
logger_level = os.getenv('LOGGER_LEVEL', default=None)
if logger_level is None:
logger_level = 'info'
logging.info(f'environment variable LOGGER_LEVEL not set. Using default (info)')
level = getattr(logging, logger_level.upper()) level = getattr(logging, logger_level.upper())
logging.basicConfig(format=fmt, datefmt=datefmt, level=level) logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
# setup logging to discord # setup logging to discord
discord_url = os.getenv('DISCORD_URL', default=None)
assert discord_url is not None
logger = logging.getLogger() logger = logging.getLogger()
discord_handler = DiscordHandler( discord_handler = DiscordHandler(
service_name = 'bandwidth_probing', service_name=discord_service_name,
webhook_url = discord_url, webhook_url=discord_webhook_url,
) )
discord_handler.setFormatter(logging.Formatter('%(message)s')) discord_handler.setFormatter(logging.Formatter('%(message)s'))
discord_handler.setLevel(logging.WARNING) level = getattr(logging, discord_logger_level.upper())
discord_handler.setLevel(level=level)
logger.addHandler(discord_handler) logger.addHandler(discord_handler)
# ensure environment variables are set
necessary_list = [
'DB_IP_ADDRESS',
'DB_NAME',
'DB_COLLECTION_NAME'
]
for var in necessary_list:
assert var in os.environ, f'environment variable {var} not set.'
# set defaults if not yet handled
default_dict = {
'USER_ID': 0,
'REPLICATES': 3,
'TRIGGER_INTERVAL_SECONDS': 60
}
for k, v in default_dict.items():
if not k in os.environ:
logging.info(f'environment variable {k} not set. Using default ({v}).')
os.environ[k] = str(v)
if __name__ == '__main__': if __name__ == '__main__':
+36 -9
View File
@@ -1,15 +1,34 @@
import time import time
import logging import logging
import time
import os import os
from configparser import ConfigParser
from pathlib import Path
from initialise_app import initialise_app from initialise_app import initialise_app
from bandwidth import measure as measure_bandwidth from bandwidth import measure as measure_bandwidth
from database import connect from database import connect
def event():
logging.info('started event') # load default values
# get env vars config = ConfigParser()
replicates = int(os.getenv('REPLICATES')) config.read(Path(__file__).parent / 'defaults.ini')
REPLICATES = int(config.get('main', 'replicates'))
USER_ID = int(config.get('main', 'user_id'))
TRIGGER_INTERVAL_SECONDS = float(
config.get(
'main',
'trigger_interval_seconds'
)
)
def event(
replicates: int = REPLICATES,
user_id: int = USER_ID
):
logging.debug('started event')
# load environment variables
replicates = int(os.getenv('REPLICATES', default=REPLICATES))
user_id = int(os.getenv('USER_ID', default=USER_ID))
# setup database connection # setup database connection
db = connect() db = connect()
# run event # run event
@@ -23,7 +42,7 @@ def event():
continue continue
# upload result to database # upload result to database
payload_dict = { payload_dict = {
'user_id': os.getenv('USER_ID'), 'user_id': user_id,
'data': res 'data': res
} }
try: try:
@@ -33,7 +52,8 @@ def event():
continue continue
logging.debug(f'data sent to database received db_id: {db_id}') logging.debug(f'data sent to database received db_id: {db_id}')
time.sleep(1) time.sleep(1)
logging.info('finished event') logging.debug('finished')
if __name__ == '__main__': if __name__ == '__main__':
initialise_app() initialise_app()
@@ -41,11 +61,18 @@ if __name__ == '__main__':
while True: while True:
if time.time() >= trigger_time: if time.time() >= trigger_time:
# set new trigger time # set new trigger time
trigger_time += int(os.getenv('TRIGGER_INTERVAL_SECONDS')) trigger_interval = float(
os.getenv(
'TRIGGER_INTERVAL_SECONDS',
default=TRIGGER_INTERVAL_SECONDS
)
)
trigger_time += trigger_interval
# run event # run event
try: try:
event() event()
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
else:
logging.info('finished event')
time.sleep(1) time.sleep(1)
+7
View File
@@ -0,0 +1,7 @@
[mypy]
[mypy-discord_logging.*]
ignore_missing_imports = True
[mypy-speedtest.*]
ignore_missing_imports = True