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

Read-only cache mode aren't used when running on read-only docker volumes #10906

Closed
lcobucci opened this issue Jun 30, 2022 · 7 comments
Closed
Labels
Milestone

Comments

@lcobucci
Copy link
Contributor

My composer.json:

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": "^8.1",
        "psr/log": "^3.0"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    }
}

Output of composer diagnose:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.3.7
PHP version: 8.1.7
PHP binary path: /usr/local/bin/php
OpenSSL version: OpenSSL 1.1.1o  3 May 2022
cURL version: 7.83.1 libz 1.2.12 ssl OpenSSL/1.1.1o
zip: extension present, unzip present, 7-Zip present (7z)

When I run these command:

# populate cache first (no `COMPOSER_CACHE_READ_ONLY` and `ro` flag on the docker volume)
docker run --rm -it -v $(pwd)/composer-cache/:/composer-cache -e COMPOSER_CACHE_DIR=/composer-cache -v $(pwd)/composer.json:/app/composer.json  -w /app composer:2 composer instal -vvv

# test read only mode
docker run --rm -it -v $(pwd)/composer-cache/:/composer-cache:ro -e COMPOSER_CACHE_DIR=/composer-cache -e COMPOSER_CACHE_READ_ONLY=1 -v $(pwd)/composer.json:/app/composer.json  -w /app composer:2 composer instal -vvv

I get the following output:

Reading ./composer.json (/app/composer.json)
Loading config file ./composer.json (/app/composer.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/app): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Executing command (/app): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/app): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/app): hg branch
Executing command (/app): fossil branch list
Executing command (/app): fossil tag list
Executing command (/app): svn info --xml
Failed to initialize global composer: Composer could not find the config file: /tmp/composer.json

No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Cannot create cache directory /composer-cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Downloading https://repo.packagist.org/packages.json
[200] https://repo.packagist.org/packages.json
Info from https://repo.packagist.org: #StandWithUkraine
Downloading https://repo.packagist.org/p2/psr/log.json
[200] https://repo.packagist.org/p2/psr/log.json
Built pool.
Running pool optimizer.
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
Analyzed 60 packages to resolve dependencies
Analyzed 61 rules to resolve dependencies
Lock file operations: 1 install, 0 updates, 0 removals
Installs: psr/log:3.0.0
  - Locking psr/log (3.0.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Reading ./composer.lock (/app/composer.lock)
Package operations: 1 install, 0 updates, 0 removals
Installs: psr/log:3.0.0
Cannot create cache directory /composer-cache/files/, or directory is not writable. Proceeding without cache
  - Downloading psr/log (3.0.0)
Downloading https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001
[302] https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001
Following redirect (1) https://codeload.github.com/php-fig/log/legacy.zip/fe5ea303b0887d5caefd3d431c3e61ad47037001
[200] https://codeload.github.com/php-fig/log/legacy.zip/fe5ea303b0887d5caefd3d431c3e61ad47037001
  - Installing psr/log (3.0.0): Extracting archive
Executing async command (CWD): '/usr/bin/unzip' -qq '/app/vendor/composer/tmp-387bedc37afaeda9fca43932170e28af' -d '/app/vendor/composer/8729a89c'
Executing async command (CWD): rm -rf '/app/vendor/composer/8729a89c'
Downloading https://packagist.org/downloads/
[201] https://packagist.org/downloads/
Generating autoload files

And I expected this to happen:

  • No messages like Cannot create cache directory /composer-cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
  • No packages are downloaded
@lcobucci lcobucci changed the title Read-only mode cache only bypasses writes on read-only volumes Read-only cache mode aren't used when running on read-only docker volumes Jun 30, 2022
@lcobucci
Copy link
Contributor Author

Relates to #9150 and #9152

@Seldaek
Copy link
Member

Seldaek commented Jul 1, 2022

I cannot reproduce that outside of docker (and I haven't tried with Docker because meh..). So I wonder if your /composer-cache/repo/https---repo.packagist.org/ really exists in the second command? From the output it looks like it doesn't.

Output should look smth like:

Loading composer repositories with package information
Reading /composer-cache/repo/https---repo.packagist.org/packages.json from cache
Downloading https://repo.packagist.org/packages.json if modified
[304] https://repo.packagist.org/packages.json

@Seldaek Seldaek added the Support label Jul 1, 2022
@lcobucci
Copy link
Contributor Author

lcobucci commented Jul 1, 2022

It does exist but it's not writable :)

@Seldaek Seldaek added Bug and removed Support labels Jul 1, 2022
@Seldaek Seldaek added this to the 2.2 milestone Jul 1, 2022
@Seldaek
Copy link
Member

Seldaek commented Jul 1, 2022

Ah now I see the issue and can repro with chmod -w of my cache first.

Will get this fixed

@lcobucci
Copy link
Contributor Author

lcobucci commented Jul 1, 2022

Thanks @Seldaek!

@Seldaek
Copy link
Member

Seldaek commented Jul 1, 2022

You'd have thought someone would notice this problem earlier but apparently not :D

@Seldaek Seldaek closed this as completed in f8324e0 Jul 1, 2022
@lcobucci
Copy link
Contributor Author

lcobucci commented Jul 1, 2022

It's no surprise, honestly. It's quite an edge-case... I only saw the feature last week and decided to give it a go 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants