2018-08-09 10:34:34 +02:00
|
|
|
import subprocess
|
2018-08-17 18:05:13 +02:00
|
|
|
import os
|
2018-08-09 10:34:34 +02:00
|
|
|
|
|
|
|
from doit.tools import LongRunning
|
|
|
|
|
2018-08-09 17:37:25 +02:00
|
|
|
from dodo_utils import wait_net_service, wait_pgsql_db, \
|
|
|
|
up2date_hasimage, up2date_anyimages, \
|
|
|
|
run_task_func
|
2018-08-09 10:34:34 +02:00
|
|
|
|
|
|
|
COMPOSE = 'docker-compose -p feedati'
|
2018-08-09 13:17:39 +02:00
|
|
|
DOIT_CONFIG = {'default_tasks': ['up']}
|
2018-08-09 10:34:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def task_build():
|
|
|
|
'''builda il container docker'''
|
|
|
|
return {
|
|
|
|
'uptodate': [up2date_anyimages],
|
2018-08-17 18:05:13 +02:00
|
|
|
'file_dep': ['docker-compose.yml',
|
|
|
|
'rss-bridge/Dockerfile',
|
|
|
|
] + [os.path.join('docker', fname)
|
|
|
|
for fname in os.listdir('docker')],
|
2018-08-09 10:34:34 +02:00
|
|
|
'actions': [COMPOSE + ' build'],
|
2018-08-10 02:27:17 +02:00
|
|
|
'clean': [run_task_func(task__build_rm),
|
|
|
|
run_task_func(task__build_rmi)],
|
2018-08-09 13:17:39 +02:00
|
|
|
'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`.
|
|
|
|
'''
|
2018-08-09 10:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task__build_rm():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''rimuove container avviati'''
|
2018-08-09 13:17:39 +02:00
|
|
|
return {'actions': [
|
|
|
|
"docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
|
|
|
|
"awk '$2 ~ /^feedati_/ { print $1 }' | "
|
|
|
|
"xargs -r docker container rm",
|
|
|
|
]}
|
2018-08-09 10:34:34 +02:00
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task__build_rmi():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''rimuove immagini ottenute con build'''
|
|
|
|
return {
|
|
|
|
'actions': [
|
2018-08-09 13:17:39 +02:00
|
|
|
r"docker images -q 'feedati/*' |"
|
|
|
|
"xargs -r --verbose docker rmi",
|
2018-08-09 10:34:34 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task__dbprepare_clean():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''rimuove il dump caricato sul db'''
|
|
|
|
return {
|
|
|
|
'actions': [
|
2018-08-09 17:37:25 +02:00
|
|
|
"docker ps -aqf name=feedati_db|xargs -r docker container rm ",
|
2018-08-09 10:34:34 +02:00
|
|
|
|
|
|
|
"docker volume rm feedati_postgres_data || true",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-09 17:37:25 +02:00
|
|
|
def stop():
|
|
|
|
subprocess.check_call((COMPOSE + ' stop').split())
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task_dbprepare():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''applica il dump sql al container del db'''
|
|
|
|
return {
|
2018-08-09 17:37:25 +02:00
|
|
|
'setup': ['_dbprepare_clean', 'build'],
|
2018-08-09 10:34:34 +02:00
|
|
|
'file_dep': ['docker/ttrss.sql'],
|
|
|
|
'actions': [
|
|
|
|
(COMPOSE + ' up -d db').split(),
|
2018-08-09 17:37:25 +02:00
|
|
|
(wait_net_service, ('localhost', 5432, 300)),
|
|
|
|
(wait_pgsql_db, ('feedati_db', 'ttrss', 'ttrss')),
|
|
|
|
'echo LOADING DB',
|
|
|
|
r'docker exec -i $(docker ps -aqf name=feedati_db) '
|
|
|
|
'psql -h 127.0.0.1 -f - -d ttrss ttrss < docker/ttrss.sql',
|
|
|
|
'echo DB RESTORED',
|
2018-08-09 13:17:39 +02:00
|
|
|
],
|
2018-08-09 17:37:25 +02:00
|
|
|
'teardown': [(stop, [])],
|
|
|
|
'uptodate': [up2date_hasimage('feedati_postgres_data')()],
|
2018-08-09 13:17:39 +02:00
|
|
|
'clean': [run_task_func(task__dbprepare_clean)]
|
2018-08-09 10:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task__fix_perms():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''fix permissions for shared www dir'''
|
2018-08-19 14:57:31 +02:00
|
|
|
# currently empty, but keeping it for later use
|
2018-08-09 10:34:34 +02:00
|
|
|
return {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def task_up():
|
2018-08-09 13:17:39 +02:00
|
|
|
'''RUN that stuff!'''
|
2018-08-09 10:34:34 +02:00
|
|
|
return {
|
2018-08-09 13:17:39 +02:00
|
|
|
'task_dep': ['build', 'dbprepare', '_fix_perms'],
|
2018-08-09 17:55:12 +02:00
|
|
|
'teardown': [(stop, [])],
|
2018-08-09 10:34:34 +02:00
|
|
|
'actions': [LongRunning(
|
2018-08-09 17:55:12 +02:00
|
|
|
(COMPOSE + ' up').split(),
|
|
|
|
shell=False)
|
2018-08-09 10:34:34 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-09 13:17:39 +02:00
|
|
|
def task__cleanall():
|
2018-08-09 10:34:34 +02:00
|
|
|
'''clean everything there is to clean'''
|
|
|
|
return {
|
2018-08-09 13:17:39 +02:00
|
|
|
'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
|
2018-08-09 10:34:34 +02:00
|
|
|
'actions': None
|
|
|
|
}
|
|
|
|
|