Feedati/dodo.py
boyska 0ff7263d8e 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)
2018-08-09 13:17:39 +02:00

105 lines
3 KiB
Python

import subprocess
from doit.tools import LongRunning
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():
'''builda il container docker'''
return {
'uptodate': [up2date_anyimages],
'file_dep': ['docker-compose.yml', 'docker/Dockerfile-tt-rss'],
'actions': [COMPOSE + ' 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 task__build_rm():
'''rimuove container avviati'''
return {'actions': [
"docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
"awk '$2 ~ /^feedati_/ { print $1 }' | "
"xargs -r docker container rm",
]}
def task__build_rmi():
'''rimuove immagini ottenute con build'''
return {
'actions': [
r"docker images -q 'feedati/*' |"
"xargs -r --verbose docker rmi",
]
}
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 }' | "
"xargs -r docker container rm",
"docker volume rm feedati_postgres_data || true",
]
}
def task_dbprepare():
'''applica il dump sql al container del db'''
return {
'task_dep': ['_dbprepare_clean', 'build'],
'file_dep': ['docker/ttrss.sql'],
'actions': [
(COMPOSE + ' up -d db').split(),
r'docker cp ./docker/ttrss.sql '
'$(docker ps -qf name=feedati_db):/tmp/ttrss.sql',
(wait_net_service, ['localhost', 5432, 300]),
r'docker exec -t $(docker ps -qf name=feedati_db) '
'su -c "psql -d ttrss < /tmp/ttrss.sql" postgres',
'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():
'''fix permissions for shared www dir'''
return {
'actions': [
'chmod -R 777 tt-rss/feed-icons/ tt-rss/cache/ tt-rss/lock/'
.split()
]
}
def task_up():
'''RUN that stuff!'''
return {
'task_dep': ['build', 'dbprepare', '_fix_perms'],
'actions': [LongRunning(
(COMPOSE + ' up'),
shell=True)
]
}
def task__cleanall():
'''clean everything there is to clean'''
return {
'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
'actions': None
}