1

I have an symfony application, and i want to create docker container, that contains all needed files. The purpose is to spin up/down containers for scaling, without any other deploying processes. Just with given DB connection.

Building means, pretty much just git clone and running composer install, but some of symfony's post install scripts fail without configured DB.

Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

Can i not run these scripts when i'm building container? Or what the proper way to do symfony deployment?


Using Symfony 3.2, Doctrine2, PHP 7.1

1 Answer 1

4

The proper way to build a container without running the db script is by not running there scripts in the build,

Here is the one we use in production for api-platform:

    FROM php:7.1-fpm-alpine

RUN apk add --no-cache --virtual .persistent-deps \
        git \
        icu-libs \
        zlib \
        postgresql-client

ENV APCU_VERSION 5.1.8

RUN set -xe \
    && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        icu-dev \
        zlib-dev \
        postgresql-dev \
        sqlite-dev \
        pcre-dev \
    && docker-php-ext-install \
        intl \
        mbstring \
        pdo_mysql \
        pdo_pgsql \
        pdo \
        pgsql \
        zip \
        pdo_sqlite \
    && pecl install \
        apcu-${APCU_VERSION} \
    && docker-php-ext-enable --ini-name 20-apcu.ini apcu \
    && docker-php-ext-enable --ini-name 05-opcache.ini opcache \
    && apk del .build-deps

COPY docker/php/php.ini /usr/local/etc/php/php.ini

COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer

RUN chmod +x /usr/local/bin/docker-app-install-composer

RUN set -xe \
    && apk add --no-cache --virtual .fetch-deps \
        openssl \
    && docker-app-install-composer \
    && mv composer.phar /usr/local/bin/composer \
    && apk del .fetch-deps


ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
        sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        pecl install \
                xdebug \
           && docker-php-ext-enable xdebug; \
    fi;

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1

WORKDIR /srv/quotatis

COPY composer.json ./
COPY composer.lock ./

RUN mkdir -p \
        var/cache \
        var/logs \
        var/sessions \
    && composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest -o -a \
    && composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
    && composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
    && chown -R www-data var

COPY app app/
COPY bin bin/
COPY src src/
COPY web web/
COPY etc etc/

RUN composer dump-autoload --optimize --classmap-authoritative --no-dev

COPY docker/php/start.sh /usr/local/bin/docker-app-start

RUN chmod +x /usr/local/bin/docker-app-start

CMD ["docker-app-start"]

You could see the whole stack (nginx + fpm + varnish on github)

The line that you need in here is this one

composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.