Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. DIR=$(strip $(notdir $(CURDIR))) # Seems a bit hack-ish, but `basename` works differently
  2. translate-container-name = $$(if docker container inspect $(1) > /dev/null 2>&1; then echo $(1); else echo $(1) | sed 'y/_/-/' ; fi)
  3. args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}`
  4. %:
  5. @:
  6. .PHONY:
  7. @if ! docker info > /dev/null; then echo "Docker does not seem to be running"; exit 1; fi
  8. up: .PHONY
  9. docker-compose up -d
  10. down: .PHONY
  11. docker-compose down
  12. redis-shell:
  13. docker exec -it $(call translate-container-name,$(strip $(DIR))_redis_1) sh -c 'redis-cli'
  14. php-repl: .PHONY
  15. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c '/var/www/social/bin/console psysh'
  16. php-shell: .PHONY
  17. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c 'cd /var/www/social; sh'
  18. psql-shell: .PHONY
  19. docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) sh -c "psql -U postgres social"
  20. database-force-nuke:
  21. docker stop $(call translate-container-name,$(strip $(DIR))_worker_1) \
  22. && docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c "cd /var/www/social; bin/console doctrine:database:drop --force && bin/console doctrine:database:create && bin/console doctrine:schema:update --dump-sql --force && bin/console app:populate_initial_values" \
  23. && docker-compose up -d
  24. database-force-schema-update:
  25. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c "/var/www/social/bin/console doctrine:schema:update --dump-sql --force"
  26. tooling-docker: .PHONY
  27. @cd docker/tooling && docker-compose up -d --build > /dev/null 2>&1
  28. stop-tooling: .PHONY
  29. cd docker/tooling && docker-compose down
  30. tooling-php-shell: tooling-docker
  31. docker exec -it $(call translate-container-name,tooling_php_1) sh
  32. test-accesibility: tooling-docker
  33. cd docker/tooling && docker-compose run pa11y /accessibility.sh
  34. test: tooling-docker
  35. docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'')
  36. cs-fixer: tooling-docker
  37. @bin/php-cs-fixer $${CS_FIXER_FILE}
  38. doc-check: tooling-docker
  39. bin/php-doc-check
  40. phpstan: tooling-docker
  41. bin/phpstan
  42. remove-var:
  43. rm -rf var/*
  44. remove-file:
  45. sudo rm -rf file/*
  46. flush-redis-cache:
  47. docker exec -it $(call translate-container-name,$(strip $(DIR))_redis_1) sh -c 'redis-cli flushall'
  48. install-plugins:
  49. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) /var/www/social/bin/install_plugins.sh
  50. update-dependencies:
  51. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c 'cd /var/www/social && composer update'
  52. update-autocode:
  53. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c 'cd /var/www/social && bin/update_autocode'
  54. backup-actors:
  55. docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) \
  56. sh -c 'su postgres -c "mkdir -p /tmp/backup"' && \
  57. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) \
  58. sh -c "cd /var/www/social && bin/console doctrine:query:sql \"\
  59. copy actor to '/tmp/backup/actor.csv';\
  60. copy local_user to '/tmp/backup/local_user.csv';\
  61. copy local_group to '/tmp/backup/local_group.csv';\
  62. \
  63. copy activitypub_actor to '/tmp/backup/ap_actor.csv';\
  64. copy activitypub_rsa to '/tmp/backup/ap_rsa.csv';\
  65. \
  66. copy actor_subscription to '/tmp/backup/actor_subscription.csv';\
  67. copy group_member to '/tmp/backup/group_member.csv';\
  68. \
  69. copy feed to '/tmp/backup/feed.csv';\
  70. copy (SELECT 'ALTER SEQUENCE ' || c.relname || ' RESTART WITH ' || nextval(c.relname::regclass) || ';'\
  71. FROM pg_class c WHERE c.relkind = 'S') to '/tmp/backup/sequences';\"" && \
  72. mkdir -p /tmp/social-sql-backup && \
  73. docker cp $(call translate-container-name,$(strip $(DIR))_db_1):/tmp/backup/. /tmp/social-sql-backup
  74. restore-actors:
  75. docker cp /tmp/social-sql-backup/. $(call translate-container-name,$(strip $(DIR))_db_1):/tmp/backup
  76. docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) sh -c 'chown postgres /tmp/backup' && \
  77. docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) \
  78. sh -c "cd /var/www/social && bin/console doctrine:query:sql \"\
  79. copy actor from '/tmp/backup/actor.csv';\
  80. copy local_user from '/tmp/backup/local_user.csv';\
  81. copy local_group from '/tmp/backup/local_group.csv';\
  82. \
  83. copy activitypub_actor from '/tmp/backup/ap_actor.csv';\
  84. copy activitypub_rsa from '/tmp/backup/ap_rsa.csv';\
  85. \
  86. copy actor_subscription from '/tmp/backup/actor_subscription.csv';\
  87. copy group_member from '/tmp/backup/group_member.csv';\
  88. \
  89. copy feed from '/tmp/backup/feed.csv';\
  90. `cat /tmp/social-sql-backup/sequences`\""
  91. force-nuke-everything: down remove-var remove-file up flush-redis-cache database-force-nuke install-plugins
  92. force-delete-content: backup-actors force-nuke-everything restore-actors