TYPO3-docker-boilerplate icon indicating copy to clipboard operation
TYPO3-docker-boilerplate copied to clipboard

[SUGGESTION] Remove /var/ folder from composer installation in docker volume

Open Wingmk opened this issue 6 years ago • 26 comments
trafficstars

Currently the TYPO3 backend is slow in docker installations. Even if a delegated volume is mounted. If TYPO3 is setup as composer we can stop mounting the /var/ folder to the docker container.

I ran some Tests after removing the folder from mounting to docker and it runs a lot faster, especially the backend.

There might also be reasons to remove the typo3temp folder from mounting inside the docker container, but currently I don't even know what or why TYPO3 stores still data inside that directory.

Wingmk avatar Nov 14 '19 14:11 Wingmk

Can you explain, how do you did this exclusion?

mediaessenz avatar Mar 25 '20 11:03 mediaessenz

@mediaessenz I changed the volumes inside the docker-compose.yaml from

volumes:
  - ./app/:/app/:delegated

to

volumes:
  - ./app/config:/app/config
  - ./app/vendor:/app/vendor
  - ./app/web:/app/web

This way the app folder itself and therefore the /var/ folder does sync itself with the docker system. This does also means that the root of the project is not complete. e.g. /var/, composer.json, composer.lock

Wingmk avatar Mar 25 '20 11:03 Wingmk

Thank you for the explaination.

To bad that there is no easier way to exclude some files or subfolder, like it is possible in eg. .gitignore files

mediaessenz avatar Mar 25 '20 17:03 mediaessenz

You can do this:

version: '3.7'
services:
  app:
    volumes:
      - ./app:/app:cached
      - app-cache:/app/var:nocopy
volumes:
  app-cache:

htuscher avatar Mar 25 '20 17:03 htuscher

@hhoechtl Does this setup work for you? It looks like the /app/var directory inside the container is not writable by the TYPO3 application. Having the folder empty on the clientside and filled by the application inside the docker container is the desired outcome.

Wingmk avatar Mar 26 '20 07:03 Wingmk

Yes that works, but you have to do chown 1000:1000 /app/var inside of the container once of course.

htuscher avatar Mar 26 '20 07:03 htuscher

@hhoechtl can you put this inside a Dockerfile so this is executed on container creation? A manual chown would not be a great solution.

Wingmk avatar Mar 26 '20 07:03 Wingmk

Of course you could. I'm personally not supporting TYPO3 anymore.

Am Do., 26. März 2020 um 08:46 Uhr schrieb TimoWinkler < [email protected]>:

@hhoechtl https://github.com/hhoechtl can you put this inside a Dockerfile so this is executed on container creation? A manual chown would not be a great solution.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/webdevops/TYPO3-docker-boilerplate/issues/202#issuecomment-604279432, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGXLBG6DVS65NAOJT7W4UTRJMB4DANCNFSM4JNMZBAQ .

--

Onedrop GmbH & Co. KG

Dr.-Leo-Ritter-Str. 2 93049 Regensburg

Tel. +49 (0) 941 / 206 064 - 40

1drop.de [email protected] [email protected]

http://www.facebook.com/onedropsolutions http://twitter.com/1drop

htuscher avatar Mar 26 '20 07:03 htuscher

@hhoechtl I did some reading and I don't think this stops synchronising the /var folder. It instead pushes the volume location for synchronising the var folder to docker.

Wingmk avatar Mar 26 '20 08:03 Wingmk

Not it won't stop the synchronisation, but as you don't make changes locally in the var folder and it's overlayed inside the container with the nocopy volume, it doesn't matter. The nocopy volume is docker engine internally and therefore fast.

htuscher avatar Mar 26 '20 08:03 htuscher

@hhoechtl I have added this to my Dockerfile.development, right after WORKDIR /app/:

RUN mkdir /app/var && chown 1000:1000 /app/var

Additional I added your suggestion to my docker-compose.yml:

version: '3.7'
services:
  app:
    volumes:
      - ./app:/app:cached
      - app-cache:/app/var:nocopy
volumes:
  app-cache:

After all I rebuild the app container and started all again and get this error when opening the app in the browser:

Fatal error: Uncaught RuntimeException: Could not create directory "/app/var/log/"! in /app/public/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 2169

Did I forget/missunderstand something?

mediaessenz avatar Mar 26 '20 10:03 mediaessenz

Creating the directory upfront doesn't work. The volume mount will override that and still belongs to root

htuscher avatar Mar 26 '20 10:03 htuscher

But how can I change the owner/group later?

mediaessenz avatar Mar 26 '20 10:03 mediaessenz

docker exec {container} chown 1000:1000 /app/var

htuscher avatar Mar 26 '20 10:03 htuscher

Is there also a way to do this automaticaly after "docker-compose up" with the right container name?

mediaessenz avatar Mar 26 '20 11:03 mediaessenz

We have that in our Makefile

up: ## Start Project
	docker-compose up -d --remove-orphans --force-recreate
	docker-compose exec app chown -R 1000:1000 /app/var/

htuscher avatar Mar 26 '20 13:03 htuscher

I see, thanks for sharing.

Any idea, why I get this errors in the backend:

Warning: rename(/app/var/transient/preview_1066312516667750181.jpg,/app/public/fileadmin/_processed_/c/7/preview_Alexander_Grein_Avatar_d04235402e.jpg): Operation not permitted in /app/public/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php on line

When I check the owner/group of this directory inside the app container, all files inside there and the subfolder itself have application:application with 644 (files) 2775 (folder)

It seems the system couldn't delete the files inside /app/var/transient/ after doing some image processing. I can see the processed file inside /app/public/fileadmin/processed/c/7/, but there is also still this old, unnecessary file /app/var/transient/preview_1066312516667750181.jpg

mediaessenz avatar Mar 26 '20 14:03 mediaessenz

After some research I found a way to fix this problem. Unfortunately it needs a TYPO3 core patch :-( This code in line 787 of TYPO3\CMS\Core\Resource\Driver\LocalDriver::addFile() is the problem:

                $result = rename($localFilePath, $targetPath);

When I change it to this, it works fine:

                $result = copy($localFilePath, $targetPath);
                unlink($localFilePath);

I have no idea why this is necessary, but it seams to be a bug in TYPO3 (or PHP?). I just checked some /app/var/transient/ dirs on my live systems and they are all packet with this temporary files!

mediaessenz avatar Mar 26 '20 16:03 mediaessenz

One more, hopefully last question to this issue: I added the docker-compose exec app chown -R 1000:1000 /app/var/ to my Makefile, which works fine for my development system. If I want to do the same on my production system, where I use the same docker setup (with production settings, of course), what about the restart: always entries inside my docker-compose.yml file. Are they startup the system after a reboot with the fixed rights of the /app/var/ folder?

mediaessenz avatar Mar 30 '20 13:03 mediaessenz

No a restart does not execute a command that it's not aware of.

But the rights remain as long as don't recreate the named volume that is mounted.

htuscher avatar Mar 30 '20 14:03 htuscher

Cool, thanks for helping

mediaessenz avatar Mar 30 '20 14:03 mediaessenz

Is there any reason, why this volume "trick" doesn't work on a production system? I added exact the same things to the docker-compose.yml of a staging system (ubuntu) with the exact same docker/docker-compose versions. If I rebuild this docker system, the /app/var dir is still synced by docker with the local filesystem. Any idea what could be the reason for this?

mediaessenz avatar Mar 30 '20 15:03 mediaessenz

No, but why would you care. On Linux that's just irrelevant performance wise.

htuscher avatar Mar 30 '20 15:03 htuscher

Okay, good to know :-)

mediaessenz avatar Mar 30 '20 15:03 mediaessenz

It's me again: I have the problem that my volume mapping only works for a short moment.

My steps:

  1. Stop all docker containers
  2. Remove local app/var folder by rm -rf app/var
  3. Remove app container with docker-compose rm app
  4. Start containers by make up with the upper descipted settings
  5. Open shell to running app container by make shell and checked correct /app/var owner -> application/application
  6. Open the app (TYPO3 page) in a browser and visit some pages who create cache files inside e.g. /var/app/cache/code
  7. Check local app/var, which normaly should not exists -> folder exists and is full of generated files
  8. Go into the app container by "make shell" and check owner of /app/var -> 501:dialout

What's going wrong here?

mediaessenz avatar Apr 01 '20 08:04 mediaessenz

Okay, I think I have found my problem. After removing this setting from my Development-Context-Configuration it works like expected: $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = 'dialout';

mediaessenz avatar Apr 01 '20 08:04 mediaessenz