diff --git a/docker-compose.yaml b/docker-compose.yaml index 03a6e862b6..286e41f2d8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,8 @@ version: '3.2' + +volumes: + broker: {} + services: api-db: image: ${IMAGE_REPO:-lagoon}/api-db @@ -26,6 +30,17 @@ services: ports: - '15672:15672' - '5672:5672' + hostname: broker + volumes: + - broker:/var/lib/rabbitmq + broker-ff-enable: + image: ${IMAGE_REPO:-lagoon}/broker + entrypoint: /enable-feature-flags.sh + environment: + - SERVICE_NAME=broker + depends_on: + broker: + condition: service_started logs2notifications: image: ${IMAGE_REPO:-lagoon}/logs2notifications environment: diff --git a/services/broker/Dockerfile b/services/broker/Dockerfile index c9c177d77d..52c27634c0 100644 --- a/services/broker/Dockerfile +++ b/services/broker/Dockerfile @@ -1,21 +1,26 @@ ARG UPSTREAM_REPO ARG UPSTREAM_TAG FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} as commons -FROM rabbitmq:3.10.25-management-alpine +FROM rabbitmq:3.11.28-management-alpine ARG LAGOON_VERSION ENV LAGOON_VERSION=$LAGOON_VERSION -ENV RABBITMQ_DEFAULT_USER='guest' \ - RABBITMQ_DEFAULT_PASS='guest'\ - RABBITMQ_DEFAULT_HA_PATTERN='^$'\ +ENV SERVICE_NAME='0.0.0.0' \ + RABBITMQ_DEFAULT_USER='guest' \ + RABBITMQ_DEFAULT_PASS='guest' \ + RABBITMQ_DEFAULT_HA_PATTERN='^$' \ RABBITMQ_DEFAULT_VHOST='/' \ - RABBITMQ_DEFAULT_HA_PATTERN='^lagoon-'\ + RABBITMQ_DEFAULT_HA_PATTERN='^lagoon-' \ RABBITMQ_ERLANG_COOKIE=5188fd99edf19acfefcbb29a16f3d373aa01f66bfe89929852dfad2674d36af2 COPY --from=commons /bin/ep /bin/fix-permissions /bin/ -RUN wget -P /plugins https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.10.2/rabbitmq_delayed_message_exchange-3.10.2.ez \ +RUN apk add --no-cache \ + gojq \ + curl + +RUN wget -P /plugins https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/3.11.1/rabbitmq_delayed_message_exchange-3.11.1.ez \ && chown rabbitmq:rabbitmq /plugins/rabbitmq_delayed_message_exchange-* # override sticky bit set in upstream whilst we still ep the files in /etc/rabbitmq @@ -24,8 +29,8 @@ RUN chmod 0777 /var/lib/rabbitmq /etc/rabbitmq /etc/rabbitmq/conf.d /tmp/rabbitm COPY definitions.json enabled_plugins rabbitmq.conf /etc/rabbitmq/ RUN fix-permissions /etc/rabbitmq -COPY start-rabbit.sh / -RUN fix-permissions start-rabbit.sh && chmod +x /start-rabbit.sh +COPY start-rabbit.sh enable-feature-flags.sh / +RUN fix-permissions start-rabbit.sh enable-feature-flags.sh && chmod +x /start-rabbit.sh /enable-feature-flags.sh # Copy the new entrypoint for b/c reasons COPY /start-rabbit.sh /cluster-rabbit.sh diff --git a/services/broker/enable-feature-flags.sh b/services/broker/enable-feature-flags.sh new file mode 100755 index 0000000000..74ffebf75c --- /dev/null +++ b/services/broker/enable-feature-flags.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# This script needs to be run after a minor version update (or prior to one) +# to ensure that any disabled feature_flags are correctly enabled. + +function is_broker_running { + local http_code=$(curl -s -o /dev/null -w "%{http_code}" -u "${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}" "http://${SERVICE_NAME}:15672/api/health/checks/virtual-hosts/") + if [[ $http_code -eq 200 ]]; then + return 0 + else + return 1 + fi +} + +echo check broker is running +until is_broker_running; do + echo Broker not running, waiting 2 seconds + sleep 2 +done + +echo enabling any disabled feature flags +for feature in $(curl -s -u "${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}" "http://${SERVICE_NAME}:15672/api/feature-flags/" | gojq -r '.[] | select(.state=="disabled") | .name'); do + echo " - enabling ${feature}" + curl -X PUT --header "Content-Type: application/json" -s -u "${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}" -d '{"name":"'${feature}'"}' http://${SERVICE_NAME}:15672/api/feature-flags/${feature}/enable +done + +echo all feature flags enabled