]> git.rocketbowman.com Git - jetsam.git/commitdiff
add make deploy functionality
authorKyle Bowman <kyle+github@rocketbowman.com>
Sat, 8 Feb 2025 19:08:05 +0000 (14:08 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sat, 8 Feb 2025 19:08:05 +0000 (14:08 -0500)
Makefile
README.md
scripts/make-env.sh [new file with mode: 0755]

index 43779c71c14fbe3c824e13b98ca3a85e3884d9cf..f9e8df0ede0a1b211102675b9817507b96f4ebf9 100644 (file)
--- 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
index f6398509c251dc1b20fc9dc0bfcb1311d5816655..e1addcd603af03759f411c8ca40740021016cca4 100644 (file)
--- 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 (executable)
index 0000000..c9b72d0
--- /dev/null
@@ -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