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
9 changes: 0 additions & 9 deletions .build/mysql/init.sql

This file was deleted.

63 changes: 0 additions & 63 deletions .build/rabbitmq/definitions.json

This file was deleted.

31 changes: 31 additions & 0 deletions .build/rabbitmq/definitions.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"rabbit_version": "{RABBITMQ_VERSION}",
"rabbitmq_version": "{RABBITMQ_VERSION}",
"product_name": "RabbitMQ",
"product_version": "{RABBITMQ_VERSION}",
"users": [
{
"name": "{RABBITMQ_USER}",
"password": "{RABBITMQ_PASS}",
"tags": "administrator"
}
],
"vhosts": [{VHOSTS_LIST}],
"permissions": [{PERMISSIONS_LIST}],
"topic_permissions": [],
"parameters": [],
"global_parameters": [
{
"name": "cluster_name",
"value": "rabbit@a8d5c6e08439"
},
{
"name": "internal_cluster_id",
"value": "rabbitmq-cluster-id-gXeBLbsUC2W2tU0Bx_QY_w"
}
],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}
16 changes: 10 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
DOCKER_GROUP=php_not_dead
UID=1000

# Some DB configs are duplicated in .build/mysql/init.sql
DB_DOCKER_PORT=3310
DB_DATABASE="localstack"
DB_USERNAME="localstack"
DB_PASSWORD="password"
DB_ROOT_PASSWORD="password"
DB_DOCKER_PORT=3306
DB_DATABASE=php_not_dead
DB_USERNAME=php_not_dead
DB_PASSWORD=password
DB_ROOT_PASSWORD=password
DB_SCHEMAS=test1,test2
MYSQL_VERSION=8.4.6

REDIS_PASSWORD=password
REDIS_PORT=6379

RABBITMQ_VERSION=4.1.4
RABBITMQ_PORT=5672
RABBITMQ_MANAGER_PORT=15672
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
RABBITMQ_VHOSTS=/,test1,test2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea
.rabbitmq
docker-compose.override.yml
.build/mysql/init.sql
.build/rabbitmq/definitions.json
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
start:
docker-compose up -d
./builders/build_mysql.sh
./builders/build_rabbitmq.sh
docker compose up -d

stop:
docker-compose down
docker compose down

db-restore:
docker compose down
./builders/build_mysql.sh --rebuild=1
sudo docker volume rm localstack_mysql

mq-restore:
docker compose down
./builders/build_rabbitmq.sh --rebuild=1
sudo rm -rf .rabbitmq

list:
docker-compose ps
docker compose ps

list-all:
docker ps -a

mysql:
docker-compose exec mysql bash
docker compose exec mysql bash

redis:
docker-compose exec redis redis-cli
docker compose exec redis redis-cli

rabbitmq:
docker-compose exec rabbitmq bash
docker compose exec rabbitmq bash
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ MySQL image must be saved in GitHub packages in case of global deprecation.
1. `docker pull mysql:8.4.6` - pull preferred version of MySQL
2. `docker tag mysql:8.4.6 ghcr.io/php-not-dead/mysql:8.4.6` - create `ghcr.io/php-not-dead` for new version
3. `docker push ghcr.io/php-not-dead/mysql:8.4.6`
4. Replace `docker-compose.yml` line `image: ghcr.io/php-not-dead/mysql:8.4.5` with proper version `image: ghcr.io/php-not-dead/mysql:8.4.6`
4. Update `.env` and `.env.example` variable `MYSQL_VERSION` with proper version
5. `make stop`
6. `make db-restore` - will TRUNCATE all schemas and data
6. `make db-restore` - will TRUNCATE all schemas and data, rebuild init.sql
7. `make start`
All historical MySQL images are stored here: https://github.com/php-not-dead/dockerfiles/pkgs/container/mysql

## Add/remove MySQL schema
1. Update `.build/mysql/init.sql` - add/remove database and grant all permissions to new schema
1. Update `.env` file `DB_SCHEMAS` list - add/remove database
2. `make stop`
3. `make db-restore` - will TRUNCATE all schemas and data
4. `make start` - will create new list of schemas
Expand Down Expand Up @@ -60,6 +60,6 @@ RabbitMQ image must be saved in GitHub packages in case of global deprecation.
10. `make start`

## Add RabbitMQ vhost
1. Update `.build/rabbitmq/definitions.json` - add/remove vhost to `vhosts` and `permissions`
1. Update `.env` file `RABBITMQ_VHOSTS` list - add/remove vhosts
2. `make stop`
3. `make start`
44 changes: 44 additions & 0 deletions builders/build_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

WORK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "${WORK_DIR}/read_env.sh"

ENV_FILE="${WORK_DIR}/../.env"
INIT_FILE="${WORK_DIR}/../.build/mysql/init.sql"

if [ "$1" == "--rebuild=1" ]; then
REBUILD=true
fi

if [ -f "$INIT_FILE" ] && [ "$REBUILD" != true ]; then
echo 'MySQL init.sql file is already build. Skipping.'

exit
fi

if [ -f "$INIT_FILE" ] && [ "$REBUILD" == true ]; then
echo 'Re-building MySQL init.sql file'

rm "$INIT_FILE"
else
echo 'Building MySQL init.sql file'
fi

DB_USERNAME=$(env DB_USERNAME)
DB_PASSWORD=$(env DB_PASSWORD)
DB_SCHEMAS_LIST=()

SOURCE=''

# Create schemas and grant master user privileges
env_array DB_SCHEMAS DB_SCHEMAS_LIST
for DB_SCHEMA in "${DB_SCHEMAS_LIST[@]}"; do
SOURCE="$SOURCE"$"CREATE DATABASE IF NOT EXISTS ${DB_SCHEMA};"$'\n'
SOURCE="$SOURCE"$"GRANT ALL PRIVILEGES ON ${DB_SCHEMA}.* TO '${DB_USERNAME}'@'%';"$'\n\n'
done;

# Flush privileges
SOURCE="$SOURCE"$'FLUSH PRIVILEGES;'

echo "$SOURCE" > "$INIT_FILE"
57 changes: 57 additions & 0 deletions builders/build_rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

WORK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "${WORK_DIR}/read_env.sh"

ENV_FILE="${WORK_DIR}/../.env"
TEMPLATE_FILE="${WORK_DIR}/../.build/rabbitmq/definitions.template.json"
DEFINITIONS_FILE="${WORK_DIR}/../.build/rabbitmq/definitions.json"

if [ "$1" == "--rebuild=1" ]; then
REBUILD=true
fi

if [ -f "$DEFINITIONS_FILE" ] && [ "$REBUILD" != true ]; then
echo 'RabbitMQ definitions.json file is already build. Skipping.'

exit
fi

if [ -f "$DEFINITIONS_FILE" ] && [ "$REBUILD" == true ]; then
echo 'Re-building RabbitMQ definitions.json file'

rm "$DEFINITIONS_FILE"
else
echo 'Building RabbitMQ definitions.json file'
fi

RABBITMQ_VERSION=$(env RABBITMQ_VERSION)
RABBITMQ_USER=$(env RABBITMQ_DEFAULT_USER)
RABBITMQ_PASS=$(env RABBITMQ_DEFAULT_PASS)

RABBITMQ_VHOSTS_LIST=()
env_array RABBITMQ_VHOSTS RABBITMQ_VHOSTS_LIST

VHOSTS_LIST=''
PERMISSIONS_LIST=''
for VHOST in "${RABBITMQ_VHOSTS_LIST[@]}"; do
if [[ "$VHOSTS_LIST" != "" ]]; then
VHOSTS_LIST+=","
PERMISSIONS_LIST+=","
fi

VHOSTS_LIST+="{\"name\": \"${VHOST}\"}"

PERMISSIONS_LIST+="{\"user\": \"guest\",\"vhost\": \"${VHOST}\",\"configure\": \".*\",\"write\": \".*\",\"read\": \".*\"}"
done

DELIM=$'\x1F'

sed \
-e "s${DELIM}{RABBITMQ_VERSION}${DELIM}${RABBITMQ_VERSION}${DELIM}g" \
-e "s${DELIM}{RABBITMQ_USER}${DELIM}${RABBITMQ_USER}${DELIM}g" \
-e "s${DELIM}{RABBITMQ_PASS}${DELIM}${RABBITMQ_PASS}${DELIM}g" \
-e "s${DELIM}{VHOSTS_LIST}${DELIM}${VHOSTS_LIST}${DELIM}g" \
-e "s${DELIM}{PERMISSIONS_LIST}${DELIM}${PERMISSIONS_LIST}${DELIM}g" \
"$TEMPLATE_FILE" > "$DEFINITIONS_FILE"
22 changes: 22 additions & 0 deletions builders/read_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

env() {
local KEY="$1"
local VALUE

VALUE=$(grep -E "^${KEY}=" "$ENV_FILE" | sed -e "s/^${KEY}=//")

sed -E 's/^"(.*)"$/\1/; s/^'\''(.*)'\''$/\1/' <<< "$VALUE"
}

env_array() {
local KEY="$1"
local OUT_VAR="$2"
local RAW
local IFS=','

RAW=$(env "$KEY")
read -ra VALUES <<< "$RAW"

eval "$OUT_VAR=(\"\${VALUES[@]}\")"
}
Loading