forked from blallo/Feedati
doit: reorganization
- default task (up) - automatic clean actions: doit clean -a now works! - FIX some commands (shell errors in clean actions) - private tasks (doit list is not a mess anymore; doit list -p is)
This commit is contained in:
parent
96c225da50
commit
0ff7263d8e
2 changed files with 50 additions and 24 deletions
52
dodo.py
52
dodo.py
|
@ -2,9 +2,10 @@ import subprocess
|
|||
|
||||
from doit.tools import LongRunning
|
||||
|
||||
from dodo_utils import wait_net_service, up2date_anyimages
|
||||
from dodo_utils import wait_net_service, up2date_anyimages, run_task_func
|
||||
|
||||
COMPOSE = 'docker-compose -p feedati'
|
||||
DOIT_CONFIG = {'default_tasks': ['up']}
|
||||
|
||||
|
||||
def task_build():
|
||||
|
@ -13,39 +14,40 @@ def task_build():
|
|||
'uptodate': [up2date_anyimages],
|
||||
'file_dep': ['docker-compose.yml', 'docker/Dockerfile-tt-rss'],
|
||||
'actions': [COMPOSE + ' build'],
|
||||
'clean': [remove_build],
|
||||
'clean': [run_task_func(task__build_rm), run_task_func(task__build_rmi)],
|
||||
'doc': '''
|
||||
This task recreates every docker container. While it is automatically run for most changes in the
|
||||
development environment, please remember that if you want to run it manually to grab changes in the
|
||||
docker hub, you need to run `doit run -a build`.
|
||||
'''
|
||||
}
|
||||
|
||||
|
||||
def remove_build():
|
||||
cmd = "docker container ls -a --format '{{.ID}}\t{{.Names}}'|" \
|
||||
"awk '$2 ~ /feedati_/ { print $$1 }' | " \
|
||||
"xargs -r docker container rm",
|
||||
subprocess.check_call(cmd, shell=True)
|
||||
|
||||
|
||||
def task_build_rm():
|
||||
def task__build_rm():
|
||||
'''rimuove container avviati'''
|
||||
return {'actions': [remove_build]}
|
||||
return {'actions': [
|
||||
"docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
|
||||
"awk '$2 ~ /^feedati_/ { print $1 }' | "
|
||||
"xargs -r docker container rm",
|
||||
]}
|
||||
|
||||
|
||||
def task_build_rmi():
|
||||
def task__build_rmi():
|
||||
'''rimuove immagini ottenute con build'''
|
||||
return {
|
||||
'actions': [
|
||||
r"docker images |"
|
||||
"awk '$1 ~ /^feedati\// { print $3 }' | xargs -r "
|
||||
"docker rmi",
|
||||
r"docker images -q 'feedati/*' |"
|
||||
"xargs -r --verbose docker rmi",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def task_dump_rm():
|
||||
def task__dbprepare_clean():
|
||||
'''rimuove il dump caricato sul db'''
|
||||
return {
|
||||
'actions': [
|
||||
"docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
|
||||
"awk '$2 ~ /^feedati_db { print $$1 }' | "
|
||||
"awk '$2 ~ /^feedati_db$/ { print $$1 }' | "
|
||||
"xargs -r docker container rm",
|
||||
|
||||
"docker volume rm feedati_postgres_data || true",
|
||||
|
@ -53,10 +55,10 @@ def task_dump_rm():
|
|||
}
|
||||
|
||||
|
||||
def task_dump_load():
|
||||
def task_dbprepare():
|
||||
'''applica il dump sql al container del db'''
|
||||
return {
|
||||
'task_dep': ['dump_rm', 'build'],
|
||||
'task_dep': ['_dbprepare_clean', 'build'],
|
||||
'file_dep': ['docker/ttrss.sql'],
|
||||
'actions': [
|
||||
(COMPOSE + ' up -d db').split(),
|
||||
|
@ -68,11 +70,12 @@ def task_dump_load():
|
|||
'docker exec -t $(docker ps -qf name=feedati_db) '
|
||||
'rm -f /tmp/ttrss.sql',
|
||||
COMPOSE + ' stop',
|
||||
]
|
||||
],
|
||||
'clean': [run_task_func(task__dbprepare_clean)]
|
||||
}
|
||||
|
||||
|
||||
def task_fix_perms():
|
||||
def task__fix_perms():
|
||||
'''fix permissions for shared www dir'''
|
||||
return {
|
||||
'actions': [
|
||||
|
@ -83,8 +86,9 @@ def task_fix_perms():
|
|||
|
||||
|
||||
def task_up():
|
||||
'''RUN that stuff!'''
|
||||
return {
|
||||
'task_dep': ['build', 'dump_load', 'fix_perms'],
|
||||
'task_dep': ['build', 'dbprepare', '_fix_perms'],
|
||||
'actions': [LongRunning(
|
||||
(COMPOSE + ' up'),
|
||||
shell=True)
|
||||
|
@ -92,10 +96,10 @@ def task_up():
|
|||
}
|
||||
|
||||
|
||||
def task_cleanall():
|
||||
def task__cleanall():
|
||||
'''clean everything there is to clean'''
|
||||
return {
|
||||
'task_dep': ['build_rm', 'build_rmi', 'dump_rm'],
|
||||
'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
|
||||
'actions': None
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import subprocess
|
||||
|
||||
from doit import loader
|
||||
|
||||
def wait_net_service(server, port, timeout=None):
|
||||
""" Wait for network service to appear
|
||||
@param timeout: in seconds, if None or 0 wait forever
|
||||
|
@ -44,3 +46,23 @@ def up2date_anyimages():
|
|||
if output:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def run(cmd, **kwargs):
|
||||
def fun():
|
||||
subprocess.check_call(cmd, **kwargs)
|
||||
return True
|
||||
return fun
|
||||
|
||||
|
||||
def run_task_func(taskf):
|
||||
ret = taskf()
|
||||
tasks = loader.generate_tasks(taskf.__name__, ret, taskf.__doc__)
|
||||
|
||||
def fun():
|
||||
for task in tasks:
|
||||
task.execute()
|
||||
return True
|
||||
if tasks:
|
||||
fun.__doc__ = '\n'.join(t.doc for t in tasks)
|
||||
return fun
|
||||
|
|
Reference in a new issue