mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Adds airflow assessment generation to hpa scripts.
This commit is contained in:
47
env/.local/scripts/utils/hpa/aap
vendored
Executable file
47
env/.local/scripts/utils/hpa/aap
vendored
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# A wrapper script to run swift-hpa in a docker container and
|
||||
# mount the correct volumes, etc.
|
||||
#
|
||||
# Make sure to run 'hpa-init' first on this machine to setup
|
||||
# dependencies, if you have not done so already.
|
||||
#
|
||||
# To attach to a shell inside the container run:
|
||||
# `hpa bash`
|
||||
#
|
||||
# To run ansible vault commands inside the container run:
|
||||
# `hpa ansible-vault ...`
|
||||
#
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
. "$SCRIPTS/utils/hpa/hpa.env"
|
||||
|
||||
############################## MAIN ##############################
|
||||
|
||||
# Don't pull images if they're prefixed with 'localhost'.
|
||||
if echo "$HPA_DOCKER_IMAGE" | grep -vq "localhost"; then
|
||||
|
||||
# Check if we should pull the image prior to running.
|
||||
last_pull="0"
|
||||
if [[ -f "$HPA_AIRFLOW_CONFIG_DIR/.lastpull" ]]; then
|
||||
last_pull=$(cat "$HPA_AIRFLOW_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
|
||||
fi
|
||||
|
||||
podman run --rm --interactive --tty \
|
||||
--volume "$HPA_AIRFLOW_CONFIG_DIR":/root/.config/hpa:ro \
|
||||
--volume "$HPA_DATA_DIR":/root/.local/share/hpa:ro \
|
||||
--volume "$HPA_CONSULTS_DIR":/consults \
|
||||
--volume "$PWD":/root/project \
|
||||
--secret "$HPA_VAULT_SECRET_KEY" \
|
||||
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
|
||||
32
env/.local/scripts/utils/hpa/hpa-create
vendored
32
env/.local/scripts/utils/hpa/hpa-create
vendored
@@ -17,7 +17,8 @@ LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
# Load environment / shared variables.
|
||||
. "$SCRIPTS/utils/hpa/hpa.env"
|
||||
|
||||
declare no_git_flag no_push_flag date_opt
|
||||
declare airflow_flag no_git_flag no_push_flag date_opt
|
||||
airflow_flag="0"
|
||||
no_git_flag="0"
|
||||
no_push_flag="0"
|
||||
date_opt=$(date '+%Y.%m.%d')
|
||||
@@ -25,7 +26,8 @@ date_opt=$(date '+%Y.%m.%d')
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
A utility script to generate a new home performance assessment project.
|
||||
A utility script to generate a new home performance assessment project or
|
||||
airflow assessment project.
|
||||
|
||||
All output from the 'hpa' command get suppressed so that this script can
|
||||
be piped / used to automatically cd into the directory after creation to
|
||||
@@ -41,6 +43,7 @@ USAGE:
|
||||
$ $THIS <flags> <customer>
|
||||
|
||||
FLAGS:
|
||||
-a | --airflow: Generate using the airflow assessment project template.
|
||||
-d | --date: Override the date the project was started.
|
||||
-g | --no-git: Do not initialize a git repository for the project.
|
||||
-h | --help: Show this help page.
|
||||
@@ -62,21 +65,32 @@ log() {
|
||||
}
|
||||
|
||||
create() {
|
||||
local customer container_dir
|
||||
local customer container_dir script suffix
|
||||
customer=${1:-""}
|
||||
|
||||
[[ -z $customer ]] &&
|
||||
log --error "Must supply a customer name for the project" &&
|
||||
exit 1
|
||||
|
||||
[[ ! -f $SCRIPTS/hpa ]] &&
|
||||
log --error "Unable to find the 'hpa' script." &&
|
||||
exit 1
|
||||
|
||||
log "Generating project for: '$customer'"
|
||||
|
||||
# Setup approriate configuration and project suffix.
|
||||
if [[ $airflow_flag == "1" ]]; then
|
||||
suffix="AAP"
|
||||
script="$SCRIPTS/utils/hpa/aap"
|
||||
else
|
||||
suffix="HPA"
|
||||
script="$SCRIPTS/hpa"
|
||||
fi
|
||||
|
||||
[[ ! -f $SCRIPTS/hpa ]] &&
|
||||
log --error "Unable to find the script: '$script'." &&
|
||||
exit 1
|
||||
|
||||
log "Using script: '$script'"
|
||||
|
||||
container_dir=$(
|
||||
"$SCRIPTS/hpa" create --quiet "/consults/$date_opt.$customer"
|
||||
"$script" create --quiet "/consults/$date_opt.$customer.$suffix"
|
||||
)
|
||||
echo "$HPA_CONSULTS_DIR/$(basename "$container_dir")"
|
||||
}
|
||||
@@ -129,6 +143,8 @@ declare customer output
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
elif [[ $1 == "-a" ]] || [[ $1 == "--airflow" ]]; then
|
||||
airflow_flag="1"
|
||||
elif [[ $1 == "-d" ]] || [[ $1 == "--date" ]]; then
|
||||
shift
|
||||
date_opt="$1"
|
||||
|
||||
8
env/.local/scripts/utils/hpa/hpa.env
vendored
8
env/.local/scripts/utils/hpa/hpa.env
vendored
@@ -33,6 +33,11 @@ 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_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
|
||||
|
||||
# Airflow assessment vars.
|
||||
HPA_AIRFLOW_CONFIG_DIR="${XDG_CONFIG_HOME}/aap"
|
||||
HPA_AIRFLOW_TEMPLATE_DIR="${HPA_DATA_DIR}/airflow-assessment-template"
|
||||
HPA_AIRFLOW_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/airflow-assessment-template.git"
|
||||
|
||||
export HPA_AUTO_PULL
|
||||
export HPA_AUTO_PULL_INTERVAL
|
||||
export HPA_AUTO_PULL_OPTS
|
||||
@@ -47,3 +52,6 @@ export HPA_DOCKER_TAG
|
||||
export HPA_PLAYBOOK_URL
|
||||
export HPA_PLAYBOOK_DIR
|
||||
export HPA_VAULT_SECRET_KEY
|
||||
export HPA_AIRFLOW_CONFIG_DIR
|
||||
export HPA_AIRFLOW_TEMPLATE_DIR
|
||||
export HPA_AIRFLOW_TEMPLATE_URL
|
||||
|
||||
Reference in New Issue
Block a user