simplified docker usage
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-09-27 22:00:54 +02:00
parent 51e1aab134
commit eb797a945d
5 changed files with 31 additions and 39 deletions

View File

@@ -1,6 +1,7 @@
FROM python:3.7.3-stretch FROM python:3.7.3-stretch
COPY requirements.txt /tmp/ COPY requirements.txt /tmp/
COPY entrypoint.sh /
RUN pip install -r /tmp/requirements.txt RUN pip install -r /tmp/requirements.txt
COPY . /tmp/infomentor COPY . /tmp/infomentor
@@ -10,5 +11,4 @@ RUN useradd --create-home appuser
WORKDIR /home/appuser WORKDIR /home/appuser
USER appuser USER appuser
VOLUME ["/home/appuser"] VOLUME ["/home/appuser"]
ENTRYPOINT ["/entrypoint.sh"]
CMD [ "python", "-m", "infomentor" ]

View File

@@ -1,9 +1,12 @@
# Infomentor Tool # Infomentor Tool
This tool is designed to check the infomentor portal and send notifications using mail or pushover api. This tool is designed to check the infomentor portal and send notifications using mail or pushover api.
It is also capable of sending Calendar invitations/entries.
## Usage ## Usage
You could install it locally but using the docker image is preferred.
``` ```
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
@@ -13,53 +16,29 @@ infomentor
After the first run a `infomentor.ini` file is available which has a few values to be entered. After the first run a `infomentor.ini` file is available which has a few values to be entered.
## Docker ## Docker
This could be run within docker. You it has a volume `/home/appuser` where all the data is stored. In favour of accessing it from a webserver you should bindmount it. This could be run within docker. You it has a volume `/home/appuser` where all the data is stored. In favour of accessing it from a webserver you should bindmount it.
There also the infomentor.ini should be placed. There also the infomentor.ini would be placed.
Build the container by `docker build -t infomentor:latest .` and run it like this: Build the container by `docker build -t infomentor:latest .` and run it like this:
### Notify Users / First Run
``` ```
docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest
``` ```
for adding an user or all the commands run it adding -it to it, like: ### Adding a user
``` ```
docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest adduser docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest --username <uname> --password <pwd> --pushover <pushoverid> --invitationmail <mymail>
``` ```
## Manage Users ### See all options
### Step 1 create a user
Provide the username and password for infomentor.
```
docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest adduser --username <username>
```
### Step 2 add notification mechanism
```
docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest addmail --username <username>
```
or
``` ```
docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest pushover --username <username> docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest --help
```
### Step 3 (optional) Add iCloud calendar
*NB:* This is currently not working. You could add it, but it won't work.
It is capable of syncing all the infomentor calendar elements to icloud calendar
```
source venv/bin/activate
addcalendar --username <username>
``` ```
## NB ## NB

3
entrypoint.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
infomentor $*

View File

@@ -34,6 +34,7 @@ def parse_args(arglist):
parser.add_argument("--username", type=str, nargs="?", help="infomentor username") parser.add_argument("--username", type=str, nargs="?", help="infomentor username")
parser.add_argument("--password", type=str, nargs="?", help="infomentor password") parser.add_argument("--password", type=str, nargs="?", help="infomentor password")
parser.add_argument("--fake", action="store_true", help="add fake") parser.add_argument("--fake", action="store_true", help="add fake")
parser.add_argument("--notifyerrors", action="store_true", help="add fake")
parser.add_argument("--pushover", type=str, nargs="?", help="pushover user id") parser.add_argument("--pushover", type=str, nargs="?", help="pushover user id")
parser.add_argument("--mail", type=str, nargs="?", help="e-mail for notification") parser.add_argument("--mail", type=str, nargs="?", help="e-mail for notification")
parser.add_argument( parser.add_argument(
@@ -59,13 +60,13 @@ def perform_user_update(args):
session.query(model.User).filter(model.User.name == username).one_or_none() session.query(model.User).filter(model.User.name == username).one_or_none()
) )
if existing_user is not None: if existing_user is not None:
print("user exists, changing pw") logger.info("Updating user {}", username)
else: else:
print(f"Adding user: {username}") logger.info("Creating User user {}", username)
if args.password is None: if args.password is None:
logger.info("No password provided, asking for it")
import getpass import getpass
password = getpass.getpass(prompt="Password: ") password = getpass.getpass(prompt="Password: ")
else: else:
password = args.password password = args.password
@@ -76,15 +77,23 @@ def perform_user_update(args):
user = model.User(name=username, password=password) user = model.User(name=username, password=password)
session.add(user) session.add(user)
if args.notifyerrors:
user.wantstatus = True
else:
user.wantstatus = False
if args.pushover is not None: if args.pushover is not None:
logger.info("Adding pushover notification")
user.notification = model.Notification( user.notification = model.Notification(
ntype=model.Notification.Types.PUSHOVER, info=args.pushover ntype=model.Notification.Types.PUSHOVER, info=args.pushover
) )
elif args.mail: elif args.mail:
logger.info("Adding email notification")
user.notification = model.Notification( user.notification = model.Notification(
ntype=model.Notification.Types.EMAIL, info=args.mail ntype=model.Notification.Types.EMAIL, info=args.mail
) )
elif args.fake: elif args.fake:
logger.info("Adding fake notification")
user.notification = model.Notification( user.notification = model.Notification(
ntype=model.Notification.Types.FAKE, info="" ntype=model.Notification.Types.FAKE, info=""
) )
@@ -94,6 +103,7 @@ def perform_user_update(args):
and args.icloudpwd is not None and args.icloudpwd is not None
and args.icloudcalendar is not None and args.icloudcalendar is not None
): ):
logger.info("Adding icloud calendar")
user.icalendar = model.ICloudCalendar( user.icalendar = model.ICloudCalendar(
icloud_user=args.iclouduser, icloud_user=args.iclouduser,
password=args.icloudpwd, password=args.icloudpwd,
@@ -101,6 +111,7 @@ def perform_user_update(args):
) )
if args.invitationmail: if args.invitationmail:
logger.info("Activating sending of calendar entries per mail")
user.invitation = model.Invitation(email=mail) user.invitation = model.Invitation(email=mail)
session.commit() session.commit()
@@ -111,6 +122,7 @@ def notify_users():
session = db.get_db() session = db.get_db()
cfg = config.load() cfg = config.load()
if cfg["healthchecks"]["url"] != "": if cfg["healthchecks"]["url"] != "":
logger.info("Triggering Healthcheck Start")
requests.get(cfg["healthchecks"]["url"] + "/start") requests.get(cfg["healthchecks"]["url"] + "/start")
for user in session.query(model.User): for user in session.query(model.User):
@@ -161,6 +173,7 @@ def notify_users():
session.commit() session.commit()
if cfg["healthchecks"]["url"] != "": if cfg["healthchecks"]["url"] != "":
logger.info("Triggering Healthcheck Stop")
requests.get(cfg["healthchecks"]["url"]) requests.get(cfg["healthchecks"]["url"])

View File

@@ -11,9 +11,6 @@ setup(
entry_points = { entry_points = {
'console_scripts': [ 'console_scripts': [
'infomentor=infomentor:main', 'infomentor=infomentor:main',
'adduser=infomentor:run_adduser',
'addmail=infomentor:run_addmail',
'addpushover=infomentor:run_addpushover',
], ],
}, },
install_requires=[ install_requires=[