openbenches.org icon indicating copy to clipboard operation
openbenches.org copied to clipboard

Docker for local development?

Open pwaring opened this issue 2 years ago • 13 comments
trafficstars

Would it be useful to have a Docker environment that could be used for local development, with everything pre-installed and with version numbers (e.g. for PHP) matching production? I've moved lots of existing bespoke projects into Docker so I think it would be doable.

pwaring avatar May 31 '23 15:05 pwaring

Sure! Go ahead and do it.

edent avatar Jun 02 '23 21:06 edent

Okay, I'm working on this now.

pwaring avatar Jun 04 '23 08:06 pwaring

I'm also looking at this - I was going to take a look at #333 - and I didn't want to install a load of stuff - and though that the docker approach might be cool (I use it at work for this sort of thing).

So far I have :

  • A Database set up script - that (i think) sets up the database correctly - there seems to be some warnings when executing image

  • A PHP / FPM based application that I think might work - currently getting composer vendor issues image

  • An NGINX wrapper - which passes php calls to FPM - but serves static files.

computamike avatar Jul 23 '23 00:07 computamike

@edent - One thing I'm not sure about : the code (and the CONTRIBUTING.md file) use composer to install dependancies - but there isn't a composer.json file included? unless the composer installation includes the version number, then won't there be the possibility that developers could have different version dependencies installed?

computamike avatar Jul 23 '23 01:07 computamike

Thanks for the prompt @computamike - I've added the composer.json file

edent avatar Jul 23 '23 08:07 edent

Just to add, I'm not working on this at the moment - I couldn't get the environment file to change the cache location and eventually I gave up in frustration (still not sure what the problem was).

pwaring avatar Jul 24 '23 08:07 pwaring

@pwaring - what was the issue with the cache location? at the moment I have caching working - but I'm guessing you wanted to map it somewhere else on the container so that it wasn't mapped back to the host file system?

computamike avatar Jul 27 '23 22:07 computamike

@computamike Yes, I wanted the cache to use /tmp inside the container, that way it wouldn't create lots of files on the host (owned by root, one of the very annoying things about Docker). My understanding of Symfony is that setting APP_CACHE_DIR="/tmp" in the .env file should change the cache directory, but this didn't seem to work, and neither did manually setting $_ENV['APP_CACHE_DIR'], and stepping through with Xdebug suggested Symfony wasn't using it.

pwaring avatar Jul 28 '23 08:07 pwaring

@pwaring - I thought that might be it. Caching configuration is provided by bundle configuration - https://symfonycasts.com/screencast/symfony-fundamentals/bundle-config#play image

  • I think if you mounted in a suitable config file there, then that might work - I'll give it a go.

computamike avatar Jul 28 '23 18:07 computamike

Hi @pwaring - I'd be interested in getting your opinion on my branch for adding docker support for local development - I'm putting together a guide for developers so it's not 100% yet.

https://github.com/computamike/openbenches.org/tree/Feature/docker-setup

I currently have the code volume mapped from a Windows drive (as opposed to running the code in wsl) and the page performance is not great - but I have read that storing the code like that can have performance issues.

computamike avatar Aug 02 '23 11:08 computamike

Just an update - I'm currently attempting to get Xdebug working - but from what I can see it's just a case of open the port, install Xdebug and set up some config and off you go...

computamike avatar Aug 10 '23 23:08 computamike

@computamike If you want an example of how to get it working in VSCode, you can lift the config from a repository I work on:

https://github.com/phpdev-uk/slim-skeleton

Specifically the launch.json:

https://github.com/phpdev-uk/slim-skeleton/blob/main/.vscode/launch.json

Dockerfile:

https://github.com/phpdev-uk/slim-skeleton/blob/main/docker/Dockerfile

xdebug.ini:

https://github.com/phpdev-uk/slim-skeleton/blob/main/docker/php/xdebug.ini

It took me a long time to get this working as everything has to match - one minor difference and it won't work, plus you won't necessarily get a helpful error message as to why...

pwaring avatar Aug 11 '23 08:08 pwaring

@computamike If you want an example of how to get it working in VSCode, you can lift the config from a repository I work on:

https://github.com/phpdev-uk/slim-skeleton

Specifically the launch.json:

https://github.com/phpdev-uk/slim-skeleton/blob/main/.vscode/launch.json

Dockerfile:

https://github.com/phpdev-uk/slim-skeleton/blob/main/docker/Dockerfile

xdebug.ini:

https://github.com/phpdev-uk/slim-skeleton/blob/main/docker/php/xdebug.ini

It took me a long time to get this working as everything has to match - one minor difference and it won't work, plus you won't necessarily get a helpful error message as to why...

Thanks - I got it working last night - then the cachinf stopped working... I open port 9003 on the defender firewall - but I'm not sure I needed to do that. I'll make sure what i have looks good compared to what you've done - probably tonight.

computamike avatar Aug 11 '23 12:08 computamike