From 0959197bcd18d38ce7ed2576d0ca3ecc103b1852 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?PICHOU=20Ky=C3=A2ne?= <kyane@kyane.fr>
Date: Sat, 15 Sep 2018 13:44:18 +0200
Subject: [PATCH] Upgrade mattermost

---
 mattermost/.travis.yml                        |  2 +-
 mattermost/MAINTENANCE.md                     | 48 +++++++++----------
 mattermost/README.md                          | 32 ++++++++++---
 mattermost/app/Dockerfile                     | 18 ++++---
 mattermost/app/entrypoint.sh                  |  7 +--
 mattermost/contrib/aws/Dockerrun.aws.json     | 10 ++++
 .../kubernetes/mattermost.deployment.yaml     |  2 +-
 .../contrib/swarm/docker-stack-traefik.yml    |  1 +
 mattermost/contrib/swarm/docker-stack.yml     |  1 +
 mattermost/docker-compose.yml                 |  3 +-
 10 files changed, 78 insertions(+), 46 deletions(-)

diff --git a/mattermost/.travis.yml b/mattermost/.travis.yml
index ae6637a5..245d56e1 100644
--- a/mattermost/.travis.yml
+++ b/mattermost/.travis.yml
@@ -12,7 +12,7 @@ install:
     - sleep 30
 
 env:
-    - BUILD="mkdir -p ./volumes/app/mattermost/{data,logs,config} && docker-compose up -d"
+    - BUILD="mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins} && docker-compose up -d"
     - BUILD="docker run -d --name db -e POSTGRES_USER=mmuser -e POSTGRES_PASSWORD=mmuser_password -e POSTGRES_DB=mattermost mattermost-prod-db && sleep 5 && docker run -d --link db -p 80:8000 --name app mattermost-prod-app"
 
 script:
diff --git a/mattermost/MAINTENANCE.md b/mattermost/MAINTENANCE.md
index 3de6d033..c07a72a9 100644
--- a/mattermost/MAINTENANCE.md
+++ b/mattermost/MAINTENANCE.md
@@ -1,67 +1,67 @@
-# Maintainer Guide 
+# Maintainer Guide
 
-This file outlines the current maintainer(s) of this open source project and expectations. It also includes credits to past maintainers and the project creator. 
+This file outlines the current maintainer(s) of this open source project and expectations. It also includes credits to past maintainers and the project creator.
 
-## Project Name 
+## Project Name
 
-When reference externally, please use this for the short name: 
+When reference externally, please use this for the short name:
 
-- Production Docker deployment for Mattermost 
+- Production Docker deployment for Mattermost
 
-Please use this long name: 
+Please use this long name:
 
 - Production Docker deployment for Mattermost by the Mattermost open source project
 
 ## Maintainer(s)
 
-The following people help to maintain this open source project: 
+The following people help to maintain this open source project:
 
-| Current Maintainer(s)  | Start Date    | 
+| Current Maintainer(s)  | Start Date    |
 |:-----------------------|:--------------|
 | Pan Luo - @xcompass    | Nov 30 2015   |
 | Kyâne Pichou - @pichouk| Jun 01 2017   |
 
-In case something happens where no maintainers are able to complete their responsibilies, the following sponsoring organization can help find a new maintainer: 
+In case something happens where no maintainers are able to complete their responsibilies, the following sponsoring organization can help find a new maintainer:
 
-| Sponsoring Organization        | Start Date    | 
+| Sponsoring Organization        | Start Date    |
 |:-------------------------------|:--------------|
 | Mattermost Open Source Project | Dec 04 2016   |
 
 
 ## Activities
 
-The following is a guide for current, new maintainers and prospective maintainers of this open source project to get started and to understand on-going responsibilities: 
+The following is a guide for current, new maintainers and prospective maintainers of this open source project to get started and to understand on-going responsibilities:
 
-### Getting Started 
+### Getting Started
 
-The following steps should be completed by a new maintainer 
+The following steps should be completed by a new maintainer
 
-1. **Add your name** - Create a pull request to add your name, GitHub username and start date to this document. 
+1. **Add your name** - Create a pull request to add your name, GitHub username and start date to this document.
 2. **Subscribe to mailing lists** - To be notified of new releases and security updates of Mattermost, subscribe to the [Mattermost Security Update Mailing List](http://mattermost.us11.list-manage.com/subscribe?u=6cdba22349ae374e188e7ab8e&id=3a93eb6929) and the [Mattermost Insiders Newsletter](http://mattermost.us11.list-manage.com/subscribe?u=6cdba22349ae374e188e7ab8e&id=2add1c8034)
 
-### Updating 
+### Updating
 
-When receive a mailing list email about a new security update or major version of Mattermost being released, update the version number of this project by doing the following: 
+When receive a mailing list email about a new security update or major version of Mattermost being released, update the version number of this project by doing the following:
 
 In the **master branch**
 
-- Change the [version number](https://github.com/mattermost/mattermost-docker/blob/master/app/Dockerfile#L6) to the latest release 
-- Tag the repo 
+- Change the [version number](https://github.com/mattermost/mattermost-docker/blob/master/app/Dockerfile#L6) to the latest release
+- Tag the repo
 
-### Issue and Pull Request Review 
+### Issue and Pull Request Review
 
-Maintainer(s) should periodically review pull requests and issues submitted to provide feedback and to merge pull request changes when the maintainer feels the change would be appropriate. 
+Maintainer(s) should periodically review pull requests and issues submitted to provide feedback and to merge pull request changes when the maintainer feels the change would be appropriate.
 
-## Credits 
+## Credits
 
-PREVIOUS MAINTAINERS 
+PREVIOUS MAINTAINERS
 
 | Maintainer             | Start Date    | End Date    |
 |:-----------------------|:--------------|:------------|
-| Yi EungJun - @npcode   | Nov 26 2015   | Nov 30 2016 | 
+| Yi EungJun - @npcode   | Nov 26 2015   | Nov 30 2016 |
 
 
-CREATOR 
+CREATOR
 
 | Creator                | Created Date  |
 |:-----------------------|:--------------|
diff --git a/mattermost/README.md b/mattermost/README.md
index c8a1e6cb..fb80b048 100644
--- a/mattermost/README.md
+++ b/mattermost/README.md
@@ -17,7 +17,7 @@ The following instructions deploy Mattermost in a production configuration using
 ### Requirements
 
 * [docker] (version `1.12+`)
-* [docker-compose] (version `1.10.0+` to support Compose file version `3.0`) 
+* [docker-compose] (version `1.10.0+` to support Compose file version `3.0`)
 
 ### Choose Edition to Install
 
@@ -73,6 +73,26 @@ If you choose to use MySQL instead of PostgreSQL, you should set a different dat
 * `MM_SQLSETTINGS_DATASOURCE` : `MM_USERNAME:MM_PASSWORD@tcp(DB_HOST:DB_PORT_NUMBER)/MM_DBNAME?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s`
 Don't forget to replace all entries (beginning by `MM_` and `DB_`) in `MM_SQLSETTINGS_DATASOURCE` with the real variables values.
 
+If you want to push Mattermost application to **Cloud Foundry**, use a `manifest.yml` like this one (with external PostgreSQL service):
+
+```
+---
+applications:
+- name: mattermost
+  docker:
+    image: mattermost/mattermost-prod-app
+  instances: 1
+  memory: 1G
+  disk_quota: 256M
+  env:
+    DB_HOST: database host address
+    DB_PORT_NUMBER: database port
+    MM_DBNAME: database name
+    MM_USERNAME: database username
+    MM_PASSWORD: database password
+
+```
+
 ### Web server container
 This image is optional, you should **not** use it when you have your own reverse-proxy. It is a simple front Web server for the Mattermost app container. If you use the provided `docker-compose.yml` file, you don't have to configure anything. But if your application container is reachable on custom host and/or port (eg. if you use a container provider), you should add those two environment variables :
 * `APP_HOST`: application host address
@@ -88,7 +108,7 @@ them you may generate a self-signed SSL certificate.
 #### Start
 If you are running docker with non root user, make sure the UID and GID in app/Dockerfile are the same as your current UID/GID
 ```
-mkdir -p ./volumes/app/mattermost/{data,logs,config}
+mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins}
 chown -R 2000:2000 ./volumes/app/mattermost/
 docker-compose start
 ```
@@ -134,15 +154,15 @@ Your Docker image should now be on the latest Mattermost version.
 ## Upgrading Mattermost to 4.9+
 
 Docker images for `4.9.0` release introduce some important changes from [PR #241](https://github.com/mattermost/mattermost-docker/pull/241) to improve production use of Mattermost with Docker.
-**There are 2 important changes for existing installations**  
+**There are 2 important changes for existing installations**
 
 One important change is that we don't use `root` user by default to run the Mattermost application. So, as explained on [the README](https://github.com/mattermost/mattermost-docker#start), if you use host mounted volume you have to be sure that files on your host server have the correct UID/GID (by default those values are `2000`). In practice, you should just run following commands :
 ```
-mkdir -p ./volumes/app/mattermost/{data,logs,config}
+mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins}
 chown -R 2000:2000 ./volumes/app/mattermost/
 ```
 
-The second important change is the port used by Mattermost application container. The default port is now `8000`, and existing installations that use port `80` will not work without a little configuration change. You have to open your Mattermost configuration file (`./volumes/app/mattermost/config/config.json` by default) and change the key `ServiceSettings.ListenAddress` to `:8000`.  
+The second important change is the port used by Mattermost application container. The default port is now `8000`, and existing installations that use port `80` will not work without a little configuration change. You have to open your Mattermost configuration file (`./volumes/app/mattermost/config/config.json` by default) and change the key `ServiceSettings.ListenAddress` to `:8000`.
 Also if you use your own web-server/reverse-proxy you need to change its configuration to reach port `8000` of the Mattermost container.
 
 
@@ -171,7 +191,7 @@ Running containerized applications on multi-node swarms involves specific data p
 
 First, create mattermost directory structure on the docker hosts:
 ```
-mkdir -p /var/lib/mattermost/{cert,config,data,logs}
+mkdir -p /var/lib/mattermost/{cert,config,data,logs,plugins}
 ```
 
 Then, fire up the stack in your swarm:
diff --git a/mattermost/app/Dockerfile b/mattermost/app/Dockerfile
index 133269ee..103c3f34 100644
--- a/mattermost/app/Dockerfile
+++ b/mattermost/app/Dockerfile
@@ -1,8 +1,8 @@
-FROM alpine:3.6
+FROM alpine:3.8
 
 # Some ENV variables
 ENV PATH="/mattermost/bin:${PATH}"
-ENV MM_VERSION=4.10.0
+ENV MM_VERSION=5.3.0
 
 # Build argument to set Mattermost edition
 ARG edition=enterprise
@@ -28,14 +28,12 @@ RUN mkdir -p /mattermost/data \
     && if [ "$edition" = "team" ] ; then curl https://releases.mattermost.com/$MM_VERSION/mattermost-team-$MM_VERSION-linux-amd64.tar.gz | tar -xvz ; \
       else curl https://releases.mattermost.com/$MM_VERSION/mattermost-$MM_VERSION-linux-amd64.tar.gz | tar -xvz ; fi \
     && cp /mattermost/config/config.json /config.json.save \
-    && rm -rf /mattermost/config/config.json
-
-# Get ready for production
-RUN addgroup -g ${PGID} mattermost \
+    && rm -rf /mattermost/config/config.json \
+    && addgroup -g ${PGID} mattermost \
     && adduser -D -u ${PUID} -G mattermost -h /mattermost -D mattermost \
-    && chown -R mattermost:mattermost /mattermost /config.json.save 
+    && chown -R mattermost:mattermost /mattermost /config.json.save
 
-USER mattermost 
+USER mattermost
 
 #Healthcheck to make sure container is ready
 HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1
@@ -44,10 +42,10 @@ HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1
 COPY entrypoint.sh /
 ENTRYPOINT ["/entrypoint.sh"]
 WORKDIR /mattermost
-CMD ["platform"]
+CMD ["mattermost"]
 
 # Expose port 8000 of the container
 EXPOSE 8000
 
 # Declare volumes for mount point directories
-VOLUME ["/mattermost/data", "/mattermost/logs", "/mattermost/config"]
+VOLUME ["/mattermost/data", "/mattermost/logs", "/mattermost/config", "/mattermost/plugins"]
diff --git a/mattermost/app/entrypoint.sh b/mattermost/app/entrypoint.sh
index 99a2dfef..3b4d8055 100755
--- a/mattermost/app/entrypoint.sh
+++ b/mattermost/app/entrypoint.sh
@@ -14,10 +14,10 @@ MM_DBNAME=${MM_DBNAME:-mattermost}
 MM_CONFIG=${MM_CONFIG:-/mattermost/config/config.json}
 
 if [ "${1:0:1}" = '-' ]; then
-    set -- platform "$@"
+    set -- mattermost "$@"
 fi
 
-if [ "$1" = 'platform' ]; then
+if [ "$1" = 'mattermost' ]; then
   # Check CLI args for a -config option
   for ARG in $@;
   do
@@ -50,6 +50,7 @@ if [ "$1" = 'platform' ]; then
     jq '.RateLimitSettings.Enable = true' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
     jq '.SqlSettings.DriverName = "postgres"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
     jq '.SqlSettings.AtRestEncryptKey = "'$(generate_salt)'"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
+    jq '.PluginSettings.Directory = "/mattermost/plugins/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
   else
     echo "Using existing config file" $MM_CONFIG
   fi
@@ -77,7 +78,7 @@ if [ "$1" = 'platform' ]; then
   # Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
   sleep 1
 
-  echo "Starting platform"
+  echo "Starting mattermost"
 fi
 
 exec "$@"
diff --git a/mattermost/contrib/aws/Dockerrun.aws.json b/mattermost/contrib/aws/Dockerrun.aws.json
index 1a3da28e..7b1575c8 100644
--- a/mattermost/contrib/aws/Dockerrun.aws.json
+++ b/mattermost/contrib/aws/Dockerrun.aws.json
@@ -19,6 +19,12 @@
                 "sourcePath": "/var/app/current/app/mattermost/logs"
             }
         },
+        {
+            "name": "app-plugins",
+            "host": {
+                "sourcePath": "/var/app/current/app/mattermost/plugins"
+            }
+        },
         {
             "name": "db-data",
             "host": {
@@ -72,6 +78,10 @@
                 {
                     "sourceVolume": "app-logs",
                     "containerPath": "/mattermost/logs"
+                },
+                {
+                    "sourceVolume": "app-plugins",
+                    "containerPath": "/mattermost/plugins"
                 }
             ],
             "links": [
diff --git a/mattermost/contrib/kubernetes/mattermost.deployment.yaml b/mattermost/contrib/kubernetes/mattermost.deployment.yaml
index 7fc93842..534ac16f 100644
--- a/mattermost/contrib/kubernetes/mattermost.deployment.yaml
+++ b/mattermost/contrib/kubernetes/mattermost.deployment.yaml
@@ -17,7 +17,7 @@ spec:
     spec:
       containers:
       - name: mattermost-app
-        image: "mattermost/mattermost-prod-app:4.7.0"
+        image: "mattermost/mattermost-prod-app:5.3.0"
         env:
         - name: DB_HOST
           valueFrom:
diff --git a/mattermost/contrib/swarm/docker-stack-traefik.yml b/mattermost/contrib/swarm/docker-stack-traefik.yml
index e0ce995b..d8714652 100644
--- a/mattermost/contrib/swarm/docker-stack-traefik.yml
+++ b/mattermost/contrib/swarm/docker-stack-traefik.yml
@@ -67,6 +67,7 @@ services:
       - /var/lib/mattermost/config:/mattermost/config:rw
       - /var/lib/mattermost/data:/mattermost/data:rw
       - /var/lib/mattermost/logs:/mattermost/logs:rw
+      - /var/lib/mattermost/plugins:/mattermost/plugins:rw
       - /etc/localtime:/etc/localtime:ro
     environment:
       # use service's hostname
diff --git a/mattermost/contrib/swarm/docker-stack.yml b/mattermost/contrib/swarm/docker-stack.yml
index 883c3388..025629ea 100644
--- a/mattermost/contrib/swarm/docker-stack.yml
+++ b/mattermost/contrib/swarm/docker-stack.yml
@@ -66,6 +66,7 @@ services:
       - /var/lib/mattermost/config:/mattermost/config:rw
       - /var/lib/mattermost/data:/mattermost/data:rw
       - /var/lib/mattermost/logs:/mattermost/logs:rw
+      - /var/lib/mattermost/plugins:/mattermost/plugins:rw
       - /etc/localtime:/etc/localtime:ro
     environment:
       # use service's hostname
diff --git a/mattermost/docker-compose.yml b/mattermost/docker-compose.yml
index 65c72c65..c694117f 100644
--- a/mattermost/docker-compose.yml
+++ b/mattermost/docker-compose.yml
@@ -22,7 +22,7 @@ services:
   app:
     build:
       context: app
-      # comment out following lines for team edition or change UID/GID
+      # uncomment following lines for team edition or change UID/GID
       args:
         - edition=team
       #   - PUID=1000
@@ -32,6 +32,7 @@ services:
       - ./volumes/app/mattermost/config:/mattermost/config:rw
       - ./volumes/app/mattermost/data:/mattermost/data:rw
       - ./volumes/app/mattermost/logs:/mattermost/logs:rw
+      - ./volumes/app/mattermost/plugins:/mattermost/plugins:rw
       - /etc/localtime:/etc/localtime:ro
     environment:
       # set same as db credentials and dbname
-- 
GitLab