optimize docker build

This commit is contained in:
Arthur de Moulins
2020-02-28 15:46:19 +01:00
parent 4cfc712674
commit 4a634070d1
23 changed files with 119 additions and 106 deletions

View File

@@ -1,18 +1,33 @@
/.circleci .idea
/.git
.settings .settings
/nodes_modules /*.md
/vendor /.circleci
/docker-compose.* /.dockerignore
/Dockerfile
/.env /.env
/.env.* /.env.*
/*.md /.git
/.travis.yml /.travis.yml
/AUTHORS
/CONTRIBUTORS /CONTRIBUTORS
/Dockerfile
/LICENSE /LICENSE
/www/thumbnails /bin
/www/assets !/bin/console
/www/custom !/bin/developer
!/bin/setup
/cache
/config/configuration.yml /config/configuration.yml
/config/configuration-compiled.php /config/configuration-compiled.php
!/config/configuration.sample.yml
/datas
/docker-compose.*
/logs
/nodes_modules
/plugins
/tmp
/vendor
/www/assets
/www/custom
/www/plugins
/www/thumbnails
npm-debug.log

2
.env
View File

@@ -52,7 +52,7 @@ MYSQL_MAX_ALLOWED_PACKET=16M
# --- DEV purpose --- # --- DEV purpose ---
# PhpMyAdmin port # PhpMyAdmin port
PHPMYADMIN_PORT=8089 PHRASEANET_PHPMYADMIN_PORT=8089
# Xdebug # Xdebug
XDEBUG_ENABLED=1 XDEBUG_ENABLED=1

View File

@@ -93,7 +93,7 @@ RUN composer install --prefer-dist --no-dev --no-progress --no-suggest --classma
COPY --chown=app . . COPY --chown=app . .
RUN rm -rf docker \ RUN rm -rf docker/phraseanet/root \
&& make install && make install
ADD docker/phraseanet/ / ADD docker/phraseanet/ /
@@ -105,9 +105,9 @@ ADD docker/phraseanet/ /
FROM phraseanet-system as phraseanet-fpm FROM phraseanet-system as phraseanet-fpm
COPY --from=builder --chown=app /var/alchemy/Phraseanet /var/alchemy/Phraseanet COPY --from=builder --chown=app /var/alchemy/Phraseanet /var/alchemy/Phraseanet
ADD ./docker/phraseanet/ / ADD ./docker/phraseanet/root /
WORKDIR /var/alchemy/Phraseanet WORKDIR /var/alchemy/Phraseanet
ENTRYPOINT ["/phraseanet/entrypoint.sh"] ENTRYPOINT ["docker/phraseanet/entrypoint.sh"]
CMD ["php-fpm", "-F"] CMD ["php-fpm", "-F"]
######################################################################### #########################################################################
@@ -115,8 +115,8 @@ CMD ["php-fpm", "-F"]
######################################################################### #########################################################################
FROM phraseanet-fpm as phraseanet-worker FROM phraseanet-fpm as phraseanet-worker
ENTRYPOINT ["/phraseanet/worker/entrypoint.sh"] ENTRYPOINT ["docker/phraseanet/worker/entrypoint.sh"]
CMD ["/phraseanet/worker/scheduler-run.sh"] CMD ["docker/phraseanet/worker/scheduler-run.sh"]
######################################################################### #########################################################################
# phraseanet-nginx # phraseanet-nginx
@@ -124,7 +124,7 @@ CMD ["/phraseanet/worker/scheduler-run.sh"]
FROM nginx:1.17.8-alpine as phraseanet-nginx FROM nginx:1.17.8-alpine as phraseanet-nginx
RUN adduser --uid 1000 --disabled-password app RUN adduser --uid 1000 --disabled-password app
ADD ./docker/nginx/ / ADD ./docker/nginx/root /
COPY --from=builder /var/alchemy/Phraseanet/www /var/alchemy/Phraseanet/www COPY --from=builder /var/alchemy/Phraseanet/www /var/alchemy/Phraseanet/www
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -4,7 +4,7 @@ services:
image: phpmyadmin/phpmyadmin image: phpmyadmin/phpmyadmin
restart: on-failure restart: on-failure
ports: ports:
- ${PHPMYADMIN_PORT}:80 - ${PHRASEANET_PHPMYADMIN_PORT}:80
depends_on: depends_on:
- db - db
@@ -13,7 +13,7 @@ services:
- .:/var/alchemy/Phraseanet - .:/var/alchemy/Phraseanet
- ./datas:/var/alchemy/Phraseanet/datas:rw - ./datas:/var/alchemy/Phraseanet/datas:rw
- ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw - ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw
- ./docker/nginx/entrypoint.sh:/entrypoint.sh - ./docker/nginx/root/entrypoint.sh:/entrypoint.sh
builder: builder:
build: build:
@@ -22,6 +22,10 @@ services:
command: exit 0 command: exit 0
volumes: volumes:
- .:/var/alchemy/Phraseanet - .:/var/alchemy/Phraseanet
- ./config:/var/alchemy/Phraseanet/config:rw
- ./logs:/var/alchemy/Phraseanet/logs:rw
- ./datas:/var/alchemy/Phraseanet/datas:rw
- ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw
phraseanet: phraseanet:
environment: environment:
@@ -34,8 +38,6 @@ services:
- ./logs:/var/alchemy/Phraseanet/logs:rw - ./logs:/var/alchemy/Phraseanet/logs:rw
- ./datas:/var/alchemy/Phraseanet/datas:rw - ./datas:/var/alchemy/Phraseanet/datas:rw
- ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw - ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw
- ./docker/phraseanet/phraseanet/entrypoint.sh:/phraseanet/entrypoint.sh
- ./docker/phraseanet/phraseanet/auto-install.sh:/phraseanet/auto-install.sh
worker: worker:
volumes: volumes:
@@ -44,9 +46,6 @@ services:
- ./logs:/var/alchemy/Phraseanet/logs:rw - ./logs:/var/alchemy/Phraseanet/logs:rw
- ./datas:/var/alchemy/Phraseanet/datas:rw - ./datas:/var/alchemy/Phraseanet/datas:rw
- ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw - ./www/thumbnails:/var/alchemy/Phraseanet/www/thumbnails:rw
- ./docker/phraseanet/phraseanet/entrypoint.sh:/phraseanet/entrypoint.sh
- ./docker/phraseanet/phraseanet/worker/entrypoint.sh:/phraseanet/worker/entrypoint.sh
- ./docker/phraseanet/phraseanet/worker/scheduler-run.sh:/phraseanet/worker/scheduler-run.sh
rabbitmq: rabbitmq:
ports: ports:
@@ -67,4 +66,3 @@ networks:
ipam: ipam:
config: config:
- subnet: $PHRASEANET_SUBNET_IPS - subnet: $PHRASEANET_SUBNET_IPS

View File

@@ -1,7 +0,0 @@
#!/bin/sh
set -xe
cat nginx.conf.sample | sed "s/\$MAX_BODY_SIZE/$MAX_BODY_SIZE/g" > /etc/nginx/conf.d/default.conf
exec "$@"

View File

@@ -0,0 +1,7 @@
#!/bin/sh
set -xe
cat /nginx.conf.sample | sed "s/\$MAX_BODY_SIZE/$MAX_BODY_SIZE/g" > /etc/nginx/conf.d/default.conf
exec "$@"

View File

@@ -1,9 +0,0 @@
#!/bin/sh
set -e
if [ ! -z ${DOCKER_XDEBUG_ENABLED} ]; then
. usr-bin/docker-xdebug-enable
fi
exec "$@"

View File

@@ -1,4 +0,0 @@
#!/bin/sh
/sbin/ip route|awk '/default/ { print $3 }'
# TODO support MacOS & Windows host IP

View File

@@ -1,5 +0,0 @@
#!/bin/sh
unset HOST_IP
unset XDEBUG_CONFIG
unset XDEBUG_REMOTE_HOST

View File

@@ -1,9 +0,0 @@
#!/bin/sh
set -e
HOST_IP=$(docker-get-host-ip);
export HOST_IP
export XDEBUG_CONFIG="remote_enable=1 remote_host=${HOST_IP} idekey=PHPSTORM";
export XDEBUG_REMOTE_HOST="${HOST_IP}";

View File

@@ -2,12 +2,12 @@
set -xe set -xe
if [ $INSTALL_ACCOUNT_EMAIL = ""]; then if [ -z "$INSTALL_ACCOUNT_EMAIL" ]; then
echo "INSTALL_ACCOUNT_EMAIL var is not set." echo "INSTALL_ACCOUNT_EMAIL var is not set."
exit 1 exit 1
fi fi
if [ $INSTALL_ACCOUNT_PASSWORD = ""]; then if [ -z "$INSTALL_ACCOUNT_PASSWORD" ]; then
echo "INSTALL_ACCOUNT_PASSWORD var is not set." echo "INSTALL_ACCOUNT_PASSWORD var is not set."
exit 1 exit 1
fi fi
@@ -39,7 +39,6 @@ fi
/var/alchemy/Phraseanet/bin/setup system:config set main.cache.type redis /var/alchemy/Phraseanet/bin/setup system:config set main.cache.type redis
# RabbitMQ # RabbitMQ
bin/setup system:config set rabbitmq.server.host rabbitmq bin/setup system:config set rabbitmq.server.host rabbitmq
bin/setup system:config set rabbitmq.server.port 5672 bin/setup system:config set rabbitmq.server.port 5672
bin/setup system:config set rabbitmq.server.user $INSTALL_RABBITMQ_USER bin/setup system:config set rabbitmq.server.user $INSTALL_RABBITMQ_USER

29
docker/phraseanet/entrypoint.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
set -e
envsubst < "docker/phraseanet/php.ini.sample" > /usr/local/etc/php/php.ini
envsubst < "docker/phraseanet/php-fpm.conf.sample" > /usr/local/etc/php-fpm.conf
chown -R app:app \
config \
datas \
tmp \
logs \
www/thumbnails
FILE=config/configuration.yml
if [ -f "$FILE" ]; then
echo "$FILE exists, skip setup."
else
echo "$FILE doesn't exist, entering setup..."
runuser app -c docker/phraseanet/auto-install.sh
fi
if [ ${XDEBUG_ENABLED} == "1" ]; then
echo "XDEBUG is enabled. YOU MAY KEEP THIS FEATURE DISABLED IN PRODUCTION."
docker-php-ext-enable xdebug
fi
bash -e docker-php-entrypoint $@

View File

@@ -1,25 +0,0 @@
#!/bin/bash
set -e
envsubst < /php.ini.sample > /usr/local/etc/php/php.ini
envsubst < /php-fpm.conf.sample > /usr/local/etc/php-fpm.conf
chown -R app:app /var/alchemy/Phraseanet/config
chown -R app:app /var/alchemy/Phraseanet/datas
chown -R app:app /var/alchemy/Phraseanet/tmp
chown -R app:app /var/alchemy/Phraseanet/www/thumbnails
FILE=/var/alchemy/Phraseanet/config/configuration.yml
if [ -f "$FILE" ]; then
echo "$FILE exists, skip setup."
else
echo "$FILE doesn't exist, entering setup..."
runuser app -c '/phraseanet/auto-install.sh'
fi
if [ ${XDEBUG_ENABLED} == "1" ]; then
echo "XDEBUG is enabled. YOU MAY KEEP THIS FEATURE DISABLED IN PRODUCTION."
docker-php-ext-enable xdebug
fi
bash -e docker-php-entrypoint $@

View File

@@ -1,16 +0,0 @@
#!/bin/bash
set -e
mkdir -p /var/alchemy/Phraseanet/tmp/locks \
&& chown -R app:app /var/alchemy/Phraseanet/tmp
envsubst < /php.ini.sample > /usr/local/etc/php/php.ini
envsubst < /php-fpm.conf.sample > /usr/local/etc/php-fpm.conf
if [ ${XDEBUG_ENABLED} == "1" ]; then
echo "XDEBUG is enabled. YOU MAY KEEP THIS FEATURE DISABLED IN PRODUCTION."
docker-php-ext-enable xdebug
fi
bash -e docker-php-entrypoint $@

View File

@@ -1,3 +0,0 @@
#!/bin/bash
runuser app -c 'php /var/alchemy/Phraseanet/bin/console task-manager:scheduler:run'

View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -e
DOCKER_DIR="./docker/phraseanet"
mkdir -p "${APP_DIR}/tmp/locks" \
&& chown -R app:app "${APP_DIR}/tmp"
envsubst < "${DOCKER_DIR}/php.ini.sample" > /usr/local/etc/php/php.ini
envsubst < "${DOCKER_DIR}/php-fpm.conf.sample" > /usr/local/etc/php-fpm.conf
if [ ${XDEBUG_ENABLED} == "1" ]; then
echo "XDEBUG is enabled. YOU MAY KEEP THIS FEATURE DISABLED IN PRODUCTION."
docker-php-ext-enable xdebug
fi
bash -e docker-php-entrypoint $@

View File

@@ -0,0 +1,3 @@
#!/bin/bash
runuser app -c 'php bin/console task-manager:scheduler:run'

View File

@@ -474,6 +474,17 @@ class Basket extends \Alchemy\Phrasea\Model\Entities\Basket implements \Doctrine
return parent::hasRecord($app, $record); return parent::hasRecord($app, $record);
} }
/**
* {@inheritDoc}
*/
public function getElementByRecord(\Alchemy\Phrasea\Application $app, \record_adapter $record)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getElementByRecord', [$app, $record]);
return parent::getElementByRecord($app, $record);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@@ -518,4 +518,15 @@ class LazaretFile extends \Alchemy\Phrasea\Model\Entities\LazaretFile implements
return parent::getRecordsToSubstitute($app, $includeReason); return parent::getRecordsToSubstitute($app, $includeReason);
} }
/**
* {@inheritDoc}
*/
public function getStatus(\Alchemy\Phrasea\Application $app)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getStatus', [$app]);
return parent::getStatus($app);
}
} }