summaryrefslogtreecommitdiff
path: root/app/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'app/Makefile')
-rw-r--r--app/Makefile88
1 files changed, 65 insertions, 23 deletions
diff --git a/app/Makefile b/app/Makefile
index 8624cd8..71b936c 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -1,5 +1,24 @@
-include env.sh
+# Modify env.sh and uncomment to change config.
+#include env.sh
+# Start the race detector with "TEST_RACE=1 make test" on the command line.
+ifdef TEST_RACE
+ RACE:=-race
+else
+ RACE:=
+endif
+
+# To be verbose while testing use TEST_VERBOSE=1.
+ifdef TEST_VERBOSE
+ VERBOSE:=-v
+else
+ VERBOSE:=
+endif
+
+IMPORT_FILE:=./import.go
+APP:=statuspage
+
+# Sanity check
ifndef STATUS_DB_DRIVER
export STATUS_DB_DRIVER:=sqlite3
endif
@@ -22,35 +41,30 @@ ifndef STATUS_HTTP_PORT
export STATUS_HTTP_PORT:=8080
endif
-ifdef TEST_RACE
- RACE:=-race
-else
- RACE:=
+# Include the sqlit3 database in archiv.
+ifeq ($(STATUS_DB_DRIVER), sqlite3)
+ STATUS_DB_DIR:=db
+else
+ STATUS_DB_DIR:=
endif
-ifdef TEST_VERBOSE
- VERBOSE:=-v
-else
- VERBOSE:=
-endif
-
-IMPORT_FILE:=./import.go
-APP:=statuspage
-
+# Start targets
all: kill build run
clean: kill
@(rm $(IMPORT_FILE) 2>/dev/null && echo "Removing import file..." ) || true
- @(rm $(STATUS_DB_CREDENTIALS) 2>/dev/null && echo "Removing sqlite3 database..." ) || true
- @(rm ../$(APP).tar.gz 1>&2 2>/dev/null echo && "Removing tar archiv...") || true
- @(rm $(APP) && echo "Removing binary ($(APP))...") || true
+ @(rm $(STATUS_DB_CREDENTIALS) 2>/dev/null echo && "Removing sqlite3 database..." ) || true
+ @(rm ../$(APP).tar.gz 1>&2 2>/dev/null && echo "Removing tar archiv...") || true
+ @(rm _env.sh 1>&2 2>/dev/null && echo "Removing _env.sh...") || true
+ @(rm $(APP) 2>/dev/null && echo "Removing binary ($(APP))...") || true
+ @(rm ../start.sh 1>&2 2>/dev/null && echo "Removing startup script...") || true
@echo "Done."
build: import
go build -o statuspage
-run:
- ./$(APP) &
+run: _test_build
+ ./$(APP) &
kill:
@echo "Killing running instances..."
@@ -69,7 +83,7 @@ import:
echo "import _ \"$(STATUS_DB_IMPORT_DRIVER)\"" >> $(IMPORT_FILE) ; \
fi
-sqlite3: create_import
+sqlite3: create_import
@echo "import _ \"github.com/mattn/go-sqlite3\"" >> $(IMPORT_FILE)
mysql: create_import
@@ -81,10 +95,14 @@ postgresql: create_import
database_all: sqlite3 mysql postgresql
@echo "Created import file for all databases."
-pack:
+pack: gen_config
@cd .. && \
- tar czf $(APP).tar.gz app/$(APP) app/env.sh app/Makefile views static db 2>/dev/null && \
- echo "../$(APP).tar.gz is ready." || \
+ echo "#!/bin/sh" > start.sh && \
+ echo "cd app && . ./_env.sh && ./$(APP)" >> start.sh && \
+ chmod +x start.sh && \
+ tar czf $(APP).tar.gz start.sh app/$(APP) app/_env.sh views static $(STATUS_DB_DIR) 2>/dev/null && \
+ rm start.sh 2>/dev/null && \
+ echo "\n../$(APP).tar.gz is ready." || \
(echo "Run \"make build\" first." && exit 1)
test:
@@ -102,3 +120,27 @@ benchmark:
benchmark_dependencies: import
export DB_STATUS_LOG=false
go test $(VERBOSE) -bench=".*" -tags dep
+
+_test_build:
+ @if [ ! -f ./$(APP) ] || [ ! -x ./$(APP) ]; then \
+ echo "No executable binary found. \nRun \"make build\" first.\n" 1>&2; \
+ exit 1; \
+ fi
+
+gen_config: _test_build
+ @echo "Generating config file!\n"
+ echo "#!/bin/sh" > _env.sh
+ @echo "# Database" >> _env.sh
+ echo "export STATUS_DB_DRIVER=$(STATUS_DB_DRIVER)" >> _env.sh
+ echo "export STATUS_DB_CREDENTIALS=$(STATUS_DB_CREDENTIALS)" >> _env.sh
+ echo "export STATUS_DB_IMPORT_DRIVER=$(STATUS_DB_IMPORT_DRIVER)" >> _env.sh
+ echo "export STATUS_DB_LOG=$(STATUS_DB_LOG)\n" >> _env.sh
+ @echo ""
+ @echo "# Redis" >> _env.sh
+ echo "export STATUS_REDIS_SERVER=$(STATUS_REDIS_SERVER)" >> _env.sh
+ echo "export STATUS_REDIS_PORT=$(STATUS_REDIS_PORT)\n" >> _env.sh
+ @echo ""
+ @echo "# Http" >> _env.sh
+ echo "export STATUS_HTTP_IP=$(STATUS_HTTP_IP)" >> _env.sh
+ echo "export STATUS_HTTP_PORT=$(STATUS_HTTP_PORT)" >> _env.sh
+ @chmod +x _env.sh