Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Updated docker-compose to 3.0, use of .env file, and use of a custom network #195

Closed
wants to merge 9 commits into from

Conversation

joserprieto
Copy link

@joserprieto joserprieto commented Nov 11, 2017

Hi;

This may be useful for your;

  • I updated the docker-compose.yml file, to docker-compose 3.0 specs.
  • Avoid the use of "enviroment" key, and isolate the enviroment vars in a separated file (I versioned a .env.example only).
  • Use of a custom network, for better management in the host running docker.

If you want, i can edit the readme and document the use and changes, and why is better this approach.

Regards.

- Enable the use of a .env file, and remove the enviroment
sections on the docker-compose.yml file.

- Enable a custom network, for the complete stack.
- Enable the use of a .env file, and remove the enviroment
sections on the docker-compose.yml file.

- Enable a custom network, for the complete stack.
@joserprieto
Copy link
Author

Tested in:

Linux Mint 18.2, and last versions of Docker and docker-compose.

Debian 9 and last versions of Docker and docker-compose.

@mattermod
Copy link
Contributor

Thanks @joserprieto for the pull request!

Per the CONTRIBUTING.md file displayed when you created this pull request, we need to add you to the list of approved contributors for the Mattermost project.

Please help complete the Mattermost contribution license agreement?

This is a standard procedure for many open source projects. Your form should be processed within 24 hours and reviewers for your pull request will be able to proceed.

Please let us know if you have any questions.

We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team.

@pichouk pichouk requested review from xcompass and pichouk November 11, 2017 20:16
@pichouk
Copy link
Contributor

pichouk commented Nov 11, 2017

Thanks @joserprieto !
I'm quite busy for now but I promise I'll take a look :)

@pichouk pichouk added Enhancement 2: Dev Review Requires review by a core committer waiting-for-cla labels Nov 11, 2017
restart: unless-stopped
links:
Copy link
Contributor

Choose a reason for hiding this comment

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

We removed links in PR #185 because it is deprecated. Should remove it I guess.

Copy link
Author

Choose a reason for hiding this comment

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

The links is because you can assign one of more aliases for the different hosts; i think that, for the moment, docker-compose will mantain retrocompatibility

@pichouk
Copy link
Contributor

pichouk commented Nov 14, 2017

So we're back on the same question again @jasonblais and @xcompass : should we move to Docker Compose 3 ?

Maybe it is a good idea. Actually, the docker-compose.yml file provided in this repository is just a cool tool we provide to help people deploying with Docker. In fact, it is quite easy to build Docker images (using Dockerfiles) and deploy without Docker Compose (or with an old version). I did it for my production server because I have some custom needs, and this is not something really hard if you have some basics with Docker.
My point is : the docker-compose.yml file on this repository is not that critical. In few minutes you can easily create a new one, matching your needs. So changing version of Docker Compose is okay as soon as we provide correct documentation on how to build the Docker images.

@jasonblais
Copy link
Contributor

@pichouk I forget the previous discussion, but what were the potential side effects of moving to Docker Compose v3? (Link to a previous post is okay, I wasn't able to find it)

And conversely, what is the benefit of moving to v3? At first it was to support swarm cluster I think, but that is resolved with #176

# args:
# - edition=team
args:
- edition=team
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not change the default behavior.

Copy link
Author

Choose a reason for hiding this comment

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

Ok.
For, then, the docker-compose.yml don't be versioned.

# - AWS_REGION=us-east-1
env_file:
- .env
networks:
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale to use custom network?

Copy link
Author

Choose a reason for hiding this comment

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

For many reasons, you can want to have under control the IPs and the ports exposed outside, and so on.

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add some instruction to copy the sample file to .env?

@@ -1,53 +1,68 @@
version: "2"
version: '3'
Copy link
Contributor

Choose a reason for hiding this comment

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

Which docker-compose directive requires v3 format? If we upgrade the compose files to v3, it will break backward compatibility. Not sure if it is good time to upgrade to v3 and if we decide to go with v3, we need to list it as a breaking change.

@pichouk
Copy link
Contributor

pichouk commented Nov 14, 2017

@jasonblais We add some discussions about this subject on #151 and this forum post (and a little on #104 and #147).

Yes the main benefit to moving to v3 is the swarm support, but it was solved. So, the "only" benefit now is to be up to date on our default configuration to deploy with Docker. I have no particular interest to moving on v3. It just not the first time someone submit the idea ;)

@jasonblais
Copy link
Contributor

Thanks! I'm okay switching to v3, don't see major issues and seems to be the preference of the community @pichouk

@jasonblais
Copy link
Contributor

As long as we update the documentation accordingly, which you've taken care of here :)

Can you also help take a look at

to see if anything needs to be updated?

@pichouk
Copy link
Contributor

pichouk commented Nov 18, 2017

@jasonblais Great :)
We will work on this PR with @joserprieto since there is some things to correct/change, but when it will be ready I'll take particular attention to Mattermost documentation and will update it :)

@pichouk pichouk added Awaiting Submitter Action Blocked on the author and removed waiting-for-cla labels Nov 19, 2017
@joserprieto
Copy link
Author

I read all the discussions, and i think that here are a debate of use version 2 or version 3 of docker-compose files.

The solution can be easy; put docker-compose.v2.yml.sample and docker-compose.v3.yml.sample, and the correspondent instructions on the README.

I make a PR right now with this approach in mind.

@joserprieto
Copy link
Author

Changes done!

Please, review, @pichouk @xcompass

Regards.

@joserprieto
Copy link
Author

@pichouk about the main documentation, that remarks @jasonblais, i think that:

https://docs.mattermost.com/install/prod-docker.html

Deploy the Mattermost Production Docker setup by running:

git clone https://github.com/mattermost/mattermost-docker.git
cd mattermost-docker
docker-compose build
docker-compose up -d

Can be:

Deploy the Mattermost Production Docker setup by running:

git clone https://github.com/mattermost/mattermost-docker.git
cd mattermost-docker
open the README and follow instructions to select docker-compose version and for the enviroment vars.
docker-compose build
docker-compose up -d

The other link:

https://docs.mattermost.com/install/docker-local-machine.html

Is for use on a dev environment, not for make all the stack and so on.

Regards!

@xcompass
Copy link
Contributor

xcompass commented Dec 1, 2017

@joserprieto Thanks. I would prefer to leave a docker-compose yaml file as default one (maybe v3 one). And let people to copy v2 one or use -f option if they need v2 compose file.

@pichouk
Copy link
Contributor

pichouk commented Dec 5, 2017

I agree with @joserprieto now. We will never achieve to have a "perfect docker-compose.yml that match everyone needs". Maybe we should provide multiple example files and let users choose what they want to use.
Also it will force users to understand what they are doing, and avoid to just run git clone && docker-compose up -d, that can lead to situations where a user doesn't understand how to upgrade/where data is stored, etc.

It will not be a breaking change. Current users will still have their docker-compose.yml file so it will not break their setup.

@xcompass
Copy link
Contributor

xcompass commented Dec 7, 2017

@pichouk when you remove the docker-compose.yml from this repo, wouldn't it also remove from the local repo when one pulls the change (assume no change in the file)?

@pichouk
Copy link
Contributor

pichouk commented Dec 8, 2017

@xcompass Hum you're right. I just tested it and if we want to remove the docker-compose.yml file and add it to .gitignore, it will remove the file on local repositories when pulling only if you never change the file.
If you modify this file (to change default password for example) you will not be able to pull, so it will not remove it. So everybody have to backup the file, pull the change, and restore it.

@joserprieto
Copy link
Author

I'm agree with @pichouk.
And, remember, this docker / stack is for production purpose; so, the normal behaviour is to change default passwords on the docker-compose.yml (passwords that will be isolated, on a .env file, like in my PR).

I think that a votation may resolve this question; logically, i can't vote, but the mattermost team's votes can resolve all of this.

Regards.

@pichouk
Copy link
Contributor

pichouk commented Dec 12, 2017

Good for me. If @jasonblais and @xcompass are ok, then you can update your PR to match this new organization.
We will take care that it didn't broke current users installations and that documentation is correctly updated.

@joserprieto
Copy link
Author

joserprieto commented Dec 12, 2017

About of to not broke current users installations; i can see two scenarios:

  1. User changed the docker-compose.yml file (the default behaviour, i hope...); so, this user can't make a git pull and not loses his configuration (on his docker-compose.yml file); when he makes a git pull, it has to force it, and discard changes on his docker-compose.yml file (so, this new approach is good for him).
  2. User not changed the docker-compose.yml file; yes, in this case, if we put the docker-compose.yml on the .gitignore file, they docker-compose.yml file will "disappears" whith git pull.. But i think that is a very helpful behaviour, because forces the user to change default users and passwords (that are in the docker-compose.yml file already).

A correct approach (imho), it's to isolate the vars outside the docker-compose.yml file (on a .env file gitignored too), and isolate the production ready docker-compose.yml, that defines the stack (so, it's a configuration file, in a certain way..)

I think that is this approach is reflected on the documentation, the user will not have trouble with the change.

Regards.

@pdemagny
Copy link
Contributor

Any news on a merge for this PR ? Once its merged i'll start to work on #203 :)

@pdemagny pdemagny mentioned this pull request Dec 15, 2017
@pichouk
Copy link
Contributor

pichouk commented Dec 15, 2017

@joserprieto can submit changes describe in this comment and, as soon as @xcompass and/or @jasonblais approve this changes, we can merge :)

@joserprieto
Copy link
Author

joserprieto commented Dec 16, 2017

The use of docker volumes, or Traefik, i think that is a personal election.

For example; on the current stack definition, we have:

    volumes:
      - ./volumes/app/mattermost/config:/mattermost/config:rw
      - ./volumes/app/mattermost/data:/mattermost/data:rw
      - ./volumes/app/mattermost/logs:/mattermost/logs:rw
      - /etc/localtime:/etc/localtime:ro

    volumes:
      # This directory must have cert files if you want to enable SSL
      - ./volumes/web/cert:/cert:ro
      - /etc/localtime:/etc/localtime:ro

And yes, we can use something like that:

version: "3"
services:
(...)
    volumes:
      - mttm-config:/mattermost/config:rw
      - mttm-data:/mattermost/data:rw
      - mttm-logs:/mattermost/logs:rw
      - etc-localtime:/etc/localtime:ro
(...)

volumes:
  mttm-config:
  mttm-data:
  mttm-logs:
  web-cert:
  etc-localtime:

But it's the same of the discussion on other threads; is better to use volumes? is better to use custom networks? is better to use compose files v2 or v3?

The answer is easy; depends of the use case.

With traefick, is the same.

I think that put sample docker-compose files, is the best choice; and, with this, any user can take is own decissions, taking his/her use case.

@joserprieto
Copy link
Author

joserprieto commented Dec 16, 2017

@pichouk , if i'm not wrong, i made the changes.

I resume changes made:

  • Created two separated files; docker-compose-v3.yml.sample and docker-compose-v2.yml-sample.
  • Updated the v2 to get the advantange of isolated environment vars in a .env file.
  • Updated the README with the instructions to use the docker-compose that you choose, and the .env file that you need.
  • gitignored files .env and docker-compose.yml

I think that is all done... But, if any change is needed, please, tell me.

@joserprieto
Copy link
Author

Another changes that can will add, is the explanation of how isolated the .env file and docker-compose.yml file.

One option (as valid as another), is take advantage of git hooks. And do something like:

  • Put the .env and the docker-compose.yml files outside the repo directory.
  • Make symlinks to this files, on the repo dir.
  • Before a pull/push, remove this symlinks.
  • After the pull/push, make the symlinks again.

Another form, is make a simple bash script outside the repo dir, that do something like "setup.sh --enable" and "setup.sh --disable", for put symlinks / delete symlinks, before/after pull/push.

Maybe useful to explain this on the README. Or, it can be useful on the docs. As you wish 😉

@pdemagny
Copy link
Contributor

pdemagny commented Dec 16, 2017

Well, for "simple" compose files (debate v2/v3), i think that going with the flow is important here, v2 is getting really old and should be present only for backward compatible reasons.

Regarding the "Volumes" debate, a quick look at docker doc is enough for me:

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. Volumes have several advantages over bind mounts ...

I read a lot of people being reluctant to move to docker volumes because they think its easier to backup, why would it be ? Docker volumes are stored in a predictible directory on the host ... (/var/lib/docker/volumes) and are named like you named them in the compose file.
They offer better integration with docker, better isolation & avoid dirty permissions hacks.
And btw using local mounts tied to one host makes no sense in a multi-node swarm where you want your storage to be distributed & redundant over multiple nodes, or at least portable.

Same goes for custom networks, they offer better isolation for services, while still allowing them to talk to each other if the user wants to.

As for the env file, it is a best practice that i'm going to apply on docker-stack.yml file, but we also should promote the use of docker secrets for passwords in this file.

And for Traefik, yes it is a personal choice, but it offers this choice to the users of this repo, and doesn't prevent from adding more choices for them in the future by adding more compose/stack file with support for more load-balancers ...
Having a single node swarm is almost pointless, people running swarms have these kind of services, we simply provide them with a good example here.
Traefik is a container ready solution, unlike things such as nginx-proxy, and offers a quick and nice way of handling https by automating creation & renewal of ssl certificates.

For all of these reasons, i completely back the solution with multiple yaml "sample" files in the root of the repo, with something like:

  • docker-compose.yml (v3, volumes)
  • docker-compose-v2.yml (v2, mounts, for backward compatibility)
  • docker-stack.yml (v3 with volumes, configs, secrets, env_file, network)
  • docker-stack-with_traefik.yml (same but with traefik & letsencrypt)

I'm willing to do this after the merge of this PR by extending the work i've done on docker-stack.yml file, depending of what you decide, just let me know ;)

.env.sample Outdated

# See https://docs.docker.com/compose/environment-variables/#the-env-file

# PostgreSQL Enviroment Variables:
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo Enviroment => environment

Copy link
Author

Choose a reason for hiding this comment

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

done

.env.sample Outdated
POSTGRES_DB=mattermost
#PGDATA="/path/to/your/postgresql/data/files | default: /var/lib/postgresql/data/pgdata optional"
#POSTGRES_DB="name_of_your_postgresql_db | default: postgres_user value | optional
# uncomment the following to enable backupe
Copy link
Contributor

Choose a reason for hiding this comment

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

backup*

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -50,4 +41,4 @@ services:
- /etc/localtime:/etc/localtime:ro
# Uncomment for SSL
# environment:
# - MATTERMOST_ENABLE_SSL=true
# - MATTERMOST_ENABLE_SSL=true
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the newline :)

Copy link
Author

Choose a reason for hiding this comment

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

done


# Specific files:

docker-compose.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep a newline :)

Copy link
Author

Choose a reason for hiding this comment

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

done

README.md Outdated
* https://forum.mattermost.org/t/mattermost-with-docker-discussion-about-requirements/3518
* https://github.com/mattermost/mattermost-docker/issues/151

You only have to do is:
Copy link
Contributor

Choose a reason for hiding this comment

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

is -> this

Copy link
Author

Choose a reason for hiding this comment

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

done

README.md Outdated
@@ -83,6 +132,14 @@ Put your SSL certificate as `./volumes/web/cert/cert.pem` and the private key th
no password as `./volumes/web/cert/key-no-password.pem`. If you don't have
them you may generate a self-signed SSL certificate.

### Building images

Before start the containers, we must to build the images:
Copy link
Contributor

Choose a reason for hiding this comment

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

we must to build -> you must build

Copy link
Author

Choose a reason for hiding this comment

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

done

@pichouk
Copy link
Contributor

pichouk commented Dec 16, 2017

@joserprieto Great :)
I made a review, I'll like @xcompass to review too.
Also, it is important to update documentation on this page. So if you can submit a PR on this file too I'll appreciate :)

To add new features (as @pdemagny suggest) I prefer to wait for another PR, but it is a good idea :)

Also, thanks for your proposal, it is a great improvement :)

@joserprieto
Copy link
Author

@pichouk i think that i made all fixes.
Review and if you see more errors, please, tell me.

About the documentation, i can propose here the new doc page, and if you like it, i wll make the PR.

Do you agree in proceed on this way?

Regards.

@pichouk
Copy link
Contributor

pichouk commented Dec 17, 2017

LGTM, thanks a lot :)
@joserprieto I'm okay to do it this way !

@joserprieto
Copy link
Author

But, this PR is still open?
Why?

@pichouk
Copy link
Contributor

pichouk commented Feb 2, 2018

@joserprieto You proposed to submit a PR to Mattermost documentation before merging this one.

@joserprieto
Copy link
Author

Ah, ok.
I'll try to do it this weekend

@mattermod
Copy link
Contributor

This issue has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @hanzei

@hanzei
Copy link

hanzei commented Mar 12, 2019

Hey @pichouk,

What is the status of this PR? Can it be merged after it has been synced with master?

Would you help with the changes required in the docs?

@pichouk
Copy link
Contributor

pichouk commented Mar 12, 2019

We are dropping the support of the docker-compose.yml file so I guess we can close this PR.

@pichouk pichouk closed this Mar 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2: Dev Review Requires review by a core committer Awaiting Submitter Action Blocked on the author Enhancement Lifecycle/1:stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants