Add redis to docker development setup
With #8392 the `single_process_mode` was removed, which means that development now also requires a redis.
This commit is contained in:
parent
7c450b4446
commit
84df8eed33
3 changed files with 42 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
version: "3.4"
|
version: "3.4"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
redis_data:
|
||||||
postgresql_data:
|
postgresql_data:
|
||||||
mysql_data:
|
mysql_data:
|
||||||
dia_data_tmp:
|
dia_data_tmp:
|
||||||
|
|
@ -21,8 +22,17 @@ services:
|
||||||
- dia_data_bundle:/diaspora/vendor/bundle
|
- dia_data_bundle:/diaspora/vendor/bundle
|
||||||
ports:
|
ports:
|
||||||
- ${DIASPORA_DOCKER_PORT:-3000}:3000
|
- ${DIASPORA_DOCKER_PORT:-3000}:3000
|
||||||
|
environment:
|
||||||
|
- ENVIRONMENT_REDIS=redis://redis
|
||||||
depends_on:
|
depends_on:
|
||||||
- "${DIASPORA_DOCKER_DB}"
|
- "${DIASPORA_DOCKER_DB}"
|
||||||
|
- redis
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7
|
||||||
|
command: redis-server --save 60 1 --loglevel warning
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
|
||||||
postgresql:
|
postgresql:
|
||||||
image: postgres:10.3
|
image: postgres:10.3
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,11 @@ chown -R $HOST_UID:$HOST_GID /home/diaspora
|
||||||
mkdir -p /diaspora/tmp/pids
|
mkdir -p /diaspora/tmp/pids
|
||||||
chown $HOST_UID:$HOST_GID /diaspora/tmp /diaspora/tmp/pids /diaspora/vendor/bundle
|
chown $HOST_UID:$HOST_GID /diaspora/tmp /diaspora/tmp/pids /diaspora/vendor/bundle
|
||||||
|
|
||||||
# ----- Wait for DB ----
|
function wait_for_port() {
|
||||||
if [ -z $DIA_NODB ] || [ ! $DIA_NODB -eq 1 ]; then
|
local host=$1
|
||||||
if grep -qFx " <<: *postgresql" /diaspora/config/database.yml; then
|
local port=$2
|
||||||
host=postgresql
|
|
||||||
port=5432
|
|
||||||
else
|
|
||||||
host=mysql
|
|
||||||
port=3306
|
|
||||||
fi
|
|
||||||
|
|
||||||
c=0
|
|
||||||
|
|
||||||
|
local c=0
|
||||||
trap '{ exit 1; }' INT
|
trap '{ exit 1; }' INT
|
||||||
while ! (< /dev/tcp/${host}/${port}) 2>/dev/null; do
|
while ! (< /dev/tcp/${host}/${port}) 2>/dev/null; do
|
||||||
printf "\rWaiting for $host:$port to become ready ... ${c}s"
|
printf "\rWaiting for $host:$port to become ready ... ${c}s"
|
||||||
|
|
@ -40,6 +33,18 @@ if [ -z $DIA_NODB ] || [ ! $DIA_NODB -eq 1 ]; then
|
||||||
if [ ! -z $c ]; then
|
if [ ! -z $c ]; then
|
||||||
printf "\rWaiting for $host:$port to become ready ... done (${c}s)\n"
|
printf "\rWaiting for $host:$port to become ready ... done (${c}s)\n"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z $DIA_NODB ] || [ ! $DIA_NODB -eq 1 ]; then
|
||||||
|
# ----- Wait for DB -----
|
||||||
|
if grep -qFx " <<: *postgresql" /diaspora/config/database.yml; then
|
||||||
|
wait_for_port postgresql 5432
|
||||||
|
else
|
||||||
|
wait_for_port mysql 3306
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----- Wait for Redis -----
|
||||||
|
wait_for_port redis 6379
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd /diaspora
|
cd /diaspora
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,11 @@ dia_is_db_running() {
|
||||||
dia_docker_compose ps --services --filter status=running | grep -qx $DIASPORA_DOCKER_DB
|
dia_docker_compose ps --services --filter status=running | grep -qx $DIASPORA_DOCKER_DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dia_is_redis_running() {
|
||||||
|
# Check if redis container is running
|
||||||
|
dia_docker_compose ps --services --filter status=running | grep -qx redis
|
||||||
|
}
|
||||||
|
|
||||||
dia_get_db() {
|
dia_get_db() {
|
||||||
# Get currently configured or assumed db type
|
# Get currently configured or assumed db type
|
||||||
grep -q '^ <<: \*mysql' "$DIASPORA_CONFIG_DB" 2>/dev/null && echo mysql || echo postgresql
|
grep -q '^ <<: \*mysql' "$DIASPORA_CONFIG_DB" 2>/dev/null && echo mysql || echo postgresql
|
||||||
|
|
@ -324,13 +329,14 @@ dia_exec() {
|
||||||
# Use a running container
|
# Use a running container
|
||||||
dia_docker_compose exec $detach diaspora /exec-entrypoint.sh "$@"
|
dia_docker_compose exec $detach diaspora /exec-entrypoint.sh "$@"
|
||||||
else
|
else
|
||||||
if ! dia_is_db_running; then not_running=1; fi
|
# stop db/redis if it was not running before
|
||||||
|
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
|
||||||
|
if ! dia_is_redis_running; then stopredis="dia_docker_compose stop redis"; fi
|
||||||
# Start a new container
|
# Start a new container
|
||||||
echo "No running instance found, starting new one for command execution ..."
|
echo "No running instance found, starting new one for command execution ..."
|
||||||
dia_docker_compose run --rm $detach --service-ports diaspora "$@"
|
dia_docker_compose run --rm $detach --service-ports diaspora "$@"
|
||||||
if [ ! -z $not_running ]; then
|
$stopdb
|
||||||
dia_docker_compose stop $DIASPORA_DOCKER_DB
|
$stopredis
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -449,24 +455,28 @@ dia_setup() {
|
||||||
|
|
||||||
dia_setup_rails() {
|
dia_setup_rails() {
|
||||||
# Prepare rails, install dependencies, migrate database, ...
|
# Prepare rails, install dependencies, migrate database, ...
|
||||||
# stop db if it was not running before
|
|
||||||
echo "Setting up environment for tests ..."
|
echo "Setting up environment for tests ..."
|
||||||
|
# stop db/redis if it was not running before
|
||||||
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
|
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
|
||||||
|
if ! dia_is_redis_running; then stopredis="dia_docker_compose stop redis"; fi
|
||||||
dia_docker_compose run --rm diaspora bin/setup
|
dia_docker_compose run --rm diaspora bin/setup
|
||||||
$stopdb
|
$stopdb
|
||||||
|
$stopredis
|
||||||
}
|
}
|
||||||
|
|
||||||
dia_setup_tests() {
|
dia_setup_tests() {
|
||||||
# Prepare all possible tests
|
# Prepare all possible tests
|
||||||
# stop db if it was not running before
|
|
||||||
echo "Setting up environment for tests ..."
|
echo "Setting up environment for tests ..."
|
||||||
|
# stop db/redis if it was not running before
|
||||||
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
|
if ! dia_is_db_running; then stopdb="dia_docker_compose stop $DIASPORA_DOCKER_DB"; fi
|
||||||
|
if ! dia_is_redis_running; then stopredis="dia_docker_compose stop redis"; fi
|
||||||
dia_docker_compose run \
|
dia_docker_compose run \
|
||||||
--rm \
|
--rm \
|
||||||
-e RAILS_ENV=test \
|
-e RAILS_ENV=test \
|
||||||
diaspora \
|
diaspora \
|
||||||
bin/rake db:create db:migrate tests:generate_fixtures assets:generate_error_pages
|
bin/rake db:create db:migrate tests:generate_fixtures assets:generate_error_pages
|
||||||
$stopdb
|
$stopdb
|
||||||
|
$stopredis
|
||||||
}
|
}
|
||||||
|
|
||||||
dia_start() {
|
dia_start() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue