Skip to content

Commit

Permalink
Fixed Redis connection during Docker container initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Oct 24, 2023
1 parent 7698721 commit a52a209
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DATABASE_PASSWORD=password

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_USERNAME=username
REDIS_USERNAME=default
REDIS_PASSWORD=password

# SMTP and DKIM credentials
Expand Down
49 changes: 23 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ FROM php:${VERSION}
# Install dependencies
ARG MANAGER=apt
RUN if [ $MANAGER = "apt" ]; then \
apt update && apt install git cron -y; \
else \
apt update && apt install git cron -y; \
else \
echo https://dl-4.alpinelinux.org/alpine/latest-stable/community/ >> /etc/apk/repositories && \
apk update && \
apk add --no-cache git; \
fi
apk add --no-cache git; \
fi

# Install some PHP extensions
RUN curl -sSLf \
-o /usr/local/bin/install-php-extensions \
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions zip pdo_mysql pdo_pgsql redis opcache intl
-o /usr/local/bin/install-php-extensions \
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions zip pdo_mysql pdo_pgsql redis opcache intl

# Install Composer for dependency management
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
Expand Down Expand Up @@ -83,7 +83,7 @@ RUN if [ $VERSION = "8.2-apache" ]; then \
sed -ri -e "s!/var/www/html!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/sites-available/*.conf && \
sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \
a2enmod rewrite; \
fi
fi

# Add wait script to wait for other services to be ready
ADD https://github.com/ufoscout/docker-compose-wait/releases/latest/download/wait /wait
Expand All @@ -100,33 +100,30 @@ RUN sed -i "s/DATABASE_HOST=127.0.0.1/DATABASE_HOST=mariadb/g" .env
RUN sed -i "s/REDIS_HOST=127.0.0.1/REDIS_HOST=redis/g" .env

RUN sed -i "s/DATABASE_USERNAME=username/DATABASE_USERNAME=source_web_console/g" .env
RUN sed -i "s/REDIS_USERNAME=username/REDIS_USERNAME=default/g" .env

RUN sed -i "s/DATABASE_PASSWORD=password/DATABASE_PASSWORD=$(cat /run/secrets/db_password | tr -d '\n')/g" .env

# Dump autoloader class to optimize performance
# https://symfony.com/doc/current/deployment.html
RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod

# Use the PHP custom configuration (if exists)
RUN if [ -f "docker/php.ini" ]; then mv "docker/php.ini" "$PHP_INI_DIR/php.ini"; fi

# Use the PHP custom entrypoint
# https://symfony.com/doc/current/deployment.html / https://symfony.com/doc/current/setup/file_permissions.html
RUN mkdir docker
RUN mkdir -p docker

ARG VERSION
RUN if [ $VERSION = "8.2-apache" ]; then \
echo "/wait && mkdir -p var/cache var/log && /usr/local/bin/php ./bin/console cache:clear && \
/usr/local/bin/php ./bin/console doctrine:database:create --no-interaction --if-not-exists && \
/usr/local/bin/php ./bin/console doctrine:schema:create --no-interaction && \
/usr/local/bin/php /app/bin/console app:udp-server 127.0.0.1:81 & \
echo "/wait && mkdir -p var/cache var/log && \
sed -i \"s/DATABASE_PASSWORD=password/DATABASE_PASSWORD=$(cat /run/secrets/db_password)/g\" .env && \
/usr/local/bin/php bin/console cache:clear && COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod && \
/usr/local/bin/php bin/console doctrine:database:create --no-interaction --if-not-exists && \
/usr/local/bin/php bin/console doctrine:schema:create --no-interaction && \
/usr/local/bin/php bin/console app:udp-server 127.0.0.1:81 & \
apache2-foreground" >> docker/entrypoint.sh; \
else \
echo "/wait && mkdir -p var/cache var/log && /usr/local/bin/php ./bin/console cache:clear && \
/usr/local/bin/php ./bin/console doctrine:database:create --no-interaction --if-not-exists && \
/usr/local/bin/php ./bin/console doctrine:schema:create --no-interaction && \
/usr/local/bin/php /app/bin/console app:udp-server 127.0.0.1:81 & \
else \
echo "/wait && mkdir -p var/cache var/log && \
sed -i \"s/DATABASE_PASSWORD=password/DATABASE_PASSWORD=$(cat /run/secrets/db_password)/g\" .env && \
/usr/local/bin/php bin/console cache:clear && COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod && \
/usr/local/bin/php bin/console doctrine:database:create --no-interaction --if-not-exists && \
/usr/local/bin/php bin/console doctrine:schema:create --no-interaction && \
/usr/local/bin/php bin/console app:udp-server 127.0.0.1:81 & \
php-fpm" >> docker/entrypoint.sh; \
fi

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
redis:
image: redis:alpine
restart: always
command: >
--requirepass password --maxmemory 128mb --maxmemory-policy allkeys-lru
volumes:
- ./docker/redis/config:/usr/local/etc/redis
- ./docker/redis/database:/data
Expand Down

0 comments on commit a52a209

Please sign in to comment.