Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3764280
D1524.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D1524.diff
View Options
diff --git a/roles/paas-docker/wrappers/files/phpbb.sh b/roles/paas-docker/wrappers/files/phpbb.sh
--- a/roles/paas-docker/wrappers/files/phpbb.sh
+++ b/roles/paas-docker/wrappers/files/phpbb.sh
@@ -22,29 +22,61 @@
MYSQL_CONTAINER=phpbb_db
MYSQL_IMAGE=nasqueron/mysql
+MYSQL_HOST=phpbb-db.equatower.ulubis
+
+SERVICE_DIR=/srv/phpbb
# -------------------------------------------------------------
# Helper methods
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+error() {
+ echo "$@" 1>&2;
+}
+
getcommandname() {
basename "$0"
}
usage() {
- echo "Usage: $(getcommandname) <command>"
+ error "Usage: $(getcommandname) <command>"
exit 1
}
unknown_command() {
- echo "$(getcommandname): $COMMAND: unknown command"
+ error "$(getcommandname): $COMMAND: unknown command"
usage
}
+# -------------------------------------------------------------
+# Enviroment files methods
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ensure_environment_file_exists() {
+ [ -f "$1" ] || populate_environment_files
+ [ -f "$1" ] || help_create_container
+}
+
+populate_environment_files() {
+ cd $SERVICE_DIR/sites || exit 32
+ make
+}
+
+help_create_container() {
+ error "No environment information for container $CONTAINER"
+ error "If this is a new forum, you need first to populate the sites db."
+ error "To do so, run '$(getcommandname) add $CONTAINER'"
+ exit 16
+}
+
# -------------------------------------------------------------
# Commands
#
# :: phpbb storage: connects to MySQL database
+# :: phpbb add: populates site database with the new forum
+# :: phpbb run: creates and starts the forum container
+# :: phpbb postinstall: cleans install and provides config
+# :: phpbb etc-hosts: prints a /etc/host entry for MySQL container
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
phpbb_storage() {
@@ -53,6 +85,74 @@
sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
}
+phpbb_site_add() {
+ if [ $# -lt 2 ]; then
+ error "Usage: $(getcommandname) $COMMAND <forum identifier> <host>"
+ exit 2
+ fi
+ ID=$1
+ SITE_HOST=$2
+
+ sqlite3 -batch $SERVICE_DIR/sites/sites.db <<EOF
+ INSERT INTO sites
+ (id, host, db_user, db_password, db_prefix, active)
+ VALUES
+ ("$ID", "$SITE_HOST", "$ID", "$PASSWORD", "phpbb_", 1);
+EOF
+ run_maintenance_script createdb "$ID"
+}
+
+phpbb_container_run() {
+ if [ $# -lt 1 ]; then
+ error "$(getcommandname): $COMMAND: missing forum identifier"
+ exit 2
+ fi
+ ID=$1
+ CONTAINER=phpbb_$ID
+
+ # Environment information is extracted from a SQLite database
+ ENV_FILE=$SERVICE_DIR/sites/containers-env/$ID
+ ensure_environment_file_exists "$ENV_FILE"
+
+ # Loads environment for this container
+ # shellcheck disable=1090
+ . "$ENV_FILE"
+ [ -z "$SITE_HOST" ] && error "Enviroment isn't correctly defined." && exit 8
+
+ echo "TODO: switch to nasqueron/phpbb image."
+ docker run -d \
+ -v "/home/dereckson/dev/docker/phpbb/phpBB3:/var/wwwroot/default" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/cache:/var/wwwroot/default/cache" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/config:/var/wwwroot/default/config" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/ext:/var/wwwroot/default/ext" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/files:/var/wwwroot/default/files" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/images:/var/wwwroot/default/images" \
+ -v "$SERVICE_DIR/data/$SITE_HOST/store:/var/wwwroot/default/store" \
+ -v "$SERVICE_DIR/run/$SITE_HOST:/run/nginx" \
+ -e "PHPBB_DB_HOST=$MYSQL_HOST" \
+ -e "PHPBB_DB_USER=$DB_USER" \
+ -e "PHPBB_DB_PASSWORD=$DB_PASSWORD" \
+ -e "PHPBB_DB_NAME=$ID" \
+ --name "$CONTAINER" nasqueron/nginx-php7-fpm
+}
+
+phpbb_post_install() {
+ if [ $# -lt 1 ]; then
+ echo "$(getcommandname): $COMMAND: missing container name"
+ exit 2
+ fi
+ CONTAINER=phpbb_$1
+
+ docker exec "$CONTAINER" cp /usr/share/saas-phpbb/config.php /var/wwwroot/default/
+ docker exec "$CONTAINER" rm -rf /var/wwwroot/default/install
+}
+
+phpbb_etc_hosts() {
+ SELECT_IP=".[0].NetworkSettings.IPAddress"
+ MYSQL_CONTAINER_IP=$(docker inspect $MYSQL_CONTAINER | jq -r "$SELECT_IP")
+ echo "$MYSQL_CONTAINER_IP $MYSQL_HOST"
+}
+
# -------------------------------------------------------------
# Check arguments
#
@@ -73,6 +173,14 @@
if [ "$COMMAND" = "storage" ]; then
phpbb_storage
+elif [ "$COMMAND" = "postinstall" ]; then
+ phpbb_post_install "$1"
+elif [ "$COMMAND" = "add" ]; then
+ phpbb_site_add "$1"
+elif [ "$COMMAND" = "run" ]; then
+ phpbb_container_run "$1"
+elif [ "$COMMAND" = "etc-hosts" ]; then
+ phpbb_etc_hosts $MYSQL_CONTAINER
else
unknown_command
fi
diff --git a/roles/paas-docker/wrappers/init.sls b/roles/paas-docker/wrappers/init.sls
--- a/roles/paas-docker/wrappers/init.sls
+++ b/roles/paas-docker/wrappers/init.sls
@@ -18,3 +18,12 @@
- source: salt://roles/paas-docker/wrappers/files/{{ command }}.sh
- mode: 755
{% endfor %}
+
+# -------------------------------------------------------------
+# Dependencies
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+phpbb_dependencies:
+ pkg.installed:
+ - pkgs:
+ - jq
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 04:54 (17 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2257237
Default Alt Text
D1524.diff (5 KB)
Attached To
Mode
D1524: WIP: Allow to manage phpBB containers
Attached
Detach File
Event Timeline
Log In to Comment