Move to bin/ folder

This commit is contained in:
decentral1se
2021-04-01 22:33:05 +02:00
parent 26e839ea7b
commit 73c1290c52
3 changed files with 0 additions and 0 deletions

100
bin/app-catalogue.sh Executable file
View File

@ -0,0 +1,100 @@
#!/bin/bash
# Usage: ./app-catalogue.sh
#
# Gather metadata from Co-op Cloud apps in $ABRA_DIR/apps (default
# ~/.abra/apps), and format it as a Markdown table for this page:
# https://docs.cloud.autonomic.zone/apps/
stack_dir="${ABRA_DIR:-$HOME/.abra}/apps/"
cd "$stack_dir"
# load all README files into ENV_FILES array
mapfile -t readmes < <(find -L . -name "README.md")
# FIXME 3wc: requires bash 4, use for loop instead
base_url="https://git.autonomic.zone/coop-cloud"
cat_apps=()
cat_development=()
cat_utilities=()
cat_graveyard=()
get_var() {
echo "$1" | grep "$2" | sed 's/^[^:]*: //'
}
# shellcheck disable=SC2120
trim() {
# accept input as argument or from STDIN, see here:
# https://zwbetz.com/passing-input-to-a-bash-function-via-arguments-or-stdin/
# shellcheck disable=SC2155
local input="$([[ -p /dev/stdin ]] && cat - || echo "$@")"
[[ -z "$input" ]] && return 1
echo "$input" | tr -d ' '
}
# shellcheck disable=SC2120
prettify() {
# as above
# shellcheck disable=SC2155
local input="$([[ -p /dev/stdin ]] && cat - || echo "$@")"
[[ -z "$input" ]] && return 1
echo "$input" | sed -e 's/Yes/✅/' -e 's/No/❌/' -e 's/N\/A/⛔/'
}
for readme in "${readmes[@]}"; do
type="$(basename "${readme%README.md}")"
if [ "$type" = "example" ]; then
continue
fi
title="$(grep '^# ' "$type/README.md" | sed 's/^# //' )"
# find section between 'metadata' and 'endmetadata' comments
metadata="$(awk '/-- metadata --/,/-- endmetadata --/' "$type/README.md")"
status="$(get_var "$metadata" "Status")"
category="$(get_var "$metadata" "Category" | cut -d',' -f2 | trim)"
if [ -z "$category" ]; then
echo "ERROR: missing category for $type"
continue
fi
image="$(get_var "$metadata" "Image" | cut -d',' -f2 | trim)"
healthcheck="$(get_var "$metadata" "Healthcheck" | prettify)"
backups="$(get_var "$metadata" "Backups" | prettify)"
email="$(get_var "$metadata" "Email" | prettify)"
tests="$(get_var "$metadata" "Tests" | prettify)"
sso="$(get_var "$metadata" "SSO" | prettify)"
row="| [$title]($base_url/$type) | $status | $image | $healthcheck | $backups | $email | $tests | $sso |"
category_lower="$(echo "$category" | tr '[:upper:]' '[:lower:]')"
eval "cat_$category_lower+=( '$row' )"
done
headers="
| **Name** | **Status** | **Image** | **Healtcheck** | **Backups** | **Email** | **CI** | **Single-Sign-On** |
| --- | --- | --- | --- | --- | --- | --- | --- |"
echo "## Applications"
echo "$headers"
printf '%s\n' "${cat_apps[@]}" | sort
echo
echo "## Developer tools"
echo "$headers"
printf '%s\n' "${cat_development[@]}" | sort
echo
echo "## Utilities"
echo "$headers"
printf '%s\n' "${cat_utilities[@]}" | sort
echo
echo "## Graveyard"
echo "$headers"
printf '%s\n' "${cat_graveyard[@]}" | sort

104
bin/app-json.py Executable file
View File

@ -0,0 +1,104 @@
#!/usr/bin/env python3
from json import dump
from os import chdir, getcwd, listdir, mkdir
from os.path import exists, expanduser
from pathlib import Path
from re import findall, search
from shlex import split
from subprocess import check_output, run
from requests import get
HOME_PATH = expanduser("~/")
CLONES_PATH = Path(f"{HOME_PATH}/.abra/apps").absolute()
def clone_apps():
if not exists(CLONES_PATH):
mkdir(CLONES_PATH)
response = get("https://git.autonomic.zone/api/v1/orgs/coop-cloud/repos")
repos = [[p["name"], p["ssh_url"]] for p in response.json()]
skips = ("organising", "cloud.autonomic.zone", "docs.cloud.autonomic.zone", "abra")
for name, url in repos:
if name in skips:
continue
try:
if not exists(f"{CLONES_PATH}/{name}"):
run(split(f"git clone {url} {CLONES_PATH}/{name}"))
chdir(f"{CLONES_PATH}/{name}")
if not int(check_output("git branch --list | wc -l", shell=True)):
run(split("git checkout main"))
except Exception:
pass
def gen_apps_json():
apps_json = {}
for app in listdir(CLONES_PATH):
app_path = f"{CLONES_PATH}/{app}"
chdir(app_path)
output = check_output("git tag --list", shell=True)
tags = output.strip().decode("utf-8")
if not tags:
continue
for tag in tags:
apps_json[app] = {
"category": "apps",
"repository": f"https://git.autonomic.zone/coop-cloud/{app}.git",
"features": get_app_features(app_path),
"versions": get_app_versions(app_path),
}
return apps_json
def get_app_features(app_path):
features = {}
with open(f"{app_path}/README.md", "r") as handle:
contents = handle.read()
for match in findall(r"\*\*.*\s\*", contents):
title = search(r"(?<=\*\*).*(?=\*\*)", match).group().lower()
if title == "image":
value = {
"image": search(r"(?<=`).*(?=`)", match).group(),
"url": search(r"(?<=\().*(?=\))", match).group(),
"rating": match.split(",")[1].strip(),
"source": match.split(",")[-1].replace("*", "").strip(),
}
else:
value = match.split(":")[-1].replace("*", "").strip()
features[title] = value
return features
def get_app_versions(app_path):
versions = {}
chdir(app_path)
tags = check_output(f"git tag --list", shell=True).strip()
for tag in tags:
# TODO
# checkout that tag in the local git branch
# parse all service images via yq or other magic
# lookup the digest with skopeo
pass
return versions
clone_apps()
with open(f"{getcwd()}/abra-apps.json", "w", encoding="utf-8") as handle:
dump(gen_apps_json(), handle, ensure_ascii=False, indent=4)
print("Output saved to abra-apps.json")

42
bin/app-version.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
# Usage: ./app-version.sh <image> <service>
# Example: ./app-version.sh drone/drone:1.10.1 app
#
# Accepts a full format hub.docker.com image tag which it pulls locally and
# generates output which can be used to put in the abra.sh for app packaging.
# Requires the yq program https://mikefarah.gitbook.io/yq/
error() {
echo "$(tput setaf 1)ERROR: $*$(tput sgr0)"
exit 1
}
IMAGE="$1"
SERVICE="$2"
if ! docker pull -q "$IMAGE" > /dev/null 2>&1; then
error "Failed to download image, is the tag correct?"
fi
version=$(echo "$IMAGE" | cut -d ':' -f2)
digest=$(docker image inspect -f "{{.Id}}" "$IMAGE" | cut -d ':' -f2- | cut -c 1-8)
echo "--- Add the following to your abra.sh ---"
echo "export ABRA_TYPE_${SERVICE^^}_VERSION=${version}"
echo "export ABRA_TYPE_${SERVICE^^}_DIGEST=${digest}"
version_lookup="ABRA_TYPE_${SERVICE^^}_VERSION"
digest_lookup="ABRA_TYPE_${SERVICE^^}_DIGEST"
label='- "coop-cloud.${STACK_NAME}.'
label+="${SERVICE}"
label+='.version=${'
label+="${version_lookup}"
label+='}-${'
label+="${digest_lookup}"
label+='}"'
echo
echo "--- And don't forget to label the actual service in the compose file ---"
echo "$label"