Composer.lock bug with multiple psr-4 autoload – Your lock file cannot be installed on this system without changes

Published

I have a Docker build working with following:

Dockerfile

# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=7.4.12
ARG OPENRESTY_VERSION=1.17.8.2
#ARG VARNISH_VERSION=6.5

###
### 1. "php" stage
###

FROM php:${PHP_VERSION}-fpm-alpine AS php

# persistent / runtime deps
RUN apk add --no-cache 
        acl 
        fcgi 
        file 
        gettext 
        git 
        rabbitmq-c-dev 
        openssh-client 
        supervisor 
    ;

ARG APCU_VERSION=5.1.19
ARG PECL_AMQP_VERSION=1.10.2
ARG PECL_REDIS_VERSION=5.3.2
RUN set -eux; 
    apk add --no-cache --virtual .build-deps 
        $PHPIZE_DEPS 
        icu-dev 
        libzip-dev 
        postgresql-dev 
        zlib-dev 
    ; 
    
    docker-php-ext-configure zip; 
    docker-php-ext-install -j$(nproc) 
        intl 
        pgsql 
        pdo_pgsql 
        zip 
    ; 
    pecl install 
        amqp-${PECL_AMQP_VERSION} 
        redis-${PECL_REDIS_VERSION} 
        apcu-${APCU_VERSION} 
    ; 
    pecl clear-cache; 
    docker-php-ext-enable 
        apcu 
        amqp 
        opcache 
        redis 
    ; 
    
    runDeps="$( 
        scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions 
            | tr ',' 'n' 
            | sort -u 
            | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' 
    )"; 
    apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; 
    
    apk del .build-deps

# INSTALL and CONFIGURE SSH
ARG PRIVATE_SSH_KEY_PATH=id_rsa_for_build

RUN mkdir /root/.ssh
COPY ${PRIVATE_SSH_KEY_PATH} /root/.ssh/id_rsa

RUN chmod 700 /root/.ssh && chmod 600 /root/.ssh/id_rsa

RUN which ssh-agent || ( apk --update add openssh-client ) 
    && eval "$(ssh-agent -s)" 
    && ssh-keyscan -H gitlab.com >> /root/.ssh/known_hosts

#Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

#Configure PHP && PHP-FPM
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY .infra-ci-cd/docker/php/conf.d/opcache.ini $PHP_INI_DIR/conf.d/api-opcache.ini
COPY .infra-ci-cd/docker/php/conf.d/php.ini $PHP_INI_DIR/conf.d/api-php.ini
COPY .infra-ci-cd/docker/php/conf.d/fpm-pool.conf /usr/local/etc/php-fpm.d/www.conf

RUN set -eux; 
    { 
        echo '[www]'; 
        echo 'ping.path = /ping'; 
    } | tee /usr/local/etc/php-fpm.d/docker-healthcheck.conf

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
RUN set -eux; 
    composer global require "symfony/flex" --prefer-dist --no-progress --classmap-authoritative; 
    composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"

# Setup document root
WORKDIR /srv

# Stop using cache from here if CACHEBUST has a different value from the cached image
ARG CACHEBUST=1

# build for production
ARG BUILD_APP_ENV=prod
ENV APP_ENV=$BUILD_APP_ENV

# prevent the reinstallation of vendors at every changes in the source code
COPY app/composer.json app/composer.lock app/symfony.lock ./
RUN set -eux; 
    composer install --prefer-dist --no-dev --no-scripts --no-progress; 
    composer clear-cache

# do not use .env files in production (instead generate a file reflecting the real env)
COPY app/.env ./
RUN composer dump-env $BUILD_APP_ENV; 
    rm ./.env

# copy only specifically what we need
COPY app/bin bin/
COPY app/config config/
COPY app/migrations migrations/
COPY app/public public/
COPY app/src src/
COPY app/templates templates/
COPY app/translations translations/

#remove chmod 666 when the log will be outside
RUN set -eux; 
    mkdir -p var/cache var/log; 
    chmod a+w var/cache var/log; 
    touch var/log/prod.log var/log/prod.deprecations.log; 
    chmod 666 var/log/*; 
    composer dump-autoload --classmap-authoritative --no-dev; 
    composer run-script --no-dev post-install-cmd; 
    chmod +x bin/console; sync
[...]

composer.json

{
    "name": "XXXXX/XXXXX-api",
    "description": "Expose XXXXXData through ",
    "type": "project",
    "license": "proprietary",
    "version": "1.13.0-dev",
    "repositories": [
        {
            "type": "vcs",
            "url": "ssh://[email protected]/XXXXX/packages/php/helpers"
        }
    ],
    "require": {
        "php": ">=7.4",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-json": "*",
        "api-platform/core": "^2.5",
        "composer/package-versions-deprecated": "1.11.99.1",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.2",
        "doctrine/doctrine-migrations-bundle": "^3.0",
        "doctrine/orm": "^2.8",
        "elasticsearch/elasticsearch": "^7.10",
        "XXXXX/helpers": "^1.5",
        "myclabs/php-enum": "^1.7",
        "nelmio/cors-bundle": "^2.1",
        "phpdocumentor/reflection-docblock": "^5.2",
        "predis/predis": "^1.1",
        "sensio/framework-extra-bundle": "^5.6",
        "sentry/sentry-symfony": "^3.5",
        "symfony/asset": "5.2.*",
        "symfony/console": "5.2.*",
        "symfony/dotenv": "5.2.*",
        "symfony/expression-language": "5.2.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "5.2.*",
        "symfony/framework-bundle": "5.2.*",
        "symfony/http-client": "5.2.*",
        "symfony/intl": "5.2.*",
        "symfony/mailer": "5.2.*",
        "symfony/messenger": "5.2.*",
        "symfony/mime": "5.2.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/process": "5.2.*",
        "symfony/property-access": "5.2.*",
        "symfony/property-info": "5.2.*",
        "symfony/security-bundle": "5.2.*",
        "symfony/sendgrid-mailer": "5.2.*",
        "symfony/serializer": "5.2.*",
        "symfony/string": "5.2.*",
        "symfony/translation": "5.2.*",
        "symfony/twig-bundle": "^5.2",
        "symfony/validator": "5.2.*",
        "symfony/web-link": "5.2.*",
        "symfony/yaml": "5.2.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "dama/doctrine-test-bundle": "^6.3",
        "dg/bypass-finals": "^1.3",
        "doctrine/doctrine-fixtures-bundle": "^3.3",
        "fzaninotto/faker": "^1.9",
        "myclabs/deep-copy": "^1.10",
        "symfony/browser-kit": "^5.2",
        "symfony/css-selector": "^5.2",
        "symfony/debug-bundle": "^5.2",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^5.2",
        "symfony/profiler-pack": "^1.0.4",
        "symfony/stopwatch": "^5.2",
        "symfony/test-pack": "^1.0.4",
        "symfony/var-dumper": "^5.2",
        "symfony/web-profiler-bundle": "^5.2"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "AppTests": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "5.2.*"
        }
    }
}

After only adding an entry to composer.json => autoload =>psr-4 such as :

    "autoload": {
        "psr-4": {
            "App": "src/",
            "Demo": "demo/"
        }
    },`

When i run the build i have the following error

#22 [php 17/30] RUN set -eux;     composer dump-autoload --classmap-authorit...
#22 0.277 + composer dump-autoload --classmap-authoritative --no-dev
#22 0.403 Generating optimized autoload files (authoritative)
#22 0.406 Generated optimized autoload files (authoritative) containing 1 classes
#22 0.409 + composer install --prefer-dist --no-dev --no-scripts --no-progress
#22 0.541 Installing dependencies from lock file
#22 0.549 Verifying lock file contents can be installed on current platform.
#22 0.671 Your lock file cannot be installed on this system without changes. Please run composer update.
#22 ERROR: executor failed running [/bin/sh -c set -eux;     composer dump-autoload --classmap-authoritative --no-dev;  composer install --prefer-dist --no-dev --no-scripts --no-progress;     composer clear-cache]: runc did not terminate sucessfully

I tried to add this before the composer install, but I get the exact same issue

    rm -rf app/vendor; 
    composer dump-autoload --classmap-authoritative --no-dev; 

UPDATE 1

I can’t run composer update since I don’t want to update all my dependencies.

UPDATE 2

I tried to update only 1 dependency to regenerate a composer.lock, I still have the same issue.

Source: Docker Questions

Published
Categorised as composer-php, docker, php, symfony Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq