https://github.com/ai4os/docker-mail

Docker image for mail task in Nomad

https://github.com/ai4os/docker-mail

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Docker image for mail task in Nomad

Basic Info
  • Host: GitHub
  • Owner: ai4os
  • Language: Python
  • Default Branch: main
  • Size: 36.1 KB
Statistics
  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme

README.md

logo

Automated mail notifications

Build client Build server

This project has been developed based on the need to notify users when their Nomad jobs are assigned after a delay time (currently set to 7 days). For this and due to specific needs of the mail service used it's necessary to take a client-server approach.

The idea is that the client part will be deployed as a side task (mailtask) in a Nomad job, taking care of all the temporal logic. If the premise is met then it will make a request to the server, which will be in charge of sending the email.

Both Docker images are available in the project's Harbor registry: * registry.services.ai4os.eu/ai4os/docker-mail:client * registry.services.ai4os.eu/ai4os/docker-mail:server

Usage

As mentioned, the idea is to send an email notification if the Nomad Job has been scheduled after the specified deadline.

This means that if the Job is executed within the first 7 days (default) of its creation, no email will be sent. Otherwise, this task will notify the job author when its execution begins.

For this purpose, the client-side script reads a set of environment variables from the container, which must be specified in the Nomad Job.

  • NUM_DAYS: Number of days from which the notification will be sent by email (It has a default value of 7 days).

  • DATE: Date the nomad job was created.

  • DEST: Email address to notify the start of the Job execution.

  • BODY: Body of the mail.

  • SUBJECT: Subject of the mail.

  • MAILING_TOKEN: Must be the same on the client and server side.

The server side only needs the MAILING_TOKEN environment variable to work.

API

The server implements an API developed in python through FastApi. This API listens on port 8082. Once the service is up, the API specification can be accessed in /docs.

The status of the service can be checked through a GET request to the root route /. If the service is active, it should respond with the following message:

bash {"message": "Server is UP"}

Emails can be sent through a GET request to /notify with the following query params:

  • email: Email recipient.

  • body: Body of the mail.

  • subject: Subject of the mail.

  • token: Security token. Must be the same on the client and server side.

If the request is received correctly and the token is correct, the following message is returned

bash {"status": "ok", "message": "Notification sent successfully"}

Otherwise, if an incorrect token is sent, the following message is returned

bash {"status": "error", "message": "Invalid token, notification not sent"}

Exim4

Server is configured to send emails via exim4. The Docker image already has exim4 installed, but it needs to read the configuration files from the host machine, located in /etc/exim4.

For this purpose, it is necessary to mount the host configuration folder on the guest file system.

bash docker run ... -v /etc/exim4:/etc/exim4 ...

Note: The docker image already restarts the exim4 service after boot so it can use the new configuration files.

Important: If Docker was installed via Snap, it will not copy files from privileged directories when mounting, according to this issue.

At the moment, it is possible to copy the host configuration files to a non-privileged path.

Demo

Both the client and the server can be easily deployed locally using the scripts in the scripts folder.

To allow connectivity between containers, it is necessary to previously execute the following command:

bash docker network create --subnet=192.168.1.0/24 mailing_net

Containers can then be deployed by running launch_client.sh and launch_server.sh. Environment variables for each instance are specified through the vars.env file in the server and client folders. For example:

  • For the client container bash NUM_DAYS=7 DATE="2024-01-07T11:19:29.914177+01:00" DEST=test@email.com BODY="Body of the test mail" SUBJECT="Test mail" MAILING_TOKEN=1234

  • For the server container bash MAILING_TOKEN=1234

Depending on the Date variable, the email will be sent or not.

Owner

  • Name: AI4OS
  • Login: ai4os
  • Kind: organization
  • Email: ai4eosc-po@listas.csic.es

AI4OS is the software powering the AI4EOSC platform

GitHub Events

Total
Last Year

Dependencies

.github/workflows/build-docker-dev.yml actions
  • actions/checkout v3 composite
  • docker/build-push-action v3 composite
  • docker/login-action v2 composite
  • docker/setup-buildx-action v2 composite
client/Dockerfile docker
  • python 3.8-slim build
server/Dockerfile docker
  • python 3.8-slim build
server/requirements_server.txt pypi
  • fastapi >=0.68.0,<0.69.0
  • pydantic >=1.8.0,<2.0.0
  • python-dateutil >=2.4.1,<2.8.2
  • uvicorn >=0.15.0,<0.16.0