From e60d90c7e7989ec754c5e9dd915e5cd43e3ae88d Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 14 Oct 2024 01:17:26 +0400 Subject: [PATCH] discourse OK --- lib/functions.sh | 18 +++++------------- recipes/discourse/crud.sh | 37 ++++++++++++++++++------------------ recipes/discourse/install.sh | 21 +++++++++++++++++++- recipes/odoo12/crud.sh | 4 ++-- recipes/odoo15/crud.sh | 4 ++-- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index 4e64127..19eab9d 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -432,20 +432,12 @@ function launch_container() { arg1_required "$@" local ct="$1" if ! container_exists "$ct"; then - echo "container <$ct> about to be created ..." - local extra_release="${2:-}" - if [[ -n "$extra_release" ]] && ! lxc image info "${extra_release}-miaou" >/dev/null; then - echoerrn "unknown extra_release <${extra_release}-miaou>!\nHINT : please add it into /etc/miaou/defaults.yaml, then re-install miaou!" - exit 128 - fi + echo -e "container <$ct> about to be created ..." - if [[ -n "$extra_release" ]]; then - echoerrn "FIXME: lxc-miaou-create -o release=bookworm should be implemented ...." - lxc-miaou-create "$ct" "$extra_release" - else - lxc-miaou-create "$ct" - fi - echo "DONE" + # shellcheck disable=SC2068 + lxc-miaou-create "$ct" ${@:2} + + PREFIX="" echo "DONE" fi if ! container_running "$ct"; then diff --git a/recipes/discourse/crud.sh b/recipes/discourse/crud.sh index e41f991..9c241ac 100755 --- a/recipes/discourse/crud.sh +++ b/recipes/discourse/crud.sh @@ -17,37 +17,38 @@ function _create() { echo "creating discourse instance for <$shortname> ... " echo "initialize discourse $shortname $longname ... OK" + if ! (db-psql list | grep -q "$longname"); then + echo "create empty database <$longname> ... " + db-psql create "$longname" + db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS hstore" + db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS pg_trgm" + echo "create empty database <$longname> ... OK" + else + echo "database already exists!" + fi + admin_username=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.username) admin_email=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.email) admin_password=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.password) redis_password=$(load_yaml_from_expanded credential.redis) mkdir -p "$MIAOU_CONFIGDIR/apps/discourse" - APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" + APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null echo "creating templates ... OK" echo "copying files to container <$container> ... " - lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml" + lxc file push --uid 0 --gid 0 --mode 600 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml" echo "copying files to container <$container> ... OK" - if ! (db-psql list | grep -q "$longname"); then - echo "create empty database <$longname> ... " - db-psql create "$longname" - db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS hstore" - db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS pg_trgm" - echo "create empty database <$longname> ... OK" - else - echo "database already exists!" - fi + console="u=User.create_with(email: '$admin_email', password: '$admin_password').find_or_initialize_by(username: '$admin_username'); u.save; u.activate" + # console="puts User.count" + activate_admin="rails runner \"$console\"" echo "build docker container $longname ..." - lxc exec "$container" -- bash <" + lxc exec "$container" -- /var/discourse/launcher run "$longname" "$activate_admin" echo "initialize discourse $longname ... OK" } diff --git a/recipes/discourse/install.sh b/recipes/discourse/install.sh index 2ea3726..4eb1d62 100755 --- a/recipes/discourse/install.sh +++ b/recipes/discourse/install.sh @@ -7,6 +7,12 @@ function check() { container_exists "$CONTAINER" || return 1 container_running "$CONTAINER" || return 2 + var_discourse_exists "$CONTAINER" || return 3 +} + +function var_discourse_exists() { + container="$1" + lxc exec "$container" -- test -d /var/discourse/containers } ### INSTALL @@ -15,8 +21,21 @@ function install() { PREFIX="recipe:discourse:install" : $PREFIX - launch_container "$CONTAINER" + launch_container "$CONTAINER" "-o nesting" echo "initializing discourse ... " + lxc exec "$CONTAINER" -- bash < /dev/null + apt update + apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + mkdir /var/discourse + git clone https://github.com/discourse/discourse_docker.git /var/discourse +EOF PREFIX="" echo "OK" } diff --git a/recipes/odoo12/crud.sh b/recipes/odoo12/crud.sh index 0df4fda..ae8f157 100755 --- a/recipes/odoo12/crud.sh +++ b/recipes/odoo12/crud.sh @@ -44,10 +44,10 @@ function _create() { db-psql create "$longname" echo "create empty database <$longname> ... OK" - admin_username=$(cat "$data" | yq '.admin.username') + admin_username=$(echo -e "$data" | yq '.admin.username') [[ $admin_username == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:username\` into miaou.yaml service definition of <$fqdn>" && exit 1 - admin_password=$(cat "$data" | yq '.admin.password') + admin_password=$(echo -e "$data" | yq '.admin.password') [[ $admin_password == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:password\` into miaou.yaml service definition of <$fqdn>" && exit 1 cat < ... OK" - admin_username=$(cat "$data" | yq '.admin.username') + admin_username=$(echo -e "$data" | yq '.admin.username') [[ $admin_username == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:username\` into miaou.yaml service definition of <$fqdn>" && exit 1 - admin_password=$(cat "$data" | yq '.admin.password') + admin_password=$(echo -e "$data" | yq '.admin.password') [[ $admin_password == 'null ' ]] && echoerr "odoo12 recipe requires \`data:admin:password\` into miaou.yaml service definition of <$fqdn>" && exit 1 cat <