Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM php:7.2-apache

# Update distrib
RUN apt update
RUN apt full-upgrade -y

# Required for java
RUN mkdir -p /usr/share/man/man1

# Install dependencies
RUN apt install -y git zip unzip libpng-dev nano wkhtmltopdf openjdk-11-jre zlib1g-dev libicu-dev g++


# Update php.ini
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN echo "date.timezone = Europe/Paris" >> "$PHP_INI_DIR/php.ini"
RUN sed -ri -e "s!'memory_limit'!'; memory_limit'!g" $PHP_INI_DIR/php.ini
RUN echo "memory_limit = 2048M" >> "$PHP_INI_DIR/php.ini"

# Install dependencies mods
RUN docker-php-ext-install gd
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install intl
RUN pecl install apcu
RUN pecl install apcu_bc
RUN echo "extension=apcu.so" >> "$PHP_INI_DIR/php.ini"
RUN echo "extension=apc.so" >> "$PHP_INI_DIR/php.ini"

# Configure apache2
ENV APACHE_DOCUMENT_ROOT /bde/web
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN a2enmod rewrite

# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN rm composer-setup.php
RUN mv composer.phar /usr/bin/composer

# Add sources
COPY . /bde
WORKDIR /bde

# Install sources
RUN composer install
# Install assets
RUN app/console assets:install --env=prod

# Install bootstrap
RUN app/console mopa:bootstrap:install:font --env=prod
RUN app/console mopa:bootstrap:symlink:less --env=prod

# Compile stylesheets and JS
RUN app/console assetic:dump --env=prod --no-debug

RUN rm app/cache -rf

EXPOSE 80

CMD ["./init.sh"]
37 changes: 37 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3'
services:
web:
image: bde-esiee:latest
volumes:
- db_data:/bde/web/uploads
ports:
- 80:80
environment:
- DB_HOST=database
- DB_NAME=bde
- DB_USER=bde
- DB_PASSWORD=bde
- MAILER_HOST=change.it
- MAILER_USER=~
- MAILER_PASSWORD=~
- SECRET_KEY=CHANGEIT
- HOSTNAME=http://localhost
- PIWIK_ID=0
- PIWIK_URL=http://change.it/
- GOOGLE_CLIENT_ID=CHANGE IT
- GOOGLE_CLIENT_SECRET=CHANGE IT


database:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=CHANGEIT
- MYSQL_DATABASE=bde
- MYSQL_USER=bde
- MYSQL_PASSWORD=bde

volumes:
six3six marked this conversation as resolved.
Show resolved Hide resolved
db_data:
uploads:
64 changes: 64 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#/bin/bash

# define path to custom docker environment
DOCKER_ENVVARS=/etc/apache2/docker_envvars

# write variables to DOCKER_ENVVARS
cat << EOF > "$DOCKER_ENVVARS"
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_LOG_DIR=/var/log/apache2
export APACHE_LOCK_DIR=/var/lock/apache2
export APACHE_PID_FILE=/var/run/apache2.pid
export APACHE_RUN_DIR=/var/run/apache2
export APACHE_DOCUMENT_ROOT=/bde/web
EOF

PARAMETERS_FILE=app/config/parameters.yml

cat << EOF > "$PARAMETERS_FILE"
parameters:
database_driver: pdo_mysql
database_host: $DB_HOST
database_port: ~
database_name: $DB_NAME
database_user: $DB_USER
database_password: $DB_PASSWORD

mailer_transport: smtp
mailer_host: $MAILER_HOST
mailer_user: $MAILER_USER
mailer_password: $MAILER_PASSWORD

locale: fr
secret: $SECRET_KEY
application_version: 1.0.0
hostname: $HOSTNAME
piwik_id: $PIWIK_ID
piwik_url: $PIWIK_URL
use_proxy: false

wkhtmltopdf_binary: /usr/local/bin/wkhtmltopdf

client_id : $GOOGLE_CLIENT_ID
client_secret : $GOOGLE_CLIENT_SECRET
proxy: ""
EOF

chown www-data:www-data /bde/app/logs/ -R
mkdir /bde/app/cache/
chown www-data:www-data /bde/app/cache/ -R

# source environment variables to get APACHE_PID_FILE
. "$DOCKER_ENVVARS"

# only delete pidfile if APACHE_PID_FILE is defined
if [ -n "$APACHE_PID_FILE" ]; then
rm -f "$APACHE_PID_FILE"
fi

# line copied from /etc/init.d/apache2
ENV="env -i LANG=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# use apache2ctl instead of /usr/sbin/apache2
$ENV APACHE_ENVVARS="$DOCKER_ENVVARS" apache2ctl -DFOREGROUND