Browse Source

domain + subdomain

main
pvincent 1 month ago
parent
commit
ac7268731a
  1. 22
      recipes/base/common.sh
  2. 17
      recipes/cagettepei/crud.sh
  3. 42
      recipes/discourse/crud.sh
  4. 10
      recipes/dolibarr/crud.sh
  5. 10
      recipes/odoo12/crud.sh
  6. 10
      recipes/odoo15/crud.sh
  7. 6
      recipes/stub/crud.sh
  8. 10
      recipes/wordpress/crud.sh
  9. 3
      scripts/miaou
  10. 77
      templates/apps/discourse/forum.yml.j2

22
recipes/base/common.sh

@ -0,0 +1,22 @@
#!/bin/bash
function check_db_maria_exists() {
db-maria list | grep -q "$1"
}
function check_db_postgres_exists() {
db-psql list | grep -q "$1"
}
function extract_domain_from_fqdn() {
fqdn=$1
part1=$(builtin echo "$fqdn" | rev | cut -d'.' -f1 | rev)
part2=$(builtin echo "${fqdn%."$part1"}" | rev | cut -d'.' -f1 | rev)
builtin echo "$part2.$part1"
}
function extract_subdomain_from_fqdn() {
fqdn=$1
domain=$(extract_domain_from_fqdn "$fqdn")
builtin echo "${fqdn%."$domain"}"
}

17
recipes/cagettepei/crud.sh

@ -1,9 +1,5 @@
#!/bin/bash #!/bin/bash
function check_database_exists() {
db-maria list | grep -q "$longname"
}
function check_port_used() { function check_port_used() {
# shellcheck disable=SC2034 # shellcheck disable=SC2034
usedport=$(lxc exec "$container" -- bash -c "grep Listen /etc/apache2/sites-enabled/$longname.conf | cut -d' ' -f2") usedport=$(lxc exec "$container" -- bash -c "grep Listen /etc/apache2/sites-enabled/$longname.conf | cut -d' ' -f2")
@ -21,7 +17,7 @@ function check_config_defined() {
function _read() { function _read() {
disable_trace disable_trace
check_database_exists
check_db_maria_exists "$longname"
check_container "$container" check_container "$container"
check_port_used check_port_used
check_config_defined check_config_defined
@ -139,11 +135,12 @@ function usage() {
# init_strict # init_strict
source "$(dirname "$0")/../base/common.sh"
COMMAND_NAME=$(basename "$0") COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -175,6 +172,12 @@ while true; do
longname="cagettepei-$shortname" longname="cagettepei-$shortname"
shift 2 shift 2
;; ;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c) -c)
[[ "$action" == "unset" ]] || usage [[ "$action" == "unset" ]] || usage
action="_create" action="_create"
@ -200,7 +203,7 @@ while true; do
break break
;; ;;
*) *)
echo "Internal error!"
echo "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac

42
recipes/discourse/crud.sh

@ -1,12 +1,26 @@
#!/bin/bash #!/bin/bash
function check_service_running() {
lxc exec "$container" -- bash -c "docker ps --format {{.Names}} | grep $1"
}
function _read() { function _read() {
disable_trace
check_db_postgres_exists "$longname"
check_container "$container"
check_service_running "$shortname"
enable_trace
return 0 return 0
} }
function _create() { function _create() {
echo "creating discourse-docker instance for <$shortname> ... "
echo "initialize discourse-docker $shortname $longname ... OK"
echo "creating discourse instance for <$shortname> ... "
echo "initialize discourse $shortname $longname ... OK"
mkdir -p "$MIAOU_CONFIGDIR/apps/discourse"
APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$shortname 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"
echo "creating templates ... OK"
} }
function _update() { function _update() {
@ -25,12 +39,12 @@ function usage() {
### MAIN ### MAIN
# init_strict # init_strict
source "$(dirname "$0")/../base/common.sh"
COMMAND_NAME=$(basename "$0") COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -41,7 +55,8 @@ container="unset"
shortname="unset" shortname="unset"
longname="unset" longname="unset"
fqdn="unset" fqdn="unset"
data="unset"
domain="unset"
subdomain="unset"
# extract options and their arguments into variables. # extract options and their arguments into variables.
while true; do while true; do
@ -60,11 +75,19 @@ while true; do
;; ;;
--name) --name)
shortname=$2 shortname=$2
longname="cagettepei-$shortname"
longname="discourse-$shortname"
shift 2
;;
--domain)
domain=$2
shift 2
;;
--subdomain)
subdomain=$2
shift 2 shift 2
;; ;;
--data) --data)
data=$2
# don't care
shift 2 shift 2
;; ;;
-c) -c)
@ -92,7 +115,7 @@ while true; do
break break
;; ;;
*) *)
echo "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac
@ -103,7 +126,8 @@ done
"$port" != unset && "$port" != unset &&
"$container" != unset && "$container" != unset &&
"$fqdn" != unset && "$fqdn" != unset &&
"$data" != unset &&
"$domain" != unset &&
"$subdomain" != unset &&
"$shortname" != unset ]] || usage "$shortname" != unset ]] || usage
. "$MIAOU_BASEDIR/lib/init.sh" . "$MIAOU_BASEDIR/lib/init.sh"

10
recipes/dolibarr/crud.sh

@ -108,7 +108,7 @@ COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -138,6 +138,12 @@ while true; do
longname="dolibarr-$shortname" longname="dolibarr-$shortname"
shift 2 shift 2
;; ;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c) -c)
[[ "$action" == "unset" ]] || usage [[ "$action" == "unset" ]] || usage
action="_create" action="_create"
@ -163,7 +169,7 @@ while true; do
break break
;; ;;
*) *)
echo "Internal error!"
echo "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac

10
recipes/odoo12/crud.sh

@ -111,7 +111,7 @@ COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -144,6 +144,12 @@ while true; do
longname="odoo12-$shortname" longname="odoo12-$shortname"
shift 2 shift 2
;; ;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
--data) --data)
data=$2 data=$2
shift 2 shift 2
@ -173,7 +179,7 @@ while true; do
break break
;; ;;
*) *)
echoerr "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac

10
recipes/odoo15/crud.sh

@ -127,7 +127,7 @@ COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -164,6 +164,12 @@ while true; do
data=$2 data=$2
shift 2 shift 2
;; ;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c) -c)
[[ "$action" == "unset" ]] || usage [[ "$action" == "unset" ]] || usage
action="_create" action="_create"
@ -189,7 +195,7 @@ while true; do
break break
;; ;;
*) *)
echoerr "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac

6
recipes/stub/crud.sh

@ -30,7 +30,7 @@ COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -87,8 +87,8 @@ while true; do
break break
;; ;;
*) *)
echo "Internal error!"
exit 1
builtin echo "useless option $1"
shift 2
;; ;;
esac esac
done done

10
recipes/wordpress/crud.sh

@ -132,7 +132,7 @@ COMMAND_NAME=$(basename "$0")
# read the options # read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage [[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP" eval set -- "$TEMP"
@ -162,6 +162,12 @@ while true; do
longname="wp-$shortname" longname="wp-$shortname"
shift 2 shift 2
;; ;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c) -c)
[[ "$action" == "unset" ]] || usage [[ "$action" == "unset" ]] || usage
action="_create" action="_create"
@ -187,7 +193,7 @@ while true; do
break break
;; ;;
*) *)
echo "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1 exit 1
;; ;;
esac esac

3
scripts/miaou

@ -497,10 +497,11 @@ function build_services() {
recipe="$MIAOU_BASEDIR/recipes/$app/crud.sh" recipe="$MIAOU_BASEDIR/recipes/$app/crud.sh"
if [[ -f "$recipe" ]]; then if [[ -f "$recipe" ]]; then
echo "read [$app:$name] provided by container <$container>" echo "read [$app:$name] provided by container <$container>"
command="env MIAOU_BASEDIR=$MIAOU_BASEDIR MIAOU_CONFIGDIR=$MIAOU_CONFIGDIR $recipe --port $port --container $container --name $name --fqdn $fqdn"
command="env MIAOU_BASEDIR=$MIAOU_BASEDIR MIAOU_CONFIGDIR=$MIAOU_CONFIGDIR $recipe --port $port --container $container --name $name --fqdn $fqdn --domain $domain --subdomain $subdomain"
[[ "$data" != "null" ]] && command+=" --data \"$data\"" [[ "$data" != "null" ]] && command+=" --data \"$data\""
if ! eval "$command -r" >/dev/null; then if ! eval "$command -r" >/dev/null; then
echoinfo "CREATE RECIPE" echoinfo "CREATE RECIPE"
# echo "$command -c"
eval "$command -c" eval "$command -c"
echoinfo "CREATE RECIPE: OK" echoinfo "CREATE RECIPE: OK"
fi fi

77
templates/apps/discourse/forum.yml.j2

@ -0,0 +1,77 @@
# TODO: change SOME_SECRET in this template
templates:
- "templates/web.template.yml"
- "templates/web.ratelimited.template.yml"
expose:
- "{{ env.APP_PORT }}:80"
params:
## Which Git revision should this container use? (default: tests-passed)
#version: tests-passed
version: latest-release
env:
DISCOURSE_HOSTNAME: '{{ env.APP_FQDN }}'
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
# DISCOURSE_DEFAULT_LOCALE: en
## Uncomment if you want the container to be started with the same
## hostname (-h option) as specified above (default "$hostname-$config")
DOCKER_USE_HOSTNAME: true
## TODO: List of comma delimited emails that will be made admin and developer
## on initial signup example 'user1@example.com,user2@example.com'
DISCOURSE_DEVELOPER_EMAILS: 'pvincent@artcode.re'
## TODO: The SMTP mail server used to validate new accounts and send notifications
# SMTP ADDRESS, username, and password are required
# WARNING the char '#' in SMTP password can cause problems!
DISCOURSE_SMTP_ADDRESS: mail1.zourit.net
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: postmaster@artcode.re
DISCOURSE_SMTP_PASSWORD: bHv5mTYyh3aJJKw
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
#DISCOURSE_SMTP_DOMAIN: discourse.example.com # (required by some providers)
#DISCOURSE_NOTIFICATION_EMAIL: noreply@discourse.example.com # (address to send notifications from)
## TODO: configure connectivity to the databases
DISCOURSE_DB_NAME: libre.re
DISCOURSE_DB_USERNAME: libre.re
DISCOURSE_DB_PASSWORD: libre.re
DISCOURSE_DB_HOST: ct1.lxd
DISCOURSE_REDIS_HOST: ct1.lxd
volumes:
- volume:
host: /var/discourse/shared/web-only
guest: /shared
- volume:
host: /var/discourse/shared/web-only/log/var-log
guest: /var/log
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- git clone https://github.com/discourse/docker_manager.git
{%- if services[env.APP_DOMAIN][env.APP_SUBDOMAIN]['data']['discourse']['plugins'] %}
{%- for plugin in services[env.APP_DOMAIN][env.APP_SUBDOMAIN]['data']['discourse']['plugins'] %}
- git clone {{ plugin }}
{%- endfor %}
{%- endif %}
## Remember, this is YAML syntax - you can only have one block with a name
run:
- exec: echo "Beginning of custom commands"
- exec: echo "End of custom commands"
- exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'
Loading…
Cancel
Save