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 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'
|
COMPOSE = 'docker-compose -p feedati'
|
||||||
|
DOIT_CONFIG = {'default_tasks': ['up']}
|
||||||
|
|
||||||
|
|
||||||
def task_build():
|
def task_build():
|
||||||
|
@ -13,39 +14,40 @@ def task_build():
|
||||||
'uptodate': [up2date_anyimages],
|
'uptodate': [up2date_anyimages],
|
||||||
'file_dep': ['docker-compose.yml', 'docker/Dockerfile-tt-rss'],
|
'file_dep': ['docker-compose.yml', 'docker/Dockerfile-tt-rss'],
|
||||||
'actions': [COMPOSE + ' build'],
|
'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():
|
def task__build_rm():
|
||||||
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():
|
|
||||||
'''rimuove container avviati'''
|
'''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'''
|
'''rimuove immagini ottenute con build'''
|
||||||
return {
|
return {
|
||||||
'actions': [
|
'actions': [
|
||||||
r"docker images |"
|
r"docker images -q 'feedati/*' |"
|
||||||
"awk '$1 ~ /^feedati\// { print $3 }' | xargs -r "
|
"xargs -r --verbose docker rmi",
|
||||||
"docker rmi",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def task_dump_rm():
|
def task__dbprepare_clean():
|
||||||
'''rimuove il dump caricato sul db'''
|
'''rimuove il dump caricato sul db'''
|
||||||
return {
|
return {
|
||||||
'actions': [
|
'actions': [
|
||||||
"docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
|
"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",
|
"xargs -r docker container rm",
|
||||||
|
|
||||||
"docker volume rm feedati_postgres_data || true",
|
"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'''
|
'''applica il dump sql al container del db'''
|
||||||
return {
|
return {
|
||||||
'task_dep': ['dump_rm', 'build'],
|
'task_dep': ['_dbprepare_clean', 'build'],
|
||||||
'file_dep': ['docker/ttrss.sql'],
|
'file_dep': ['docker/ttrss.sql'],
|
||||||
'actions': [
|
'actions': [
|
||||||
(COMPOSE + ' up -d db').split(),
|
(COMPOSE + ' up -d db').split(),
|
||||||
|
@ -68,11 +70,12 @@ def task_dump_load():
|
||||||
'docker exec -t $(docker ps -qf name=feedati_db) '
|
'docker exec -t $(docker ps -qf name=feedati_db) '
|
||||||
'rm -f /tmp/ttrss.sql',
|
'rm -f /tmp/ttrss.sql',
|
||||||
COMPOSE + ' stop',
|
COMPOSE + ' stop',
|
||||||
]
|
],
|
||||||
|
'clean': [run_task_func(task__dbprepare_clean)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def task_fix_perms():
|
def task__fix_perms():
|
||||||
'''fix permissions for shared www dir'''
|
'''fix permissions for shared www dir'''
|
||||||
return {
|
return {
|
||||||
'actions': [
|
'actions': [
|
||||||
|
@ -83,8 +86,9 @@ def task_fix_perms():
|
||||||
|
|
||||||
|
|
||||||
def task_up():
|
def task_up():
|
||||||
|
'''RUN that stuff!'''
|
||||||
return {
|
return {
|
||||||
'task_dep': ['build', 'dump_load', 'fix_perms'],
|
'task_dep': ['build', 'dbprepare', '_fix_perms'],
|
||||||
'actions': [LongRunning(
|
'actions': [LongRunning(
|
||||||
(COMPOSE + ' up'),
|
(COMPOSE + ' up'),
|
||||||
shell=True)
|
shell=True)
|
||||||
|
@ -92,10 +96,10 @@ def task_up():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def task_cleanall():
|
def task__cleanall():
|
||||||
'''clean everything there is to clean'''
|
'''clean everything there is to clean'''
|
||||||
return {
|
return {
|
||||||
'task_dep': ['build_rm', 'build_rmi', 'dump_rm'],
|
'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
|
||||||
'actions': None
|
'actions': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from doit import loader
|
||||||
|
|
||||||
def wait_net_service(server, port, timeout=None):
|
def wait_net_service(server, port, timeout=None):
|
||||||
""" Wait for network service to appear
|
""" Wait for network service to appear
|
||||||
@param timeout: in seconds, if None or 0 wait forever
|
@param timeout: in seconds, if None or 0 wait forever
|
||||||
|
@ -44,3 +46,23 @@ def up2date_anyimages():
|
||||||
if output:
|
if output:
|
||||||
return True
|
return True
|
||||||
return False
|
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