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

Dockerリビルド時の効率改善 #4753

Merged
merged 3 commits into from
Dec 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 22 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,42 @@ RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# Override with custom configuration settings
COPY dockerbuild/php.ini $PHP_INI_DIR/conf.d/

COPY . ${APACHE_DOCUMENT_ROOT}

WORKDIR ${APACHE_DOCUMENT_ROOT}
RUN chown www-data:www-data /var/www \
&& mkdir -p ${APACHE_DOCUMENT_ROOT}/vendor \
&& mkdir -p ${APACHE_DOCUMENT_ROOT}/var \
&& chown www-data:www-data ${APACHE_DOCUMENT_ROOT}/vendor \
&& chmod g+s ${APACHE_DOCUMENT_ROOT}/vendor

RUN curl -sS https://getcomposer.org/installer \
| php \
&& mv composer.phar /usr/bin/composer \
&& composer selfupdate --1 \
&& composer config -g repos.packagist composer https://packagist.jp \
&& composer global require hirak/prestissimo \
&& chown www-data:www-data /var/www \
&& mkdir -p ${APACHE_DOCUMENT_ROOT}/var \
&& chown -R www-data:www-data ${APACHE_DOCUMENT_ROOT} \
&& find ${APACHE_DOCUMENT_ROOT} -type d -print0 \
| xargs -0 chmod g+s \
;
&& composer global require hirak/prestissimo

# 全体コピー前にcomposer installを先行完了させる(docker cache利用によるリビルド速度向上)
USER www-data

COPY composer.json ${APACHE_DOCUMENT_ROOT}/composer.json
COPY composer.lock ${APACHE_DOCUMENT_ROOT}/composer.lock
RUN composer install \
--no-scripts \
--no-autoloader \
-d ${APACHE_DOCUMENT_ROOT} \
;

##################################################################
# ファイル変更時、以後のステップにはキャッシュが効かなくなる
USER root
COPY . ${APACHE_DOCUMENT_ROOT}
WORKDIR ${APACHE_DOCUMENT_ROOT}

RUN find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or -print0 \
| xargs -0 chown www-data:www-data \
&& find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune \) -or \( -type d -print0 \) \
| xargs -0 chmod g+s \
;

USER www-data
RUN composer dumpautoload -o --apcu

RUN if [ ! -f ${APACHE_DOCUMENT_ROOT}/.env ]; then \
Expand Down