mirror of
https://github.com/PAPAMICA/docker-compose-collection.git
synced 2026-01-18 16:27:25 +01:00
Création d'un script interactif pour générer les docker-compose (#7)
* Fichier Nix avec dépendances * Ignorer les fichiers logs * Création template Jinja2+script * Gestion des volumes * Corrections mineures et gestion de la description * Ajout de la date et corrections dans la template * Librairie request inutile dans cas (un oubli) * Remplacement du nom du conteneur par app_name en lowercase * Lien officiel devenu dépot github * Utilisation du Container_name * Ajout du champ container_name * Pas de logger pour le moment * Filtre lower pour le container_name * Forcer le fichier en lowercase * Changement format date * Filtre lower à chaque app_name * Usage de la envvar dans le container_name Co-authored-by: QJoly <qjoly@users.noreply.github.com>
This commit is contained in:
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
debug.log
|
||||
72
app/app.py
Executable file
72
app/app.py
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys, logging, jinja2
|
||||
from datetime import date
|
||||
|
||||
#logging.basicConfig(filename='debug.log', encoding='utf-8', level=logging.DEBUG)
|
||||
#logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
|
||||
def volumlist():
|
||||
volumlist = []
|
||||
volume_name = "Nothing"
|
||||
while volume_name != "":
|
||||
volume_name = input("Enter volume name or press enter to exit : ")
|
||||
if volume_name != "":
|
||||
volume_dir = input("Enter the directory mounted inside the container : ")
|
||||
volumlist.append(f"{volume_name}:{volume_dir}")
|
||||
print(volumlist)
|
||||
return volumlist
|
||||
|
||||
def envvar():
|
||||
envvar = []
|
||||
variable = "Nothing"
|
||||
while variable != "":
|
||||
variable = input("Enter environment variable or press enter to exit : ")
|
||||
if variable != "":
|
||||
envvar.append(variable)
|
||||
print(envvar)
|
||||
return envvar
|
||||
|
||||
app_name = input("App's name : ")
|
||||
app_logo = input("App's logo (url) : ")
|
||||
app_image = input("App's Docker image : ")
|
||||
app_port = input("App's port : ")
|
||||
app_url = input("App's official github repo : ")
|
||||
app_description = input("App's description : ")
|
||||
maintainer_name = input("Maintainer's name : ")
|
||||
maintainer_github = input("Maintainer's github profile : ")
|
||||
#app_name = "Ampache"
|
||||
#app_logo = "https://ampache.org/img/logo/ampache-logo.png"
|
||||
#app_image = "ampache/ampache:latest"
|
||||
#app_port = "80"
|
||||
#app_url = "https://github.com/ampache/ampache-docker"
|
||||
#app_description = "web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any internet enabled device."
|
||||
#maintainer_name = "Quentin JOLY"
|
||||
#maintainer_github = "@QJoly"
|
||||
envvar = envvar()
|
||||
volumlist = volumlist()
|
||||
|
||||
data = {
|
||||
'app_name' : app_name,
|
||||
'app_logo' : app_logo,
|
||||
'app_image' : app_image,
|
||||
'app_port' : app_port,
|
||||
'app_url' : app_url,
|
||||
'app_description' : app_description,
|
||||
'maintainer_name' : maintainer_name,
|
||||
'maintainer_github' : maintainer_github,
|
||||
'envvar' : envvar,
|
||||
'volumlist' : volumlist,
|
||||
'update_date' : date.today().strftime("%Y-%m-%d")
|
||||
}
|
||||
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "template.yml.j2"
|
||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||
outputText = template.render(data)
|
||||
|
||||
output = open(f"./{app_name}.yml".lower(), "w")
|
||||
output.write(outputText)
|
||||
output.close()
|
||||
|
||||
14
app/default.nix
Normal file
14
app/default.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
# default.nix
|
||||
with (import <nixpkgs> {});
|
||||
let
|
||||
python-packages = python-packages: with python-packages; [
|
||||
jinja2
|
||||
];
|
||||
python-with-packages = python39.withPackages python-packages;
|
||||
in
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
python-with-packages
|
||||
python39Packages.pip
|
||||
];
|
||||
}
|
||||
57
app/template.yml.j2
Normal file
57
app/template.yml.j2
Normal file
@@ -0,0 +1,57 @@
|
||||
# Maintainer: {{ maintainer_name }} - {{ maintainer_github }}
|
||||
# Update: {{ update_date }}
|
||||
|
||||
#& type: 3
|
||||
#& title: {{ app_name }}
|
||||
#& description: {{ app_description }}
|
||||
#& note: Website: <a href='{{ app_url }}' target='_blank' rel='noopener'>Github.com</a>
|
||||
#& categories: SelfHosted, PAPAMICA
|
||||
#& platform: linux
|
||||
#& logo: {{ app_logo }}
|
||||
|
||||
#% SERVICE: Name of the service (No spaces or points) [{{ app_name|lower }}]
|
||||
#% DATA_LOCATION: Data localization (Example: /apps/service) [/_data/apps]
|
||||
#% URL: Service URL (Example: service.papamica.fr or service.com)
|
||||
#% NETWORK: Your Traefik network (Example: proxy) [proxy]
|
||||
|
||||
# Work with Portainer
|
||||
version: '3.8'
|
||||
services:
|
||||
{{ app_name|lower }}:
|
||||
image: {{ app_image }}
|
||||
{%- if volumlist is defined and envvar|length > 0 -%} volumes:{%- endif -%}
|
||||
{%- for var in volumlist %}
|
||||
{%- if not loop.last %}
|
||||
- $DATA_LOCATION/$SERVICE/{{ var }}
|
||||
{%- endif %}
|
||||
{%- if loop.last %}
|
||||
- $DATA_LOCATION/$SERVICE/{{ var }}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
{%- if envvar is defined and envvar|length > 0 -%} environment:{%- endif -%}
|
||||
{%- for var in envvar %}
|
||||
{%- if not loop.last %}
|
||||
- {{ var }}
|
||||
{%- endif %}
|
||||
{%- if loop.last %}
|
||||
- {{ var }}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
healthcheck:
|
||||
test: wget -s 'http://localhost:{{ app_port }}'
|
||||
interval: 1m
|
||||
timeout: 30s
|
||||
retries: 3
|
||||
container_name: $SERVICE
|
||||
networks:
|
||||
- default
|
||||
labels:
|
||||
- "autoupdate=monitor" # https://github.com/PAPAMICA/container-updater
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.$SERVICE.entrypoints=https"
|
||||
- "traefik.http.routers.$SERVICE.rule=Host(`$URL`)"
|
||||
- "traefik.http.routers.$SERVICE.tls.certresolver=http"
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: $NETWORK
|
||||
Reference in New Issue
Block a user