Browse Source

discourse OK

main
pvincent 2 months ago
parent
commit
e60d90c7e7
  1. 18
      lib/functions.sh
  2. 37
      recipes/discourse/crud.sh
  3. 21
      recipes/discourse/install.sh
  4. 4
      recipes/odoo12/crud.sh
  5. 4
      recipes/odoo15/crud.sh

18
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

37
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 <<EOF
set -Eeuo pipefail
cd /var/discourse
./launcher rebuild $longname
command='u=User.create_with(email: "$admin_email", password: "$admin_password").find_or_initialize_by(username: "$admin_username"); u.save; u.activate'
./launcher run $longname "rails runner '\$command'"
EOF
lxc exec "$container" -- /var/discourse/launcher rebuild "$longname"
echo "initialize admin user <$admin_username>"
lxc exec "$container" -- /var/discourse/launcher run "$longname" "$activate_admin"
echo "initialize discourse $longname ... OK"
}

21
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 <<EOF
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
\$(. /etc/os-release && echo "\$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /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"
}

4
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 <<EOF | lxc_exec "$container"

4
recipes/odoo15/crud.sh

@ -54,10 +54,10 @@ EOF
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 <<EOF | lxc_exec "$container"

Loading…
Cancel
Save