mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
feat: Adds auto-pull options to hpa with a default pull interval of 1 hour.
This commit is contained in:
28
env/.local/scripts/hpa
vendored
28
env/.local/scripts/hpa
vendored
@@ -10,26 +10,26 @@ set -o pipefail
|
|||||||
# Make sure to run 'hpa-init' first on this machine to setup
|
# Make sure to run 'hpa-init' first on this machine to setup
|
||||||
# dependencies, if you have not done so already.
|
# dependencies, if you have not done so already.
|
||||||
|
|
||||||
# XDG vars.
|
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
. "$SCRIPTS/utils/hpa/hpa.env"
|
||||||
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
|
||||||
|
|
||||||
# Docker vars.
|
|
||||||
HPA_DOCKER_IMAGE="git.housh.dev/michael/swift-hpa"
|
|
||||||
HPA_DOCKER_TAG=${HPA_DOCKER_TAG:-"latest"}
|
|
||||||
|
|
||||||
# Local vars.
|
|
||||||
HPA_DATA_DIR="$XDG_DATA_HOME/hpa"
|
|
||||||
HPA_CONFIG_DIR="$XDG_CONFIG_HOME/hpa"
|
|
||||||
CONSULTS_DIR=${CONSULTS_DIR:-$HOME/work/consults}
|
|
||||||
HPA_VAULT_SECRET_KEY="${HPA_VAULT_SECRET_KEY:-vault-pass}"
|
|
||||||
|
|
||||||
############################## MAIN ##############################
|
############################## MAIN ##############################
|
||||||
|
|
||||||
|
last_pull="0"
|
||||||
|
if [[ -f "$HPA_CONFIG_DIR/.lastpull" ]]; then
|
||||||
|
last_pull=$(cat "$HPA_CONFIG_DIR/.lastpull")
|
||||||
|
fi
|
||||||
|
curr=$(date +%s)
|
||||||
|
diff=$((curr - last_pull))
|
||||||
|
|
||||||
|
if [[ $HPA_AUTO_PULL == "1" ]] && [[ $diff -gt "$HPA_AUTO_PULL_INTERVAL" ]]; then
|
||||||
|
. "$SCRIPTS/hpa-pull" "$HPA_AUTO_PULL_OPTS"
|
||||||
|
fi
|
||||||
|
|
||||||
podman run --rm --interactive --tty \
|
podman run --rm --interactive --tty \
|
||||||
--volume "$HPA_DATA_DIR/template":/template \
|
--volume "$HPA_DATA_DIR/template":/template \
|
||||||
--volume "$HPA_DATA_DIR/playbook":/playbook \
|
--volume "$HPA_DATA_DIR/playbook":/playbook \
|
||||||
--volume "$HPA_CONFIG_DIR":/config/hpa \
|
--volume "$HPA_CONFIG_DIR":/config/hpa \
|
||||||
--volume "$CONSULTS_DIR":/consults \
|
--volume "$HPA_CONSULTS_DIR":/consults \
|
||||||
--secret "$HPA_VAULT_SECRET_KEY" \
|
--secret "$HPA_VAULT_SECRET_KEY" \
|
||||||
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
||||||
|
|||||||
1
env/.local/scripts/hpa-pull
vendored
1
env/.local/scripts/hpa-pull
vendored
@@ -105,3 +105,4 @@ fi
|
|||||||
[[ $docker_flag == "1" ]] && pull-docker
|
[[ $docker_flag == "1" ]] && pull-docker
|
||||||
[[ $playbook_flag == "1" ]] && pull-playbook
|
[[ $playbook_flag == "1" ]] && pull-playbook
|
||||||
[[ $template_flag == "1" ]] && pull-template
|
[[ $template_flag == "1" ]] && pull-template
|
||||||
|
echo "$(date +%s)" >>$HPA_CONFIG_DIR/.lastpull
|
||||||
|
|||||||
11
env/.local/scripts/utils/hpa/hpa.env
vendored
11
env/.local/scripts/utils/hpa/hpa.env
vendored
@@ -4,6 +4,8 @@
|
|||||||
#
|
#
|
||||||
# This allows them all to be set / declared in one place, then those
|
# This allows them all to be set / declared in one place, then those
|
||||||
# scripts just need to source this file to use them.
|
# scripts just need to source this file to use them.
|
||||||
|
#
|
||||||
|
# All variables can be overriden by setting in your shell env.
|
||||||
|
|
||||||
# XDG vars.
|
# XDG vars.
|
||||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||||
@@ -13,6 +15,12 @@ XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
|||||||
HPA_DOCKER_IMAGE="git.housh.dev/michael/swift-hpa"
|
HPA_DOCKER_IMAGE="git.housh.dev/michael/swift-hpa"
|
||||||
HPA_DOCKER_TAG=${HPA_DOCKER_TAG:-"latest"}
|
HPA_DOCKER_TAG=${HPA_DOCKER_TAG:-"latest"}
|
||||||
|
|
||||||
|
# Auto pull options to be ran before running the hpa docker
|
||||||
|
# container, default is always pull new images and repositories.
|
||||||
|
HPA_AUTO_PULL=${HPA_AUTO_PULL:="1"}
|
||||||
|
HPA_AUTO_PULL_INTERVAL="3600" # 1 hour
|
||||||
|
HPA_AUTO_PULL_OPTS=${HPA_AUTO_PULL_OPTS:-"--all"}
|
||||||
|
|
||||||
HPA_CONFIG_DIR="$XDG_CONFIG_HOME/hpa"
|
HPA_CONFIG_DIR="$XDG_CONFIG_HOME/hpa"
|
||||||
HPA_DATA_DIR="$XDG_DATA_HOME/hpa"
|
HPA_DATA_DIR="$XDG_DATA_HOME/hpa"
|
||||||
HPA_PLAYBOOK_DIR="$HPA_DATA_DIR/playbook"
|
HPA_PLAYBOOK_DIR="$HPA_DATA_DIR/playbook"
|
||||||
@@ -25,6 +33,9 @@ HPA_CONSULT_ORIGIN_BASE_URL=${CONSULT_ORIGIN_BASE_URL:-"ssh://git@git.housh.dev:
|
|||||||
HPA_CONSULT_TEMPLATE_DIR=${HPA_DATA_DIR}/template
|
HPA_CONSULT_TEMPLATE_DIR=${HPA_DATA_DIR}/template
|
||||||
HPA_CONSULT_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
|
HPA_CONSULT_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
|
||||||
|
|
||||||
|
export HPA_AUTO_PULL
|
||||||
|
export HPA_AUTO_PULL_INTERVAL
|
||||||
|
export HPA_AUTO_PULL_OPTS
|
||||||
export HPA_CONSULTS_DIR
|
export HPA_CONSULTS_DIR
|
||||||
export HPA_CONSULT_ORIGIN_BASE_URL
|
export HPA_CONSULT_ORIGIN_BASE_URL
|
||||||
export HPA_CONSULT_TEMPLATE_DIR
|
export HPA_CONSULT_TEMPLATE_DIR
|
||||||
|
|||||||
Reference in New Issue
Block a user