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

Add Docker setup #242

Merged
merged 2 commits into from
Jul 29, 2018
Merged

Add Docker setup #242

merged 2 commits into from
Jul 29, 2018

Conversation

teohhanhui
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets Sylius/Sylius#9414
License MIT

Replaces #232

host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
driver: pdo_mysql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep that parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it cannot be used in any meaningful way. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this change for now.

@@ -10,13 +9,13 @@ parameters:

mailer_transport: '%env(SYLIUS_MAILER_TRANSPORT)%'
mailer_host: '%env(SYLIUS_MAILER_HOST)%'
mailer_port: '%env(SYLIUS_MAILER_PORT)%'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract this change to another PR?

Copy link
Contributor Author

@teohhanhui teohhanhui Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. But we need it here...

@@ -52,6 +52,9 @@ watchShop.description = 'Watch shop asset sources and rebuild on changes.';
export const build = gulp.parallel(buildAdmin, buildShop);
build.description = 'Build assets.';

export const watch = gulp.parallel(watchAdmin, watchShop);
watch.description = 'Watch asset sources and rebuild on changes.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. But we need it here...

.travis.yml Outdated
- docker-compose pull --ignore-pull-failures
- docker-compose build --pull
- docker-compose up -d
- sleep 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea how to solve that better, just leaving a comment so it's more visible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there are more fancy ways, but this is the simplest way that works. 😆

@@ -0,0 +1,108 @@
version: '3.4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two different files for dev and prod would be hard to keep in sync (eg. this version differs).

@jacquesbh mentioned this on Slack on Friday:

yes. And it's just a step away to create a docker-compose.traefik.yml and explain that docker-compose -f docker-compose.yml -f docker-compose.traefik.yml can be use

Can we use an architecture like this for those extra containers (eg. mailhog, nodejs)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just about additional services...

@@ -0,0 +1,14 @@
apc.enable_cli = 1
date.timezone = ${PHP_DATE_TIMEZONE}
opcache.enable_cli = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opcache in CLI might cause some issues during development

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such as? :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we had an issue when phpspec was running unexisting spec which had been removed before, the issue vanished after we disabled opcache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, that sounds like a misconfiguration of OpCache, so we should be fine here.

@nietzscheson
Copy link
Contributor

The Docker configurations for the Sylius project should not be included in the standard version. The reasons that I consider main are:

  • There are many out there who do not even use Docker. They do not even use virtual machines.
  • The learning curve with Docker is quite complex. So its use should not be mandatory. Not all cloud payment systems allow the use of root to install certain packages on the virtual machine.
  • There are other containerization projects such as:
       - Docker Container for Windows (https://github.com/docker/for-win)
       - RKT (https://github.com/rkt/rkt)

If Docker is included in the Standard version, the configurations of the Vagrant configured for Sylius are also included.

In Sylius/Sylius#9414 @stefandoorn adds the following: "can it still be a separate repo? I prefer to have my infra stuff in separate repo, instead of combined with the application itself (SRP). Besides that, not everyone likes or is using Docker, so for these it's not needed to have it in the same repo."

Matter of which I totally agree.

So, all efforts to achieve a good configuration of Docker for Sylius (https://github.com/Sylius/docker) should focus on the repository that already exists and keep it separate.

@teohhanhui
Copy link
Contributor Author

@nietzscheson We've already had that discussion in Sylius/Sylius#9414 and on Slack. I don't see the need to bring it up again here...

@nietzscheson
Copy link
Contributor

So is. But this is where the code merges and I see that you want to reiterate what precisely was already discussed on the channel. I just want to make clear my position...

@gabiudrescu
Copy link

Personally, I have no preference between having the Docker setup in Sylius/Sylius-Standard or as a separate repository.

Though I have a question: how can one re-use this setup when trying to contribute to Sylius/Sylius? through copy-paste of the docker and docker compose files?

Also, certain services are missing:

  • Selenium
  • Chrome headless
  • Redis or Memcache (for production environment, especially on multi-node setup, I find it mandatory)

Shouldn't we include these too?

@teohhanhui
Copy link
Contributor Author

how can one re-use this setup when trying to contribute to Sylius/Sylius? through copy-paste of the docker and docker compose files?

One way is to mount the host directory into, say, /src/Sylius/Sylius

Also, certain services are missing

Could be added in other PR(s)

@gabiudrescu
Copy link

Second thing I want to bring under your attention: running commands under the root user inside containers is going to mess up permissions on the files on the host.

Especially on development mode, I find it better to use another user inside the container that has UID and GID mapped with the one from the host. On the setup I generally use, I have the following in the docker file:

groupadd -g "$APPLICATION_GID" "$APPLICATION_GROUP"
useradd -u "$APPLICATION_UID" --home "/home/$APPLICATION_USER" --create-home --shell /bin/bash --no-user-group "$APPLICATION_GROUP" -g "$APPLICATION_GID"

This way, whenever entering the container, I make sure I use the $APPLICATION_USER and everything is OK.

Also, my understanding is that running commands inside docker containers as root may imply a security risk:

@gabiudrescu
Copy link

@teohhanhui

One way is to mount the host directory into, say, /src/Sylius/Sylius

can you offer me an example on how one can use this docker setup to test a modification it brought to the Sylius/Sylius vendor file?

@teohhanhui
Copy link
Contributor Author

@gabiudrescu

can you offer me an example on how one can use this docker setup to test a modification it brought to the Sylius/Sylius vendor file?

It's basically on its own, not as a vendor package. Just cd to that directory and do what you need to do.

@teohhanhui
Copy link
Contributor Author

As for running as root in the container, it's as we've discussed on Slack: there is no good solution that I'm aware of. But we could perhaps add support for running with a different uid/gid in the entrypoint.

@teohhanhui
Copy link
Contributor Author

teohhanhui commented Jul 24, 2018

Switching user in the Dockerfile cannot work, because the built image has to be portable (and redistributable).

@jacquesbh
Copy link
Member

jacquesbh commented Jul 24, 2018

User rights

For the user rights we have this:

Makefile:

export USER_UID=$(shell id -u)
example:
	docker-compose ps

In our Dockerfiles:

# Use www-data user
ARG USER_UID=1000
RUN usermod -u $USER_UID www-data

By default www-data has uid 1000.
On macOS the user id is 501 usually.

In our docker-compose.yml:

services:
  my-container:
    build:
      context: my-container/
      args:
        USER_UID: ${USER_UID}

This way, by using a simple variable, we avoid a lot of problems.

We don't have a makefile yet. Why not adding one? It's a good way to improve the developers flow.

Missing containers

The missing containers are for testing purpose.

This is why I propose to use a docker-compose.testing.yml. We don't need to run all the containers all the time, specially Selenium and headless browsers since they are consuming a lot.

@teohhanhui
Copy link
Contributor Author

teohhanhui commented Jul 24, 2018

@jacquesbh Anything that involves setting uid/gid in the Dockerfile is not a solution, because it'd result in an image that's not portable / redistributable.

@teohhanhui teohhanhui closed this Jul 24, 2018
@teohhanhui teohhanhui reopened this Jul 24, 2018
@jacquesbh
Copy link
Member

This is portable, working on Windows, Linux and macOS. We use it everyday for many projects. So…

@teohhanhui
Copy link
Contributor Author

Missing containers

Let's keep this first PR small?

@teohhanhui
Copy link
Contributor Author

No, I'm talking about the image being portable. It should be able to be used by any user regardless of their uid/gid on the host, without having to rebuild the image.

@teohhanhui
Copy link
Contributor Author

We should support running with arbitrary uid/gid (via the --user flag of docker run and its equivalent in docker-compose.yml), but otherwise step down from root if necessary:

docker-library/mysql#397 (comment)
docker-library/php#70 (comment)

@teohhanhui
Copy link
Contributor Author

I hope we could have this PR merged soon, then others could help to make things better.

@pamil pamil merged commit a56eecf into Sylius:master Jul 29, 2018
@pamil
Copy link
Contributor

pamil commented Jul 29, 2018

Thank you, Teoh, let's make it the best Docker ever for 1.3 release 🎉

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

Successfully merging this pull request may close these issues.

5 participants