123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import subprocess
- import os
- from doit.tools import LongRunning
- from dodo_utils import wait_net_service, wait_pgsql_db, \
- up2date_hasimage, 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',
- 'rss-bridge/Dockerfile',
- ] + [os.path.join('docker', fname)
- for fname in os.listdir('docker')],
- '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 ps -aqf name=feedati_db|xargs -r docker container rm ",
- "docker volume rm feedati_postgres_data || true",
- ]
- }
- def stop():
- subprocess.check_call((COMPOSE + ' stop').split())
- return True
- def task_dbprepare():
- '''applica il dump sql al container del db'''
- return {
- 'setup': ['_dbprepare_clean', 'build'],
- 'file_dep': ['docker/ttrss.sql'],
- 'actions': [
- (COMPOSE + ' up -d db').split(),
- (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',
- ],
- 'teardown': [(stop, [])],
- 'uptodate': [up2date_hasimage('feedati_postgres_data')()],
- 'clean': [run_task_func(task__dbprepare_clean)]
- }
- def task__fix_perms():
- '''fix permissions for shared www dir'''
- # currently empty, but keeping it for later use
- return {
- }
- def task_up():
- '''RUN that stuff!'''
- return {
- 'task_dep': ['build', 'dbprepare', '_fix_perms'],
- 'teardown': [(stop, [])],
- 'actions': [LongRunning(
- (COMPOSE + ' up').split(),
- shell=False)
- ]
- }
- def task__cleanall():
- '''clean everything there is to clean'''
- return {
- 'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
- 'actions': None
- }
|