From: Kyle Bowman Date: Sat, 8 Feb 2025 19:08:05 +0000 (-0500) Subject: add make deploy functionality X-Git-Url: https://git.rocketbowman.com/?a=commitdiff_plain;h=2851716c3d439cd789033b199bdbc09fbc6935b7;p=jetsam.git add make deploy functionality --- diff --git a/Makefile b/Makefile index 43779c7..f9e8df0 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,14 @@ help: @echo @echo "all Builds the .buildlist and an index.html. (Top-level)" @echo "clean Removes build artifacts." + @echo "deploy Copies files to destination defined in $(SRC_DIR)/.env" @echo "help Prints this help message." @echo ".buildlist Defines a list of all files to build. Paths may be relative." @echo " to this Makefile's directory. Paths should be on their own lines. You" @echo " may create this file manually or override the BUILD_LIST variable when" @echo " you invoke the make command. The default BUILD_LIST is created from MD files" @echo " found anywhere under the $(SRC_DIR) directory." + @echo "$(SRC_DIR)/.env" " Defines your deployment info. If not found, you will be prompted for info." @echo "init-demo Creates links from demo to $(SRC_DIR) so you can then build it." @echo "init-altdemo Creates links from demo to $(SRC_DIR) (alternate method) so you can then build it." @echo "rm-src Deletes symlinks in $(SRC_DIR), checking for non-link data." @@ -49,6 +51,16 @@ clean: -rm .buildlist rm -rf $(BUILD_DIR) +.PHONY: +deploy: $(BUILD_DIR) $(SRC_DIR)/.env + . $(SRC_DIR)/.env && \ + rsync --verbose --recursive --delete \ + --chown=$$SITE_USER:$$SITE_USER --chmod=755 \ + $(BUILD_DIR)/* $$SITE_USER@$$SITE_HOST:$$SITE_PATH + +$(SRC_DIR)/.env: + @scripts/make-env.sh + .PHONY: init-demo: @if [ -e $(SRC_DIR) ]; then echo "$(SRC_DIR) already exists. Aborting." && exit 1; fi diff --git a/README.md b/README.md index f639850..e1addcd 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,20 @@ edit the file to build only the files that you want. **Note:** Spaces in filepaths will mess the part where the `BUILD_LIST` variable is used to create the `.buildlist` file. +## Deploying Your Project with Make + +You can use `make deploy` to deploy your project to a server using `rsync`. +Jetsam does not handle any server-side setup, like creating a user, adding +SSH keys, or anything like that. But when that is set up correctly, you can +use `make deploy`. The first time you run it, it will prompt you for some +site-specific information like the host, user, and path where you'd like to +deploy. This creates a `.env` file in your source directory, so you can +easily deploy different content to different sites. + +**WARNING:** If you consider host, user, and path information sensitive, be +sure to add the `.env` file to your source repo's `.gitignore` file so it isn't +committed into version control. + # Explore the Demo In the demo below, `>>>` indicates a terminal prompt in which you enter a diff --git a/scripts/make-env.sh b/scripts/make-env.sh new file mode 100755 index 0000000..c9b72d0 --- /dev/null +++ b/scripts/make-env.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +ENV_FILE="src/.env" + +# $1 = environment variable to set +# $2 = description of environment variable +prompt_user() { + echo "Enter $1 ($2):" + read -r value + echo "$1=$value" >> "$ENV_FILE" +} + +# Prompt the user for SITE_HOST, SITE_USER, and SITE_PATH +if [ ! -f "$ENV_FILE" ]; then + prompt_user "SITE_HOST" "url or IP address" + prompt_user "SITE_PATH" "path to directory of hosted files" + prompt_user "SITE_USER" "owns website directory and files" + echo + echo "The following values were written to $ENV_FILE:" && echo && cat "$ENV_FILE" +else + echo "$ENV_FILE already found." +fi \ No newline at end of file