From e8f9c38340ebf3f051db22a8dfe9dd35cbf5994c Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 19 Apr 2023 11:55:13 +0200 Subject: [PATCH] Monog DB test --- IUM_07/Dockerfile | 8 ++++++++ IUM_07/Jenkinsfile | 13 +++++++++++++ IUM_07/mongo_observer.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 IUM_07/Dockerfile create mode 100644 IUM_07/Jenkinsfile create mode 100644 IUM_07/mongo_observer.py diff --git a/IUM_07/Dockerfile b/IUM_07/Dockerfile new file mode 100644 index 0000000..e6b155f --- /dev/null +++ b/IUM_07/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:latest + +RUN apt update && apt install -y \ + python3-pip \ + python3 + +RUN python3 -m pip install sacred pymongo + diff --git a/IUM_07/Jenkinsfile b/IUM_07/Jenkinsfile new file mode 100644 index 0000000..1289354 --- /dev/null +++ b/IUM_07/Jenkinsfile @@ -0,0 +1,13 @@ + node { + checkout scm + //Pierwszy argument to tag, który zostania nadany zbudowanemu obrazowi + //Jeśli chcemy użyć Dockerfile z innej ścieżki niż ./Dockerfile, możemy ją podać jako drugi argument + def testImage = docker.build("sacred_pymongo", "./IUM_07/Dockerfile") + + //Wszystkie polecenia poniżej wykonają się w kontenerze, z podmontowanym Workspace Jenkinsa + testImage.inside { + dir ("IUM_07"){ + sh 'python3 mongo_observer.py' + } + } + } diff --git a/IUM_07/mongo_observer.py b/IUM_07/mongo_observer.py new file mode 100644 index 0000000..e07bdc4 --- /dev/null +++ b/IUM_07/mongo_observer.py @@ -0,0 +1,37 @@ +from sacred.observers import MongoObserver +from sacred import Experiment +import random +import time + +ex = Experiment("sacred_scopes", interactive=True) +ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password@localhost:27017', + db_name='sacred')) # Tutaj podajemy dane uwierzytelniające i nazwę bazy skonfigurowane w pliku .env podczas uruchamiania bazy. +# W przypadku instancji na Jenkinsie url będzie wyglądał następująco: mongodb://mongo_user:mongo_password_IUM_2021@localhost:27017 +@ex.config +def my_config(): + recipient = "Świecie" + greeting = "Witaj" + +@ex.capture +def prepare_message(recipient, greeting): + return "{0} {1}!".format(greeting, recipient) + +@ex.main +def my_main(recipient, greeting, _run): + print(prepare_message()) ## Nie musimy przekazywać wartości + counter = 0 + while counter < 20: + counter+=1 + value = counter + ms_to_wait = random.randint(5, 5000) + time.sleep(ms_to_wait/1000) + noise = 1.0 + 0.1 * (random.randint(0, 10) - 5) + # This will add an entry for training.loss metric in every second iteration. + # The resulting sequence of steps for training.loss will be 0, 2, 4, ... + if counter % 2 == 0: + _run.log_scalar("training.loss", value * 1.5 * noise, counter) + # Implicit step counter (0, 1, 2, 3, ...) + # incremented with each call for training.accuracy: + _run.log_scalar("training.accuracy", value * 2 * noise) + +ex.run()