Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DISCLAMER: since it is a community driven project it is only smoke-tested and co
| [sequelpro](sequelpro) | Launches [SequelPro](https://www.sequelpro.com) with the connection information for current project. | macOS |
| [simpletest](simpletest) | Runs SimpleTest tests in Drupal 7 and 8 | Drupal |
| [sitediff](sitediff) | Runs Sitediff tests in your Docksal project | |
| [soketi](soketi) | [Socketi](https://docs.soketi.app/) Soketi is your simple, fast, and resilient open-source WebSockets server | |
| [solr](solr) | [Apache Solr](http://lucene.apache.org/solr/) search service for current project | |
| [tableplus](tableplus) | Launches [TablePlus](https://www.tableplus.com) with the connection information for current project. | macOS |
| [uli](uli) | Generate one time login url for current site | Drupal |
Expand Down
8 changes: 8 additions & 0 deletions socketi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Socketi Docksal addon

Soketi is your simple, fast, and resilient open-source WebSockets server


## Known issues

Does not work with SSL currently
15 changes: 15 additions & 0 deletions socketi/conf/socketi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#socketi settings
soketi:
hostname: socketi
image: quay.io/soketi/soketi:latest-16-debian
labels:
- io.docksal.virtual-host=socketi.${VIRTUAL_HOST}
ports:
- "${SOKETI_PORT:-6001}:6001"
- "${SOKETI_METRICS_SERVER_PORT:-9601}:9601"
environment:
SOKETI_DEBUG: "1"
SOKETI_METRICS_SERVER_PORT: "9601"
dns:
- ${DOCKSAL_DNS1}
- ${DOCKSAL_DNS2}
165 changes: 165 additions & 0 deletions socketi/socketi
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env bash

VERSION="1.0"

## Socketi addon
##
## Adds the node socket running connection (pusher compatable)
## to your stack: https://docs.soketi.app/
##
## fin example <command>
##
## Usage:
## enable enable socketi
## disable disable socketi



# Console colors
red='\033[0;91m'
red_bg='\033[101m'
yellow_bg='\033[43;90m'
green='\033[0;32m'
green_bg='\033[42m'
yellow='\033[0;33m'
yellow_bold='\033[1;33m'
NC='\033[0m'

echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
die () { echo -e "$1"; exit 1; }

DOCKSAL_YML=".docksal/docksal.yml"
DOCKSAL_YML_NEW=".docksal/docksal.yml.new"
DOCKSAL_ENV=".docksal/docksal.env"
DOCKSAL_STACKS="$HOME/.docksal/stacks"
SOCKETI_YML="$ADDON_ROOT/conf/socketi.yml"

#----------------------------------- YML & config functions ------------------------------------------

# Check whether given string is in config
# $1 - string to find
in_config ()
{
fin config 2>/dev/null | grep "$1" >/dev/null
}

# Check that docksal.yml is valid
yml_is_valid ()
{
[[ -f "$DOCKSAL_YML" ]] && $(cat "$DOCKSAL_YML" 2>/dev/null | grep "services" >/dev/null)
}

# Prepares stack to editing docksal.yml config
yml_prepare ()
{
# Get yml version to use for a new file from existing stacks
YML_VERSION=$(head "$DOCKSAL_STACKS/volumes-bind.yml" | grep "version")
YML_DEFAULT_BODY="${YML_VERSION}\nservices:"
NEW_STACK='DOCKSAL_STACK="default"'

# Source docksal.env
source "$DOCKSAL_ENV" >/dev/null 2>&1

# If DOCKSAL_STACK is not set, then...
if [[ -z "$DOCKSAL_STACK" ]]; then
echo " Configuring to use DOCKSAL_STACK=\"default\"..."
# ...set stack to default so we could use docksal.yml
echo -e "$NEW_STACK" >> "$DOCKSAL_ENV"
fi

# Create docksal.yml if needed
yml_is_valid || echo -e "$YML_DEFAULT_BODY" >> "$DOCKSAL_YML"
}

# Install tool required to edit yml from command line
yml_install_tools ()
{
fin exec "which yaml >/dev/null 2>&1 || npm install --silent -g yaml-cli >/dev/null"
}

# Add a service to docksal.yml from another yml
# $1 - filename of yml get service from
yml_add_service ()
{
[[ -z "$1" ]] && echo "File not found: $1" && return 1
# TODO: use https://www.npmjs.com/package/merge-yaml
cat "$1" >> "$DOCKSAL_YML"
}

# Removes a service from docksal.yml
# $1 - service name
yml_remove_service ()
{
[[ -z "$1" ]] && echo "Provide a service name to remove" && return 1
local service="$1"
read -r -d '' CODE_TO_EXEC <<-EOF
yaml set $DOCKSAL_YML services.$service | grep -v '$service:' | tee $DOCKSAL_YML_NEW >/dev/null;
[[ -z "\$(yaml get $DOCKSAL_YML_NEW services)" ]] && rm '$DOCKSAL_YML' || mv $DOCKSAL_YML_NEW $DOCKSAL_YML
EOF
# Remove service. If no services left after that, then remove docksal.yml
fin exec "$CODE_TO_EXEC"
}

#-------------------------------------- socketi functions ---------------------------------------------

# Set/remove proper setting into php.ini
# $1 - enable/disable
# Enable container and settings
socketi_enable ()
{
# Check that socketi is not already enabled
if (in_config "image: quay.io/soketi/soketi:latest-16-debian"); then
echo " socketi support is already enabled." && exit
fi

echo " Enabling socketi..."
yml_prepare
# Add socketi service to docksal.yml
yml_add_service "$SOCKETI_YML"
# Apply stack changes.
fin stop cli
fin up
}

# Disable container and settings
socketi_disable ()
{
echo " Running checks..."
# Make sure cli container is running
if ! (fin ps | grep "_cli_" | grep "Up" >/dev/null); then
echo " ERROR: Start the project with fin start first" && exit 1
fi

# Make sure socketi is installed
if ! in_config "image: quay.io/soketi/soketi:latest-16-debian"; then
echo " socketi support is not enabled at the moment." && exit
fi

echo " Preparing to remove socketi service..."
yml_install_tools
# Remove socketi service from docksal.yml
yml_remove_service "socketi"
# Apply stack changes
COMPOSE_FILE="" fin stop cli
fin up
}

#------------------------------------------ Runtime -----------------------------------------------

cd "$PROJECT_ROOT"

case "$1" in
enable)
socketi_enable
;;
disable)
socketi_disable
;;
*)
echo "Usage: fin socketi <enable|disable>"
exit 1
;;
esac
8 changes: 8 additions & 0 deletions socketi/socketi.filelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Hooks
socketi.pre-install
socketi.post-install
socketi.pre-uninstall

# Container config
conf/socketi.yml

20 changes: 20 additions & 0 deletions socketi/socketi.post-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
!/usr/bin/env bash

# Console colors
red='\033[0;91m'
red_bg='\033[101m'
yellow_bg='\033[43;90m'
green='\033[0;32m'
green_bg='\033[42m'
yellow='\033[0;33m'
yellow_bold='\033[1;33m'
NC='\033[0m'


echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
fin socketi enable

echo-green "Socketi uri:${yellow} http://socketi.$VIRTUAL_HOST${NC}"
42 changes: 42 additions & 0 deletions socketi/socketi.pre-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Check Docksal running
if [[ "$DOCKER_RUNNING" != "true" ]]; then
echo "[PRE-INSTALL] ERROR: Docksal and project should be running"
exit 1
fi

# Check Docksal running
if [[ "$ADDON_GLOBAL" == "true" ]]; then
echo -e "[PRE-INSTALL] ERROR: Socketi addon should not be installed globally"
exit 1
fi


# Check project running
if ! (fin ps | grep "_cli_" | grep "Up" >/dev/null); then
echo "[PRE-INSTALL] ERROR: Start the project with fin start first"
exit 1
fi

# Get fin config
fin_config=$(fin config)
if [[ $? != 0 ]]; then
echo "[PRE-INSTALL] ERROR: 'fin config' command was not successful. Check your fin config"
exit 1
fi

# Check there is no socketi already
if (echo "$fin_config" | grep "image: quay.io/soketi/soketi:latest-16-debian"); then
echo "[PRE-INSTALL] ERROR: Socketi seems to be already enabled for this project"
exit 1
fi

# Check there is no socketi already
if (echo "$fin_config" | grep " soketi:"); then
echo "[PRE-INSTALL] ERROR: Container named 'soketi' already exists. Remove it to continue."
exit 1
fi

# All good
exit 0
3 changes: 3 additions & 0 deletions socketi/socketi.pre-uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

fin socketi disable