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"
|
||||
|
||||
volumes:
|
||||
redis_data:
|
||||
postgresql_data:
|
||||
mysql_data:
|
||||
dia_data_tmp:
|
||||
|
|
@ -21,8 +22,17 @@ services:
|
|||
- dia_data_bundle:/diaspora/vendor/bundle
|
||||
ports:
|
||||
- ${DIASPORA_DOCKER_PORT:-3000}:3000
|
||||
environment:
|
||||
- ENVIRONMENT_REDIS=redis://redis
|
||||
depends_on:
|
||||
- "${DIASPORA_DOCKER_DB}"
|
||||
- redis
|
||||
|
||||
redis:
|
||||
image: redis:7
|
||||
command: redis-server --save 60 1 --loglevel warning
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
postgresql:
|
||||
image: postgres:10.3
|
||||
|
|
|
|||
|
|
@ -18,18 +18,11 @@ chown -R $HOST_UID:$HOST_GID /home/diaspora
|
|||
mkdir -p /diaspora/tmp/pids
|
||||
chown $HOST_UID:$HOST_GID /diaspora/tmp /diaspora/tmp/pids /diaspora/vendor/bundle
|
||||
|
||||
# ----- Wait for DB ----
|
||||
if [ -z $DIA_NODB ] || [ ! $DIA_NODB -eq 1 ]; then
|
||||
if grep -qFx " <<: *postgresql" /diaspora/config/database.yml; then
|
||||
host=postgresql
|
||||
port=5432
|
||||
else
|
||||
host=mysql
|
||||
port=3306
|
||||
fi
|
||||
|
||||
c=0
|
||||
function wait_for_port() {
|
||||
local host=$1
|
||||
local port=$2
|
||||
|
||||
local c=0
|
||||
trap '{ exit 1; }' INT
|
||||
while ! (< /dev/tcp/${host}/${port}) 2>/dev/null; do
|
||||
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
|
||||
printf "\rWaiting for $host:$port to become ready ... done (${c}s)\n"
|
||||
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
|
||||
|
||||
cd /diaspora
|
||||
|
|
|
|||
|
|
@ -208,6 +208,11 @@ dia_is_db_running() {
|
|||
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() {
|
||||
# Get currently configured or assumed db type
|
||||
grep -q '^ <<: \*mysql' "$DIASPORA_CONFIG_DB" 2>/dev/null && echo mysql || echo postgresql
|
||||
|
|
@ -324,13 +329,14 @@ dia_exec() {
|
|||
# Use a running container
|
||||
dia_docker_compose exec $detach diaspora /exec-entrypoint.sh "$@"
|
||||
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
|
||||
echo "No running instance found, starting new one for command execution ..."
|
||||
dia_docker_compose run --rm $detach --service-ports diaspora "$@"
|
||||
if [ ! -z $not_running ]; then
|
||||
dia_docker_compose stop $DIASPORA_DOCKER_DB
|
||||
fi
|
||||
$stopdb
|
||||
$stopredis
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -449,24 +455,28 @@ dia_setup() {
|
|||
|
||||
dia_setup_rails() {
|
||||
# Prepare rails, install dependencies, migrate database, ...
|
||||
# stop db if it was not running before
|
||||
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_redis_running; then stopredis="dia_docker_compose stop redis"; fi
|
||||
dia_docker_compose run --rm diaspora bin/setup
|
||||
$stopdb
|
||||
$stopredis
|
||||
}
|
||||
|
||||
dia_setup_tests() {
|
||||
# Prepare all possible tests
|
||||
# stop db if it was not running before
|
||||
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_redis_running; then stopredis="dia_docker_compose stop redis"; fi
|
||||
dia_docker_compose run \
|
||||
--rm \
|
||||
-e RAILS_ENV=test \
|
||||
diaspora \
|
||||
bin/rake db:create db:migrate tests:generate_fixtures assets:generate_error_pages
|
||||
$stopdb
|
||||
$stopredis
|
||||
}
|
||||
|
||||
dia_start() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue