dodo.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import subprocess
  2. from doit.tools import LongRunning
  3. from dodo_utils import wait_net_service, wait_pgsql_db, \
  4. up2date_hasimage, up2date_anyimages, \
  5. run_task_func
  6. COMPOSE = 'docker-compose -p feedati'
  7. DOIT_CONFIG = {'default_tasks': ['up']}
  8. def task_build():
  9. '''builda il container docker'''
  10. return {
  11. 'uptodate': [up2date_anyimages],
  12. 'file_dep': ['docker-compose.yml', 'docker/Dockerfile-tt-rss',
  13. 'docker/ttrss-openrc-apache',
  14. 'docker/ttrss-openrc-ttrssupdate',
  15. 'rss-bridge/Dockerfile'
  16. ],
  17. 'actions': [COMPOSE + ' build'],
  18. 'clean': [run_task_func(task__build_rm),
  19. run_task_func(task__build_rmi)],
  20. 'doc': '''
  21. This task recreates every docker container. While it is automatically run for most changes in the
  22. development environment, please remember that if you want to run it manually to grab changes in the
  23. docker hub, you need to run `doit run -a build`.
  24. '''
  25. }
  26. def task__build_rm():
  27. '''rimuove container avviati'''
  28. return {'actions': [
  29. "docker container ls -a --format '{{.ID}}\t{{.Names}}'|"
  30. "awk '$2 ~ /^feedati_/ { print $1 }' | "
  31. "xargs -r docker container rm",
  32. ]}
  33. def task__build_rmi():
  34. '''rimuove immagini ottenute con build'''
  35. return {
  36. 'actions': [
  37. r"docker images -q 'feedati/*' |"
  38. "xargs -r --verbose docker rmi",
  39. ]
  40. }
  41. def task__dbprepare_clean():
  42. '''rimuove il dump caricato sul db'''
  43. return {
  44. 'actions': [
  45. "docker ps -aqf name=feedati_db|xargs -r docker container rm ",
  46. "docker volume rm feedati_postgres_data || true",
  47. ]
  48. }
  49. def stop():
  50. subprocess.check_call((COMPOSE + ' stop').split())
  51. return True
  52. def task_dbprepare():
  53. '''applica il dump sql al container del db'''
  54. return {
  55. 'setup': ['_dbprepare_clean', 'build'],
  56. 'file_dep': ['docker/ttrss.sql'],
  57. 'actions': [
  58. (COMPOSE + ' up -d db').split(),
  59. (wait_net_service, ('localhost', 5432, 300)),
  60. (wait_pgsql_db, ('feedati_db', 'ttrss', 'ttrss')),
  61. 'echo LOADING DB',
  62. r'docker exec -i $(docker ps -aqf name=feedati_db) '
  63. 'psql -h 127.0.0.1 -f - -d ttrss ttrss < docker/ttrss.sql',
  64. 'echo DB RESTORED',
  65. ],
  66. 'teardown': [(stop, [])],
  67. 'uptodate': [up2date_hasimage('feedati_postgres_data')()],
  68. 'clean': [run_task_func(task__dbprepare_clean)]
  69. }
  70. def task__fix_perms():
  71. '''fix permissions for shared www dir'''
  72. return {
  73. 'actions': [
  74. 'chmod -R 777 tt-rss/feed-icons/ || true'
  75. ]
  76. }
  77. def task_up():
  78. '''RUN that stuff!'''
  79. return {
  80. 'task_dep': ['build', 'dbprepare', '_fix_perms'],
  81. 'teardown': [(stop, [])],
  82. 'actions': [LongRunning(
  83. (COMPOSE + ' up').split(),
  84. shell=False)
  85. ]
  86. }
  87. def task__cleanall():
  88. '''clean everything there is to clean'''
  89. return {
  90. 'task_dep': ['_build_rm', '_build_rmi', '_dbprepare_clean'],
  91. 'actions': None
  92. }