From 739afd231066645433987895d9d05fdbac4011d8 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sun, 30 Dec 2018 20:10:42 -0500 Subject: [PATCH] Embed schema files in binary This includes schema.sql and sqlite.sql in the release binary, so they no longer need to be included in the release archives. This reduces the number of files extracted, but otherwise leaves all functionality as it was -- especially the --init-db flag. Ref T536 --- .gitignore | 2 ++ Makefile | 19 ++++++++++++++----- app.go | 4 +--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f1e3331..95ad31b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ build config.ini *.db + +bindata.go diff --git a/Makefile b/Makefile index 3e0e4c6..3fc11ac 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ IMAGE_NAME=writeas/writefreely all : build -build: deps +build: assets deps cd cmd/writefreely; $(GOBUILD) -v build-linux: deps @@ -39,7 +39,7 @@ build-docker : test: $(GOTEST) -v ./... -run: +run: dev-assets $(GOINSTALL) ./... $(BINARY_NAME) --debug @@ -50,14 +50,12 @@ install : build cmd/writefreely/$(BINARY_NAME) --gen-keys cd less/; $(MAKE) install $(MFLAGS) -release : clean ui +release : clean ui assets mkdir build cp -r templates build cp -r pages build cp -r static build mkdir build/keys - cp schema.sql build - cp sqlite.sql build $(MAKE) build-linux mv build/$(BINARY_NAME)-linux-amd64 build/$(BINARY_NAME) cd build; tar -cvzf ../$(BINARY_NAME)_$(GITREV)_linux_amd64.tar.gz * @@ -78,6 +76,17 @@ release-docker : ui : force_look cd less/; $(MAKE) $(MFLAGS) +assets : generate + go-bindata -pkg writefreely -ignore=\\.gitignore schema.sql sqlite.sql + +dev-assets : generate + go-bindata -pkg writefreely -ignore=\\.gitignore -debug schema.sql sqlite.sql + +generate : + @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GOGET) -u github.com/jteeuwen/go-bindata/...; \ + fi + clean : -rm -rf build cd less/; $(MAKE) clean $(MFLAGS) diff --git a/app.go b/app.go index c435a9a..41b69d8 100644 --- a/app.go +++ b/app.go @@ -14,7 +14,6 @@ import ( "flag" "fmt" "html/template" - "io/ioutil" "net/http" "net/url" "os" @@ -270,12 +269,11 @@ func Serve() { defer shutdown(app) schemaFileName := "schema.sql" - if app.cfg.Database.Type == "sqlite3" { schemaFileName = "sqlite.sql" } - schema, err := ioutil.ReadFile(schemaFileName) + schema, err := Asset(schemaFileName) if err != nil { log.Error("Unable to load schema file: %v", err) os.Exit(1)