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

Added docker environment #250

Closed
wants to merge 2 commits into from
Closed

Added docker environment #250

wants to merge 2 commits into from

Conversation

sazo
Copy link

@sazo sazo commented Mar 16, 2017

Q A
Is bugfix? no
New feature? yes
Breaks BC? no
Tests pass? yes
Fixed issues #244 , #214

Added docker environment

BUT the php-fpm container is my personal one - https://hub.docker.com/r/sazo/php-fpm/
Could be nice if some yii maintanincer created a repo for a php-fpm image.

@samdark
Copy link
Member

samdark commented Mar 16, 2017

There's a repo in the works: https://github.com/yiisoft/yii2-docker

@sazo
Copy link
Author

sazo commented Mar 16, 2017

arrr nice.. should we wait merging this until the images is public and then ajust this PR afterwards?

@samdark
Copy link
Member

samdark commented Mar 16, 2017

Yes.

@samdark samdark added this to the 2.0.x milestone Apr 26, 2017
@axklim
Copy link

axklim commented Jun 9, 2017

why so long, can i help ?

@sazo
Copy link
Author

sazo commented Jun 9, 2017

@axklim if you help out at https://github.com/yiisoft/yii2-docker will speed of the process. This PR will, i hope, move forward when that repo is ready.

@bscheshirwork
Copy link
Contributor

@sazo I also create a some composition for advanced template, you can find it by here names:
bscheshirwork/docker-yii2-app-advanced
bscheshirwork/docker-yii2-app-advanced-rbac
bscheshirwork/docker-yii2-app-advanced-redis

official image is have a so long-time discusses about included parts 😢

@schmunk42
Copy link
Contributor

The advanced app might be a bit more complex, but nonetheless ... related: yiisoft/yii2-app-basic#157

I'd recommend to use only 3 containers frontend, backend and mysql for the initial setup.
Apache might not be the first choice for running PHP with Docker, but it's much simpler regarding the setup.

@sazo
Copy link
Author

sazo commented Nov 16, 2017

@schmunk42 Is your idea to remove all the help containers? I like the idea that you dont need to install anything(beside docker) before getting started not even composer and PHP. Keeps the developers machine clean.

I can reduce the 2 nginx containers(frontend and backend) to one nginx container. Just need to change the nginx configuration

@schmunk42
Copy link
Contributor

I like the idea that you dont need to install anything(beside docker) before getting started not even composer and PHP.

I think you do not need separate services for init, codecept and yii, when you use docker-compose run you will start a new container anyway. But yes, I am also talking about having only Docker installed; no other tools required.

A separate test environment can be handled by merely using the same stack with a different project name (and db) and setting YII_ENV=test.

I can reduce the 2 nginx containers(frontend and backend) to one nginx container. Just need to change the nginx configuration

The nginx setup is pretty tricky IMHO. Currently you use a host-volume for static files (and index.php), which is OK in development, but it's a no-go in production. PHP and nginx in separate containers is the "pure Docker-way", but you either need volumes_from, which also sucks in production, or build two images per site, resulting in building 4 custom containers when splitting frontend and backend.

That's the reason, why we built nginx on top of the offical php image - it's working very well for us, but I do not know if it would be a good starting point, since it's actually not "the 100% Docker-way"; because it runs multiple processes on one container with forego.

I am unsure what is the best way to start, an Apache+PHP container is very simple to use, although also not the thing I'd run in production.

References:

@samdark
Copy link
Member

samdark commented Feb 17, 2018

@schmunk42 do you have time to assist with this one?

@schmunk42
Copy link
Contributor

Should frontend and backend run in separate containers?

The directory structure of advanced and basic app might not be ideal for Docker development, see also yiisoft/yii-base-web#2

@samdark samdark modified the milestones: 2.0.x, 2.0.14.1 Feb 21, 2018
@bscheshirwork
Copy link
Contributor

Should frontend and backend run in separate containers?

this is (ordinal) case of diff servers of frontend and backend.

common will be duplicate

@sazo
Copy link
Author

sazo commented Feb 22, 2018

IMO we can reduce the frontend and backend container to one Apache+PHP container and just use apache configuration to specify frontend and backend. It makes things simple as @schmunk42 wrote.

@schmunk42 about the help containers. What if i reduce it to one container and then user just set the entrypoint manually?

For me its all about making it easy for developing. This can still be used in production - apache performance is fine for small apps.

@schmunk42
Copy link
Contributor

I tend to have two containers, since we could use the same base image without any modifications. You'd simply access frontend/backend under different ports.

If we have only one container we'd need to adjust the server config to handle multiple document roots.

@bscheshirwork
Copy link
Contributor

If we have only one container we'd need to adjust the server config to handle multiple document roots.

but we have 2 url (i.e. for example frontend.dev and backend.dev) in both cases (and document roots on each)

@schmunk42
Copy link
Contributor

This requires some sort of setup on your host to create DNS (or host) entries for those domains - don't use .dev btw ;)

The more "dockerish" way would be to use ports.

You can also use a reverse-proxy, like https://github.com/jwilder/nginx-proxy - but by default it works by using one ENV variable per service.

@bscheshirwork
Copy link
Contributor

@schmunk42 yes of course.
In my case usage w/o changes in any entrypoints. Only docker-compose.yml and nginx.conf
this names is example, but this names can be use internal in test (for example)
also I connect to container throw your (docker service from docker-compose.yml) name. For domain validation simulation I can use docker network alias.
https://github.com/bscheshirwork/docker-yii2-app-advanced-redis/blob/06657541edcf785fa8ab20b2fdb004fce6e49b42/docker-codeception-run/docker-compose.yml#L41-L57
https://github.com/bscheshirwork/docker-yii2-app-advanced-redis/blob/06657541edcf785fa8ab20b2fdb004fce6e49b42/nginx-conf-test/nginx.conf#L8
I use separate nginx config for run tests. This issue about test environment too (not).

also I can use reverse-proxy on pure nginx in same docker network in other case.
https://github.com/bscheshirwork/docker-yii2-app-advanced-redis/blob/06657541edcf785fa8ab20b2fdb004fce6e49b42/docker-compose.yml#L39-L53

@schmunk42
Copy link
Contributor

schmunk42 commented Mar 6, 2018

Some points I stumbled upon:
- the `init` script which asks you to setup either Dev or Prod, actually in Docker you'd do that via ENV vars
- strong assumptions about directory structure (ie. you can't really reconfigure vendor and config directories); or alternatively reconfiguration of Apache/Nginx
- sharing of code in *common*, but separate containers for *frontend*, *backend*

~~~I think it would be better, if the current PR could use `yiisoftware/yii2-php`. But I won't be able to actively support or develop it for `yii2-advanced-app`.~~~

@bscheshirwork
Copy link
Contributor

strong assumptions about directory structure (ie. you can't really reconfigure vendor and config directories); or alternatively reconfiguration of Apache/Nginx

i.e. reconfigure from docker-compose.yml?

@schmunk42
Copy link
Contributor

schmunk42 commented Mar 7, 2018

OK, forget everything I've said and assume the opposite 😄

I created a PR with a very minimal setup, please have a look. It needs some polish, but let me know if this is going into the right direction.

@bscheshirwork
Copy link
Contributor

@schmunk42 how about use shared composer storage in backend and frontend?

@schmunk42
Copy link
Contributor

@bscheshirwork Added. Thanks!

@samdark
Copy link
Member

samdark commented Mar 7, 2018

Closing this one in favor of #347

@samdark samdark closed this Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants