From a2f16246ec362f8a00ad4eedf2f7aea565e6d488 Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Wed, 16 Nov 2022 03:46:30 -0500 Subject: Makefile: Add deployment logic --- .gitignore | 3 ++ Makefile | 56 ++++++++++++++++++++++++++++++ database/contactform.sql | 7 ++++ public/dist/soundmanager2-nodebug-jsmin.js | 0 4 files changed, 66 insertions(+) create mode 100644 Makefile create mode 100644 database/contactform.sql mode change 100755 => 100644 public/dist/soundmanager2-nodebug-jsmin.js diff --git a/.gitignore b/.gitignore index 6d19387..05ddf83 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ /public/posts /vendor config.php +database generators/hugo/public google[a-z0-9]*.html +production +staging diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..761bd96 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +all: + make site + make migration + +site: + mkdir --parents public/posts + ln -sfT ../../public/posts generators/hugo/public + cd generators/hugo && hugo + +migration: + sqlite3 database/sqlite.db < database/contactform.sql + chmod g+w database/sqlite.db + sed --in-place "s|'sql:;dbname=sql_database'|'sqlite:' . __DIR__ . '/database/sqlite.db'|" config.php + +permissions: + find . -type f -print0 | xargs -0 chmod 640 + find . -type d -print0 | xargs -0 chmod 770 + +export date := $(shell date -Iseconds) +export path := deploy-$(date) +export deployment := $(target)/$(path) +export prelaunch := $(target)/prelaunch +export public := $(target)/public + +deploy: + mkdir --parent '$(deployment)' + rsync --archive --verbose \ + --exclude='.git/' \ + --exclude='.gitignore' \ + --exclude='$(target)/' \ + . '$(deployment)' + ln --symbolic --force '$(path)/public' '$(prelaunch)' + make minify + make cache + cd '$(deployment)' && make site && make migration + make permissions + mv --force --no-target-directory '$(prelaunch)' '$(public)' + find '$(target)' -maxdepth 1 ! -path '$(target)' -type d -printf '%T@\t%p\n' \ + | sort --reverse --general-numeric-sort --field-separator $$'\t' \ + | cut --delimiter $$'\t' --fields 2- \ + | awk "NR>5" \ + | xargs rm -rf + +cache: + { [ -e '$(public)' ] \ + && rsync --verbose --archive --include="*/" --include="*.min.*" --exclude="*" '$(public)/dist/' '$(prelaunch)/dist'; } || true + +minify: + minify $(prelaunch)/dist/app.css > $(prelaunch)/dist/app.min.'$(date)'.css + minify $(prelaunch)/dist/bar-ui.css > $(prelaunch)/dist/bar-ui-css.min.'$(date)'.css + minify $(prelaunch)/dist/bar-ui.js > $(prelaunch)/dist/bar-ui-js.min.'$(date)'.js + find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "app.min*" | awk -F/ '{print $NF}')|" {} \; + find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "bar-ui-css.min*" | awk -F/ '{print $NF}')|" {} \; + find $(prelaunch) -type f -exec sed --in-place "s|$$(find $(prelaunch)/dist -name "bar-ui-js.min*" | awk -F/ '{print $NF}')|" {} \; + +.PHONY: generators admin diff --git a/database/contactform.sql b/database/contactform.sql new file mode 100644 index 0000000..196cd9b --- /dev/null +++ b/database/contactform.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS contactform ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT, + email TEXT NOT NULL, + message TEXT NOT NULL, + date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL +); diff --git a/public/dist/soundmanager2-nodebug-jsmin.js b/public/dist/soundmanager2-nodebug-jsmin.js old mode 100755 new mode 100644 -- cgit v1.2.3