forked from ynput/ayon-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
119 lines (92 loc) · 3.33 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#
# Settings
#
SETTINGS_FILE=settings/template.json
IMAGE_NAME=ynput/ayon
SERVER_CONTAINER=server
TAG=dev
#
# Variables
#
# Abstract the 'docker compose' / 'docker-compose' command
COMPOSE=$(shell which docker-compose || echo "docker compose")
# Shortcut for the setup command
SETUP_CMD=$(COMPOSE) exec -T $(SERVER_CONTAINER) python -m setup
# By default, just show the usage message
default:
@echo ""
@echo "Ayon server $(TAG)"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Runtime targets:"
@echo " setup Apply settings template form the settings/template.json"
@echo " dbshell Open a PostgreSQL shell"
@echo " reload Reload the running server"
@echo " demo Create demo projects based on settings in demo directory"
@echo " dump Use 'make dump projectname=<projectname>' to backup a project"
@echo " restore Use 'make restore projectname=<projectname>' to restore a project from previous dump"
@echo ""
@echo "Development:"
@echo " backend Download / update backend"
@echo " frontend Download / update frontend"
@echo " build Build docker image"
@echo " dist Publish docker image to docker hub"
.PHONY: backend frontend build demo
# Makefile syntax, oh so bad
# Errors abound, frustration high
# Gotta love makefiles
setup:
ifneq (,"$(wildcard ./settings/template.json)")
$(SETUP_CMD) - < $(SETTINGS_FILE)
else
$(SETUP_CMD)
endif
@$(COMPOSE) exec $(SERVER_CONTAINER) ./reload.sh
dbshell:
@$(COMPOSE) exec postgres psql -U ayon ayon
reload:
@$(COMPOSE) exec $(SERVER_CONTAINER) ./reload.sh
demo:
$(foreach file, $(wildcard demo/*.json), $(COMPOSE) exec -T $(SERVER_CONTAINER) python -m demogen < $(file);)
links:
$(foreach file, $(wildcard demo/*.json), $(COMPOSE) exec -T $(SERVER_CONTAINER) python -m linker < $(file);)
update:
docker pull $(IMAGE_NAME):$(TAG)
$(COMPOSE) up --detach --build $(SERVER_CONTAINER)
dump:
@if [ -z "$(projectname)" ]; then \
echo "Error: Project name is required. Usage: make dump projectname=<projectname>"; \
exit 1; \
fi
echo "DROP SCHEMA IF EXISTS project_$(projectname) CASCADE;" > dump.$(projectname).sql
echo "DELETE FROM public.projects WHERE name = '$(projectname)';" >> dump.$(projectname).sql
docker compose exec -t postgres pg_dump --table=public.projects --column-inserts ayon -U ayon | grep "^INSERT INTO" | grep \'$(projectname)\' >> dump.$(projectname).sql
docker compose exec postgres pg_dump --schema=project_$(projectname) ayon -U ayon >> dump.$(projectname).sql
restore:
@if [ -z "$(projectname)" ]; then \
echo "Error: Project name is required. Usage: make dump projectname=<projectname>"; \
exit 1; \
fi
@if [ ! -f dump.$(projectname).sql ]; then \
echo "Error: Dump file dump.$(projectname).sql not found"; \
exit 1; \
fi
docker compose exec -T postgres psql -U ayon ayon < dump.$(projectname).sql
#
# The following targets are for development purposes only.
#
build: backend frontend
@# Build the docker image
docker build -t $(IMAGE_NAME):$(TAG) .
dist: build
@# Publish the docker image to the registry
docker push $(IMAGE_NAME):$(TAG)
backend:
@# Clone / update the backend repository
@[ -d $@ ] || git clone https://github.com/ynput/ayon-backend $@
@cd $@ && git pull
frontend:
@# Clone / update the frontend repository
@[ -d $@ ] || git clone https://github.com/ynput/ayon-frontend $@
@cd $@ && git pull