Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .ddev/.env.web
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ MERCURE_PUBLIC_URL=https://jitsi-admin.ddev.site:3000
MERCURE_JWT_SECRET=MDY3OTljNDM3MzRjMWU4ZmFkZTFlNzY5

MAILER_DSN=smtp://:@localhost:1025

MESSENGER_TRANSPORT_DSN=amqp://rabbitmq:rabbitmq@rabbitmq:5672/%2f/messages
13 changes: 13 additions & 0 deletions .ddev/addon-metadata/rabbitmq/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: rabbitmq
repository: ddev/ddev-rabbitmq
version: 0.2.0
install_date: "2026-02-02T12:01:24+01:00"
project_files:
- docker-compose.rabbitmq.yaml
- config.rabbitmq.yaml
- commands/host/rabbitmq
- commands/rabbitmq/
- rabbitmq/config.yaml
- rabbitmq/schema.json
global_files: []
removal_actions: []
40 changes: 40 additions & 0 deletions .ddev/commands/host/rabbitmq
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
#ddev-generated

## Description: A host wrapper command for rabbitmq/rabbitmq to enhance the command with "launch" capabilities
## Usage: rabbitmq
## Example: ddev rabbitmq

CMD=$1

launch_rabbitmq_gui() {
echo "Launching RabbitMQ Management UI..."
echo "Login using 'rabbitmq' user and 'rabbitmq' password."

PROTOCOL="HTTP"
if [ "${DDEV_PRIMARY_URL%://*}" != "http" ] && [ -z "${GITPOD_WORKSPACE_ID:-}" ] && [ "${CODESPACES:-}" != "true" ]; then
PROTOCOL="HTTPS"
fi
rabbitmq_port=$(ddev exec "yq '.services.rabbitmq.environment.${PROTOCOL}_EXPOSE | split(\":\")[0]' .ddev/.ddev-docker-compose-full.yaml")
ddev launch :$rabbitmq_port
}

case $CMD in
launch)
launch_rabbitmq_gui
;;
*)
if [ "$CMD" = "--help" ] || [ -z "$CMD" ]; then
# Output help and display additional information about the "launch" command
ddev exec -s rabbitmq /mnt/ddev_config/commands/rabbitmq/rabbitmq --help
echo ""
echo -e "\033[1mLaunch\033[0m"
echo "—————"
echo "Launch RabbitMQ Management UI"
echo "👉 ddev rabbitmq launch"
else
# Run the script within service container and pass in all arguments
ddev exec -s rabbitmq /mnt/ddev_config/commands/rabbitmq/rabbitmq $@
fi
;;
esac
176 changes: 176 additions & 0 deletions .ddev/commands/rabbitmq/rabbitmq
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/usr/bin/env bash
#ddev-generated

## Description: Manage parts of rabbitmq
## Usage: rabbitmq
## Example: ddev rabbitmq

CMD=$1

# Subcommands allowed to watch
ALLOWED_DISPLAY_ARGUMENTS=("overview" "connections" "channels" "consumers" "exchanges" "queues" "bindings" "users" "vhosts" "permissions" "nodes" "parameters" "policies" "operator_policies" "vhost_limits" )

YAML_FILE=/mnt/ddev_config/rabbitmq/config.yaml

function watcher() {
subcommand=$1
interval=$2

if [ "$subcommand" = "overview" ]; then
display_argument="show $subcommand"
else
display_argument="list $subcommand"
fi

if [[ " ${ALLOWED_DISPLAY_ARGUMENTS[*]} " = *" $subcommand "* ]]; then
while true; do
output=$(rabbitmqadmin "$display_argument")
clear
echo "$output"
echo "Refresh interval: $interval sec - $(date)"
sleep $interval
done
else
echo -e "Watch subcommand '$subcommand' not allowed, use one of these:\n * ${ALLOWED_DISPLAY_ARGUMENTS[*]}"
fi
}

function add_vhosts() {
vhosts_json=$(rabbitmqctl list_vhosts --formatter json)
readarray vhosts_existing < <(echo "$vhosts_json" | yq -o=y -I=0 '.[].name' -)
readarray vhosts < <(yq -o=j -I=0 '.vhost[]' $YAML_FILE )
for vhost in "${vhosts[@]}"; do
name=$(echo "$vhost" | yq '.name // ""' -)

if [[ ! " ${vhosts_existing[*]} " =~ $name ]]; then
description=$(echo "$vhost" | yq '.description // ""' -)
description_option=$([ -z "$description" ] && echo "" || echo "--description \"$description\"")

default_queue_type=$(echo "$vhost" | yq '.default-queue-type // ""' -)
default_queue_type_option=$([ -z "$default_queue_type" ] && echo "" || echo "--default-queue-type $default_queue_type")

tags=$(echo "$vhost" | yq '.tags[]' -)
comma_separated=$(echo "${tags[*]}" | xargs | sed -e 's/ /,/g')
tags_option=$([ -z "$comma_separated" ] && echo "" || echo "--tags $comma_separated")

rabbitmqctl add_vhost $name $description_option $tags_option $default_queue_type_option || exit 1
else
echo "ℹ️ vhost '$name' already exists! To update a vhost please delete it first."
fi
done
}

function add_queues() {
readarray queues < <(yq -o=j -I=0 '.queue[]' $YAML_FILE )
for queue in "${queues[@]}"; do
name=$(echo "$queue" | yq '.name' -)
vhost=$(echo "$queue" | yq '.vhost // "/"' -)

queues_existing=$(rabbitmqctl list_queues --silent --formatter json --vhost "$vhost")
readarray queues_existing < <(echo "$queues_existing" | yq -o=y -I=0 '.[].name' -)

if [[ ! " ${queues_existing[*]} " =~ $name ]]; then
durable=$(echo "$queue" | yq '.durable // "true"' -)
rabbitmqadmin declare queue --vhost="$vhost" --name="$name" --durable="$durable" || exit 1
else
echo "ℹ️ Queue '$name' already exists in vhost '$vhost'! To update the queue please delete it first."
fi
done
}

function add_users() {
users_json=$(rabbitmqctl list_users --silent --formatter json)
readarray users_existing < <(echo "$users_json" | yq -o=y -I=0 '.[].user' -)
readarray users < <(yq -o=j -I=0 '.user[]' $YAML_FILE )

for user in "${users[@]}"; do
name=$(echo "$user" | yq '.name // ""' -)

if [[ ! " ${users_existing[*]} " =~ $name ]]; then
password=$(echo "$user" | yq '.password // ""' -)
rabbitmqctl add_user "$name" "$password" || exit 1

tags=$(echo "$user" | yq '.tags[]' -)
comma_separated=$(echo "${tags[*]}" | xargs | sed -e 's/ /,/g')
rabbitmqctl set_user_tags "$name" "$comma_separated" || exit 1

permissions=$(echo "$user" | yq '.permissions[]' -)
for permission in "${permissions[@]}"; do
vhost=$(echo "$permission" | yq '.vhost // "/"' -)
conf=$(echo "$permission" | yq '.conf // ".*"' -)
write=$(echo "$permission" | yq '.write // ".*"' -)
read=$(echo "$permission" | yq '.read // ".*"' -)
rabbitmqctl set_permissions -p "$vhost" "$name" "$conf" "$write" "$read" || exit 1
done
else
echo "ℹ️ User '$name' already exists! To update a user please delete it first."
fi
done
}

case $CMD in
apply)
echo "Apply config $YAML_FILE"

plugins_array=$(yq eval '.plugins[]' "$YAML_FILE")
plugins=$(echo "${plugins_array[*]}" | tr '\n' ' ' | xargs)
rabbitmq-plugins enable $plugins

add_vhosts
# Ensure the default admin "rabbitmq" has permissions for all virtual hosts
rabbitmqctl set_permissions_globally "rabbitmq" ".*" ".*" ".*" > /dev/null
add_queues
add_users
;;

wipe)
users_json=$(rabbitmqctl list_users --silent --formatter json)
readarray users_existing < <(echo "$users_json" | yq -o=y -I=0 '.[].user' -)
for user in "${users_existing[@]}"; do
user=$(echo -n "$user" | tr -d '\n')
if [ "$user" != "rabbitmq" ]; then
rabbitmqctl delete_user "$user"
fi
done

vhosts_json=$(rabbitmqctl list_vhosts --formatter json)
readarray vhosts_existing < <(echo "$vhosts_json" | yq -o=y -I=0 '.[].name' -)
for host in "${vhosts_existing[@]}"; do
host=$(echo -n "$host" | tr -d '\n')
if [ "$host" != "/" ]; then
rabbitmqctl delete_vhost "$host"
fi
done
;;
watch)
subcommand="$2"
subcommand=${subcommand:=overview}
interval="$3"
interval=${interval:=2}

watcher "$subcommand" "$interval"
;;

--help|*)
echo "——————————————"
echo -e "\033[1mExample Usage:\033[0m"
echo "——————————————"
echo -e "\033[1mApply\033[0m"
echo "—————"
echo "Create queues, users and add 'plugins' according to configuration (see .ddev/rabbitmq/config.yaml)"
echo "👉 ddev rabbitmq apply"
echo ""
echo -e "\033[1mWipe\033[0m"
echo "—————"
echo "Clear vhosts, queues and users (only vhost '/' and user 'rabbitmq' are kept)"
echo "👉 ddev rabbitmq wipe"
echo ""
echo -e "\033[1mWatcher\033[0m"
echo "———————"
echo "A little wrapper around 'rabbitmqadmin' to be able to watch e.g. queues"
echo "👉 ddev rabbitmq watch <command> <interval>"
echo -e "Possible <command> values:\n * ${ALLOWED_DISPLAY_ARGUMENTS[*]}"
echo ""
echo -e "ℹ️ To use the rabbitmqadmin command run 'ddev rabbitmqadmin --help' for details.\nThis command passes all values to rabbitmqadmin within the container."
;;
esac
8 changes: 8 additions & 0 deletions .ddev/commands/rabbitmq/rabbitmqadmin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#ddev-generated

## Description: Manage parts of rabbitmq
## Usage: rabbitmqadmin [options] subcommand
## Example: ddev rabbitmqadmin --help

rabbitmqadmin $@
8 changes: 8 additions & 0 deletions .ddev/commands/rabbitmq/rabbitmqctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#ddev-generated

## Description: Manage parts of rabbitmq
## Usage: rabbitmqctl [--node <node>] [--timeout <timeout>] [--longnames] [--quiet] <command> [<command options>]
## Example: ddev rabbitmqctl --help

rabbitmqctl $@
2 changes: 2 additions & 0 deletions .ddev/config.rabbitmq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#ddev-generated
webimage_extra_packages: ["php${DDEV_PHP_VERSION}-amqp"]
43 changes: 43 additions & 0 deletions .ddev/docker-compose.rabbitmq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ddev-generated
services:
rabbitmq:
container_name: ddev-${DDEV_SITENAME}-rabbitmq
hostname: ${DDEV_SITENAME}-rabbitmq
image: ${RABBITMQ_DOCKER_IMAGE:-rabbitmq:4-management}-${DDEV_SITENAME}-built
build:
dockerfile_inline: |
ARG RABBITMQ_DOCKER_IMAGE="scratch"
FROM $${RABBITMQ_DOCKER_IMAGE}
RUN command -v apk >/dev/null 2>&1 || { (apt-get update || true) && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*; }
ARG TARGETARCH
RUN command -v apk >/dev/null 2>&1 && apk add --no-cache yq || { curl -fsSL "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$${TARGETARCH}" -o /usr/bin/yq && chmod +x /usr/bin/yq; }
args:
RABBITMQ_DOCKER_IMAGE: ${RABBITMQ_DOCKER_IMAGE:-rabbitmq:4-management}
expose:
- 15672
environment:
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=15672:15672
- HTTPS_EXPOSE=15673:15672
- RABBITMQ_ERLANG_COOKIE=SWQOKODSQALRPCLNMEQG
- RABBITMQ_DEFAULT_USER=rabbitmq
- RABBITMQ_DEFAULT_PASS=rabbitmq
- RABBITMQ_DEFAULT_VHOST=/
- RABBITMQADMIN_USERNAME=rabbitmq
- RABBITMQADMIN_PASSWORD=rabbitmq
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: ${DDEV_APPROOT}
volumes:
- "rabbitmq:/var/lib/rabbitmq/mnesia"
- ".:/mnt/ddev_config"
- "ddev-global-cache:/mnt/ddev-global-cache"
x-ddev:
describe-info: |
User: rabbitmq
Pass: rabbitmq
ssh-shell: bash

volumes:
rabbitmq:
name: "${DDEV_SITENAME}_rabbitmq"
25 changes: 25 additions & 0 deletions .ddev/rabbitmq/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ddev-generated
vhost:
- name: ddev-vhost
default-queue-type: classic
queue:
- name: ddev-queue
vhost: ddev-vhost
durable: true
- name: ddev-additional
vhost: ddev-vhost
durable: true
user:
- name: ddev-admin
password: password
tags:
- administrator
- management
permissions:
- vhost: ddev-vhost
conf: .*
write: .*
read: .*
plugins:
# Required!
- rabbitmq_management
Loading