diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 4851bcb..6e8d366 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -39,7 +39,6 @@ jobs: tags: ${{ secrets.DOCKER_HUB_REPOSITORY }}:latest cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - build-args: token=${{ secrets.DISCORD_TOKEN }} - name: Image digest diff --git a/Dockerfile b/Dockerfile index 4470087..85b536e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,16 @@ -# Light based python image FROM python:3.9-alpine +# Git is required for requirements.txt +RUN apk update +RUN apk add git + # Work in /app for the application from container WORKDIR /app # Copy actual directory in /app COPY . . -# Read token from argument -ARG token -# Define an environnement Variable -ENV JETON=${token} - # run necessary command to install all modules RUN pip install -r requirements.txt - +RUN pip install git+https://github.com/Pycord-Development/pycord # run trema -CMD python -u trema.py -j ${JETON} \ No newline at end of file +CMD python -u trema.py \ No newline at end of file diff --git a/README.md b/README.md index 836b972..f32aedd 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,20 @@ données. ### Lancement de Trëma -Lancez le robot en ligne de commande en lui donnant son jeton -d'authentification. +Définissez la variable d'environnement suivante : +- DISCORD_TOKEN : Discord bot token + +Installer les dépendances en ligne de commande. + +```bash +pip install -r requirements.txt +pip install git+https://github.com/Pycord-Development/pycord +``` + +Lancez le robot en ligne de commande. ```bash -python trema.py -j [jeton] +python trema.py ``` ## Docker @@ -63,7 +72,7 @@ Se placer à la racine du projet. Exectuer la commande suivante : ```bash -docker build -t trema --build-arg token= . +docker build -t trema . ``` ### Lancer l'image @@ -92,5 +101,4 @@ pytest -v ./tests/[nom du fichier].py Pour lancer un seul test d'un fichier, lancez la commande suivante. ``` -pytest -v ./tests/[nom du fichier].py::[nom de la fonction] - +pytest -v ./tests/[nom du fichier].py::[nom de la fonction] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e7f9c28..42c21c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ jsonschema==4.7.2 -py-cord==2.0.0b7 pymongo==4.1.1 pytest~=7.2.0 discord~=2.1.0 \ No newline at end of file diff --git a/trema.py b/trema.py index 8b0977a..ef805a9 100644 --- a/trema.py +++ b/trema.py @@ -3,9 +3,9 @@ Discord des clubs étudiants de l'ÉTS. """ - -from argparse import ArgumentParser +import os import discord +import sys from events import\ create_event_reactions @@ -16,21 +16,12 @@ from trema_database import\ get_trema_database - -def _make_arg_parser(): - parser = ArgumentParser(description=__doc__) - parser.add_argument("-j", "--jeton", type=str, - help="Le jeton d'authentification de ce robot logiciel") - return parser - - -arg_parser = _make_arg_parser() -args = arg_parser.parse_args() - -bot_token = args.jeton +bot_token = os.getenv('DISCORD_TOKEN') +if not bot_token: + print('ERROR: Token var is missing: DISCORD_TOKEN') + sys.exit(-1) intents = discord.Intents.default() -intents.members = True trema = discord.Bot(intents=intents)