This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
147 lines (110 loc) · 5.44 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
.PHONY: all provision test clean help
KOHAENV ?= build
ifdef VAGRANT
CMD=vagrant ssh $(SHIP)
KOHAPATH=/vagrant
HOST ?= 192.168.50.1
DOCKER_GW=$(HOST)
else
CMD=bash
KOHAPATH=$(shell pwd)
VAGRANT=true
HOST ?= localhost
DOCKER_GW=172.19.0.1
VAGRANT=false
endif
COMPOSE=cd $(KOHAPATH)/docker-compose && source docker-compose.env && KOHAPATH=$(KOHAPATH) docker-compose -f common.yml -f $(KOHAENV).yml
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
all: halt provision ## Reloads and runs full provisioning
halt: ## Takes down all docker containers and network
@$(VAGRANT) && vagrant halt || true
@$(VAGRANT) || sudo $(CMD) -c "$(COMPOSE) down" || true
provision: ## Full provision - sets up docker and compose and all docker containers
@$(VAGRANT) && vagrant provision --provision-with shell || true
-@$(VAGRANT) || ./provision.sh $(KOHAENV) $(KOHAPATH)
up: ## Sets up all docker containers
@$(VAGRANT) && vagrant up || true
@$(VAGRANT) || sudo $(CMD) -c "$(COMPOSE) up -d" || true
wait_until_ready:
@echo "======= wait until ready ======\n"
$(CMD) -c 'docker exec -i koha_$(KOHAENV) ./wait_until_ready.py'
rebuild: ## Build and start Koha
@echo "======= FORCE RECREATING koha ======\n"
$(CMD) -c "$(COMPOSE) stop koha_$(KOHAENV) && true &&\
$(COMPOSE) rm -f koha_$(KOHAENV) || true &&\
$(COMPOSE) build koha_$(KOHAENV) &&\
$(COMPOSE) up --force-recreate --no-deps -d koha_$(KOHAENV)"
build_debianfiles: ## Build from local debianfiles (koha-patched/debian)
@echo "======= BUILDING KOHA CONTAINER FROM LOCAL DEBIANFILES ======\n"
$(CMD) -c 'sudo docker build --build-arg KOHA_RELEASE=$(KOHA_RELEASE) \
-f $(KOHAPATH)/Dockerfile.debianfiles -t digibib/koha $(KOHAPATH)'
run: delete ## Start Koha container
$(CMD) -c "$(COMPOSE) up -d koha_$(KOHAENV)"
stop: ## Stop Koha container
$(CMD) -c "$(COMPOSE) stop koha_$(KOHAENV) || true"
delete: stop ## Delete Koha container
$(CMD) -c "$(COMPOSE) rm -fv koha_$(KOHAENV) || true"
######### DEBUGGING TARGETS #########
run_manual: delete ## Manually start a Koha container without entrypoint
@echo "======= MANUAL RUN OF koha_$(KOHAENV) CONTAINER ======\n"
$(CMD) -c "$(COMPOSE) run --rm --entrypoint bash --service-ports koha_$(KOHAENV)"
logs: ## Show Koha logs
$(CMD) -c "$(COMPOSE) logs koha_$(KOHAENV)"
logs-nocolor: ## Show Koha logs without ansi colours
$(CMD) -c "$(COMPOSE) logs --no-color koha_$(KOHAENV)"
logs-f: ## Tail and follow Koha logs
$(CMD) -c "$(COMPOSE) logs -f koha_$(KOHAENV)"
logs-f-nocolor: ## Tail and follow Koha logs without ansi colours
$(CMD) -c "$(COMPOSE) logs -f --no-color koha_$(KOHAENV)"
browser: ## Open Koha intra in firefox
$(CMD) -c 'firefox "http://localhost:8081/" > firefox.log 2> firefox.err < /dev/null' &
test: wait_until_ready ## Run status checks on Koha container
@echo "======= TESTING KOHA CONTAINER ======\n"
docker_cleanup: ## Clean up unused docker containers and images
@echo "cleaning up unused containers, images and volumes"
$(CMD) -c 'sudo docker system prune -f || true'
######### KOHADEV SPECIFIC TARGETS #########
dump_kohadb: ## Dumps Koha database
@echo "======= DUMPING KOHA DATABASE ======\n"
$(CMD) -c "$(COMPOSE) exec koha_$(KOHAENV) bash -c \"mysqldump --all-databases > /tmp/kohadump.sql\""
restore_kohadb: ## Restores Koha database
@echo "======= RESTORING KOHA DATABASE ======\n"
$(CMD) -c "$(COMPOSE) exec koha_$(KOHAENV) bash -c \"mysql < /tmp/kohadump.sql\""
delete_mysql_server: ## Stops and removes mysql server
@echo "======= STOPPING MYSQL SERVER ======\n"
$(CMD) -c "$(COMPOSE) stop koha_mysql"
$(CMD) -c "$(COMPOSE) rm -f koha_mysql"
delete_kohadb: stop delete_mysql_server ## Deletes Koha database
@echo "======= DELETING KOHA DATABASE ======\n"
$(CMD) -c "$(COMPOSE) volume rm -f koha_mysql_data"
load_testdata: ## Load optional test data
@echo "======= LOADING KOHA TESTDATA ======\n"
$(CMD) -c '$(COMPOSE) exec koha_$(KOHAENV) bash -c \
"for file in /kohadev/kohaclone/installer/data/mysql/en/optional/*.sql; do \
koha-mysql name < \$${file} ; \
done;"'
reset_git: ## Resets git by removing and doing new shallow clone
@echo "======= RELOADING CLEAN KOHA MASTER ======\n"
$(CMD) -c '$(COMPOSE) exec koha_$(KOHAENV) bash -c "cd /kohadev/kohaclone && \
git clean -xdf && git am --abort || true && git reset --hard && \
git checkout master && git branch -D sandbox || true"'
reset_git_hard: ## Resets git by removing and doing new shallow clone
@echo "======= RELOADING CLEAN KOHA MASTER ======\n"
$(CMD) -c '$(COMPOSE) exec koha_$(KOHAENV) bash -c "cd /kohadev && rm -rf kohaclone && git clone --depth 1 \$$KOHA_REPO kohaclone"'
patch: ## Apply patches on koha dev, needs PATCHES="<bugid> <bugid> <bugid>"
@echo "======= PATCHING KOHADEV CONTAINER ======\n"
$(CMD) -c '$(COMPOSE) exec koha_$(KOHAENV) bash -c "cd /kohadev/kohaclone && \
(git checkout -b sandbox || true) && \
for patch in $(PATCHES) ; do \
yes | git bz apply \$$patch ; \
done"'
######### DOCKER HUB SPECIFIC TARGETS #########
login: ## Log in to docker hub, needs PASSWORD and USERNAME
@ $(CMD) -c 'sudo docker login --username=$(USERNAME) --password=$(PASSWORD)'
tag = "$(shell git rev-parse HEAD)"
tag: ## Tag image from current GITREF
$(CMD) -c 'sudo docker tag -f digibib/koha digibib/koha:$(tag)'
push: ## Push current image to docker hub
@echo "======= PUSHING KOHA CONTAINER ======\n"
$(CMD) -c 'sudo docker push digibib/koha:$(tag)'