From f59afaede5c5c24bb896967fbd81e7e6f80c6cde Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?PICHOU=20Ky=C3=A2ne?= <kyane.pichou@etu.utc.fr>
Date: Tue, 21 Mar 2017 23:17:08 +0100
Subject: [PATCH] Update mattermost to 3.7.1

---
 mattermost/.gitignore                |  8 +++
 mattermost/.travis.yml               |  2 +-
 mattermost/MAINTENANCE.md            | 72 ++++++++++++++++++++++
 mattermost/README.md                 | 90 +++++++++++++++++++++-------
 mattermost/app/Dockerfile            | 11 +++-
 mattermost/app/Dockerfile-enterprise | 24 ++++++++
 mattermost/app/docker-entry.sh       | 62 ++++++++++++-------
 mattermost/db/Dockerfile             |  3 +-
 mattermost/db/make_db.sh             | 12 ----
 mattermost/db/setup-wale.sh          |  0
 mattermost/docker-compose-v1.yml     | 31 ++++++----
 mattermost/docker-compose.yml        | 34 +++++++----
 mattermost/web/Dockerfile            | 23 ++-----
 mattermost/web/docker-entry.sh       | 12 ++--
 mattermost/web/mattermost            |  2 +-
 mattermost/web/mattermost-ssl        |  2 +-
 16 files changed, 281 insertions(+), 107 deletions(-)
 create mode 100644 mattermost/.gitignore
 create mode 100644 mattermost/MAINTENANCE.md
 create mode 100644 mattermost/app/Dockerfile-enterprise
 delete mode 100644 mattermost/db/make_db.sh
 mode change 100644 => 100755 mattermost/db/setup-wale.sh

diff --git a/mattermost/.gitignore b/mattermost/.gitignore
new file mode 100644
index 00000000..5bed12fc
--- /dev/null
+++ b/mattermost/.gitignore
@@ -0,0 +1,8 @@
+
+# Elastic Beanstalk Files
+.elasticbeanstalk/*
+!.elasticbeanstalk/*.cfg.yml
+!.elasticbeanstalk/*.global.yml
+
+# Generated data
+volumes
diff --git a/mattermost/.travis.yml b/mattermost/.travis.yml
index 04ced962..e974eab6 100644
--- a/mattermost/.travis.yml
+++ b/mattermost/.travis.yml
@@ -13,7 +13,7 @@ install:
 
 env:
     - BUILD="docker-compose up -d"
-    - BUILD="docker run -d --name db mattermost-prod-db && sleep 5 && docker run -d --link db -p 80:80 --name app mattermost-prod-app"
+    - 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:80 --name app mattermost-prod-app"
 
 script:
     - curl -sSf http://localhost > /dev/null
diff --git a/mattermost/MAINTENANCE.md b/mattermost/MAINTENANCE.md
new file mode 100644
index 00000000..f47c3c31
--- /dev/null
+++ b/mattermost/MAINTENANCE.md
@@ -0,0 +1,72 @@
+# 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. 
+
+## Project Name 
+
+When reference externally, please use this for the short name: 
+
+- Production Docker deployment for Mattermost 
+
+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: 
+
+| Current Maintainer(s)  | Start Date    | 
+|:-----------------------|:--------------|
+| Pan Luo - @xcompass    | Nov 30 2015   |
+
+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    | 
+|:-------------------------------|:--------------|
+| 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: 
+
+### Getting Started 
+
+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. 
+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 
+
+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: 
+
+1) 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 
+
+2) In the **team-and-enterprise branch**
+
+- Change the [version number](https://github.com/mattermost/mattermost-docker/blob/team-and-enterprise/app/Dockerfile#L6) to the latest release 
+
+### 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. 
+
+## Credits 
+
+PREVIOUS MAINTAINERS 
+
+| Maintainer             | Start Date    | End Date    |
+|:-----------------------|:--------------|:------------|
+| Yi EungJun - @npcode   | Nov 26 2015   | Nov 30 2016 | 
+
+
+CREATOR 
+
+| Creator                | Created Date  |
+|:-----------------------|:--------------|
+| Yi EungJun - @npcode   | Nov 26 2015   |
+
diff --git a/mattermost/README.md b/mattermost/README.md
index aabbb247..441626c6 100644
--- a/mattermost/README.md
+++ b/mattermost/README.md
@@ -1,49 +1,60 @@
-Dockerfiles for Mattermost in production
+# Production Docker deployment for Mattermost
 
-See [README.aws.md](./README.aws.md) if you want to install it on AWS Elastic Beanstalk.
+This project enables deployment of a Mattermost server in a multi-node production configuration using Docker.
 
 [![Build Status](https://travis-ci.org/mattermost/mattermost-docker.svg?branch=master)](https://travis-ci.org/mattermost/mattermost-docker)
 
-## Requirements
+Notes:
+- The default Mattermost edition for this repo has changed from team edition to enterprise edition. Please see [Choose Edition](#choose-edition-to-install) section.
+- To install this Docker project on AWS Elastic Beanstalk please see [AWS Elastic Beanstalk Guide](./README.aws.md).
+- To install Mattermost without Docker directly onto a Linux-based operating systems, please see [Admin Guide](https://docs.mattermost.com/guides/administrator.html#installing-mattermost).
+
+## Installation using Docker Compose
+
+The following instructions deploy Mattermost in a production configuration using multi-node Docker Compose set up.
+
+### Requirements
 
 * [docker]
 * [docker-compose]
 
-## Installation
+### Choose Edition to Install
 
-### Install with SSL certificate
+If you want to install enterprise edition, you can skip this section.
 
-1. Open docker-compose.yml and set `MATTERMOST_ENABLE_SSL` to true.
+To install the team edition, comment out the following line in docker-compose.yaml file:
 
     ```
-    environment:
-      - MATTERMOST_ENABLE_SSL=true
+    dockerfile: Dockerfile-enterprise
     ```
 
-2. Put your SSL certificate as `./volumes/web/cert/cert.pem` and the private key that has
+### Database
+
+Make sure to set the appropriate values for `MM_USERNAME`, `MM_PASSWORD` and `MM_DBNAME`.
+
+### Install with SSL certificate
+
+1. Put your SSL certificate as `./volumes/web/cert/cert.pem` and the private key that has
    no password as `./volumes/web/cert/key-no-password.pem`. If you don't have
    them you may generate a self-signed SSL certificate.
 
-3. Build and run mattermost
+2. Build and run mattermost
 
+    ```
     docker-compose up -d
+    ```
 
-4. Open `https://your.domain` with your web browser.
+3. Open `https://your.domain` with your web browser.
 
 ### Install without SSL certificate
 
-1. Open docker-compose.yml and set `MATTERMOST_ENABLE_SSL` to false.
+1. Build and run mattermost
 
     ```
-    environment:
-      - MATTERMOST_ENABLE_SSL=false
-    ```
-    
-2. Build and run mattermost
-
     docker-compose up -d
+    ```
 
-3. Open `http://your.domain` with your web browser.
+2. Open `http://your.domain` with your web browser.
 
 ## Starting/Stopping
 
@@ -55,6 +66,15 @@ See [README.aws.md](./README.aws.md) if you want to install it on AWS Elastic Be
 
     docker-compose stop
 
+### Update
+
+Make sure to backup Mattermost data before proceeding.
+
+    docker-compose down
+    git pull
+    docker-compose build
+    docker-compose up -d
+
 ## Removing
 
 ### Remove the containers
@@ -90,6 +110,34 @@ docker exec mattermost-db su - postgres sh -c "/usr/bin/envdir /etc/wal-e.d/env
 ```
 Those tasks can be executed through a cron job or systemd timer.
 
+## Customization
+
+Customization can be done through environment variables.
+
+### Mattermost App Image
+
+* MM_USERNAME: database username, must be the same as one in DB image
+* MM_PASSWORD: database password, must be the same as one in DB image
+* MM_DBNAME: database name, must be the same as one in DB image
+* DB_HOST: database host address
+* DB_PORT_5432_TCP_PORT: database port
+* MM_CONFIG: configuration file location. It can be used when config is mounted in a different location.
+
+### Mattermost DB Image
+
+* MM_USERNAME: database username, must be the same as on in App image
+* MM_PASSWORD: database password, must be the same as on in App image
+* MM_DBNAME: database name, must be the same as on in App image
+* AWS_ACCESS_KEY_ID: aws access key, used for db backup
+* AWS_SECRET_ACCESS_KEY: aws secret, used for db backup
+* WALE_S3_PREFIX: aws s3 bucket name, used for db backup
+* AWS_REGION: aws region, used for db backup
+
+### Mattermost Web Image
+
+* MATTERMOST_ENABLE_SSL: whether to enable SSL
+* PLATFORM_PORT_80_TCP_PORT: port that Mattermost image is listening on
+
 ## Upgrading to Team Edition 3.0.x from 2.x
 
 You need to migrate your database before upgrading mattermost to 3.0.x from
@@ -108,7 +156,7 @@ See the [offical Upgrade Guide](http://docs.mattermost.com/administration/upgrad
 * Rarely 'app' container fails to start because of "connection refused" to
   database. Workaround: Restart the container.
 
-## More informations
+## More information
 
 If you want to know how to use docker-compose, see [the overview
 page](https://docs.docker.com/compose).
@@ -119,4 +167,4 @@ For the server configurations, see [prod-ubuntu.rst] of mattermost.
 
 [docker]: http://docs.docker.com/engine/installation/
 [docker-compose]: https://docs.docker.com/compose/install/
-[prod-ubuntu.rst]: https://github.com/mattermost/docs/blob/master/source/install/prod-ubuntu.rst
+[prod-ubuntu.rst]: https://docs.mattermost.com/install/install-ubuntu-1404.html
diff --git a/mattermost/app/Dockerfile b/mattermost/app/Dockerfile
index 3732032c..51c8cc39 100644
--- a/mattermost/app/Dockerfile
+++ b/mattermost/app/Dockerfile
@@ -1,9 +1,13 @@
 FROM ubuntu:14.04
 
+ENV PATH="/mattermost/bin:${PATH}"
+
 RUN apt-get update && apt-get -y install curl netcat
 RUN mkdir -p /mattermost/data
 
-RUN curl https://releases.mattermost.com/3.6.1/mattermost-team-3.6.1-linux-amd64.tar.gz | tar -xvz
+ENV MM_VERSION=3.7.2
+
+RUN curl https://releases.mattermost.com/$MM_VERSION/mattermost-team-$MM_VERSION-linux-amd64.tar.gz | tar -xvz
 
 RUN rm /mattermost/config/config.json
 COPY config.template.json /
@@ -13,3 +17,8 @@ RUN chmod +x /docker-entry.sh
 ENTRYPOINT ["/docker-entry.sh"]
 
 EXPOSE 80
+
+VOLUME /mattermost/data
+
+WORKDIR /mattermost/bin
+CMD ["platform"]
diff --git a/mattermost/app/Dockerfile-enterprise b/mattermost/app/Dockerfile-enterprise
new file mode 100644
index 00000000..b52e046e
--- /dev/null
+++ b/mattermost/app/Dockerfile-enterprise
@@ -0,0 +1,24 @@
+FROM ubuntu:14.04
+
+ENV PATH="/mattermost/bin:${PATH}"
+
+RUN apt-get update && apt-get -y install curl netcat
+RUN mkdir -p /mattermost/data
+
+ENV MM_VERSION=3.7.1
+
+RUN curl https://releases.mattermost.com/$MM_VERSION/mattermost-$MM_VERSION-linux-amd64.tar.gz | tar -xvz
+
+RUN rm /mattermost/config/config.json
+COPY config.template.json /
+
+COPY docker-entry.sh /
+RUN chmod +x /docker-entry.sh
+ENTRYPOINT ["/docker-entry.sh"]
+
+EXPOSE 80
+
+VOLUME /mattermost/data
+
+WORKDIR /mattermost/bin
+CMD ["platform"]
diff --git a/mattermost/app/docker-entry.sh b/mattermost/app/docker-entry.sh
index 27efe2e4..7a78314e 100644
--- a/mattermost/app/docker-entry.sh
+++ b/mattermost/app/docker-entry.sh
@@ -1,33 +1,51 @@
 #!/bin/bash
-config=/mattermost/config/config.json
+
 DB_HOST=${DB_HOST:-db}
 DB_PORT_5432_TCP_PORT=${DB_PORT_5432_TCP_PORT:-5432}
 MM_USERNAME=${MM_USERNAME:-mmuser}
 MM_PASSWORD=${MM_PASSWORD:-mmuser_password}
 MM_DBNAME=${MM_DBNAME:-mattermost}
-echo -ne "Configure database connection..."
-if [ ! -f $config ]
-then
-    cp /config.template.json $config
-    sed -Ei "s/DB_HOST/$DB_HOST/" $config
-    sed -Ei "s/DB_PORT/$DB_PORT_5432_TCP_PORT/" $config
-    sed -Ei "s/MM_USERNAME/$MM_USERNAME/" $config
-    sed -Ei "s/MM_PASSWORD/$MM_PASSWORD/" $config
-    sed -Ei "s/MM_DBNAME/$MM_DBNAME/" $config
-    echo OK
-else
-    echo SKIP
+MM_CONFIG=/mattermost/config/config.json
+
+if [ "${1:0:1}" = '-' ]; then
+    set -- platform "$@"
 fi
 
-echo "Wait until database $DB_HOST:$DB_PORT_5432_TCP_PORT is ready..."
-until nc -z $DB_HOST $DB_PORT_5432_TCP_PORT
-do
+if [ "$1" = 'platform' ]; then
+    for ARG in $@;
+    do
+        case "$ARG" in
+            -config=*)
+                MM_CONFIG=${ARG#*=};;
+        esac
+    done
+
+    echo "Using config file" $MM_CONFIG
+
+    echo -ne "Configure database connection..."
+    if [ ! -f $MM_CONFIG ]
+    then
+        cp /config.template.json $MM_CONFIG
+        sed -Ei "s/DB_HOST/$DB_HOST/" $MM_CONFIG
+        sed -Ei "s/DB_PORT/$DB_PORT_5432_TCP_PORT/" $MM_CONFIG
+        sed -Ei "s/MM_USERNAME/$MM_USERNAME/" $MM_CONFIG
+        sed -Ei "s/MM_PASSWORD/$MM_PASSWORD/" $MM_CONFIG
+        sed -Ei "s/MM_DBNAME/$MM_DBNAME/" $MM_CONFIG
+        echo OK
+    else
+        echo SKIP
+    fi
+
+    echo "Wait until database $DB_HOST:$DB_PORT_5432_TCP_PORT is ready..."
+    until nc -z $DB_HOST $DB_PORT_5432_TCP_PORT
+    do
+        sleep 1
+    done
+
+    # Wait to avoid "panic: Failed to open sql connection pq: the database system is starting up"
     sleep 1
-done
 
-# Wait to avoid "panic: Failed to open sql connection pq: the database system is starting up"
-sleep 1
+    echo "Starting platform"
+fi
 
-echo "Starting platform"
-cd /mattermost/bin
-./platform $*
+exec "$@"
diff --git a/mattermost/db/Dockerfile b/mattermost/db/Dockerfile
index c35098d3..4d707d28 100644
--- a/mattermost/db/Dockerfile
+++ b/mattermost/db/Dockerfile
@@ -9,8 +9,7 @@ RUN apt-get update \
     && apt-get clean \
     && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
-ADD make_db.sh /docker-entrypoint-initdb.d/
-ADD setup-wale.sh /docker-entrypoint-initdb.d/
+COPY setup-wale.sh /docker-entrypoint-initdb.d/
 COPY docker-entrypoint1.sh /
 RUN chmod +x /docker-entrypoint1.sh
 
diff --git a/mattermost/db/make_db.sh b/mattermost/db/make_db.sh
deleted file mode 100644
index b1059605..00000000
--- a/mattermost/db/make_db.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-set -e
-
-MM_USERNAME=${MM_USERNAME:-mmuser}
-MM_PASSWORD=${MM_PASSWORD:-mmuser_password}
-MM_DBNAME=${MM_DBNAME:-mattermost}
-
-psql -v ON_ERROR_STOP=1 --username "postgres" <<- EOSQL
-    CREATE DATABASE $MM_DBNAME;
-    CREATE USER $MM_USERNAME WITH PASSWORD '$MM_PASSWORD';
-    GRANT ALL PRIVILEGES ON DATABASE $MM_DBNAME to $MM_USERNAME;
-EOSQL
diff --git a/mattermost/db/setup-wale.sh b/mattermost/db/setup-wale.sh
old mode 100644
new mode 100755
diff --git a/mattermost/docker-compose-v1.yml b/mattermost/docker-compose-v1.yml
index e01768a6..4f45ceef 100644
--- a/mattermost/docker-compose-v1.yml
+++ b/mattermost/docker-compose-v1.yml
@@ -1,27 +1,39 @@
 db:
   build: db
-  restart: always
+  restart: unless-stopped
   volumes:
     - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
     - /etc/localtime:/etc/localtime:ro
-  # uncomment the following to enable backup
   environment:
-    - MM_USERNAME=mmuser
-    - MM_PASSWORD=mmuser_password
-    - MM_DBNAME=mattermost
+    - POSTGRES_USER=mmuser
+    - POSTGRES_PASSWORD=mmuser_password
+    - POSTGRES_DB=mattermost
+  # uncomment the following to enable backup
   #  - AWS_ACCESS_KEY_ID=XXXX
   #  - AWS_SECRET_ACCESS_KEY=XXXX
   #  - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
   #  - AWS_REGION=us-east-1
+  #  in case your config is not in default location
+  #  - MM_CONFIG=/mattermost/config/config.jso
 app:
-  build: app
+  build:
+    context: app
+    # comment out for team version
+    dockerfile: Dockerfile-enterprise
   links:
     - db:db
-  restart: always
+  restart: unless-stopped
   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
+  environment:
+  # set same as db environment
+    - MM_USERNAME=mmuser
+    - MM_PASSWORD=mmuser_password
+    - MM_DBNAME=mattermost
+
 web:
   build: web
   ports:
@@ -29,11 +41,8 @@ web:
     - "443:443"
   links:
     - app:app
-  restart: always
+  restart: unless-stopped
   volumes:
       # This directory must have cert files
     - ./volumes/web/cert:/cert:ro
     - /etc/localtime:/etc/localtime:ro
-  environment:
-    - MATTERMOST_ENABLE_SSL=false
-    - PLATFORM_PORT_80_TCP_PORT=80
diff --git a/mattermost/docker-compose.yml b/mattermost/docker-compose.yml
index 6751bd79..5d1622cd 100644
--- a/mattermost/docker-compose.yml
+++ b/mattermost/docker-compose.yml
@@ -4,38 +4,50 @@ services:
 
   db:
     build: db
-    restart: always
+    restart: unless-stopped
     volumes:
       - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
       - /etc/localtime:/etc/localtime:ro
-    # uncomment the following to enable backup
     environment:
-      - MM_USERNAME=mmuser
-      - MM_PASSWORD=mmuser_password
-      - MM_DBNAME=mattermost
+      - POSTGRES_USER=mmuser
+      - POSTGRES_PASSWORD=mmuser_password
+      - POSTGRES_DB=mattermost
+    # uncomment the following to enable backup
     #  - AWS_ACCESS_KEY_ID=XXXX
     #  - AWS_SECRET_ACCESS_KEY=XXXX
     #  - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
     #  - AWS_REGION=us-east-1
+    #  in case your config is not in default location
+    #  - MM_CONFIG=/mattermost/config/config.jso
 
   app:
-    build: app
-    restart: always
+    build:
+      context: app
+      # comment out for team edition
+      dockerfile: Dockerfile-enterprise
+    restart: unless-stopped
     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
+    environment:
+      # set same as db credentials and dbname
+      - MM_USERNAME=mmuser
+      - MM_PASSWORD=mmuser_password
+      - MM_DBNAME=mattermost
+    depends_on:
+      - db
 
   web:
     build: web
     ports:
       - "80:80"
       - "443:443"
-    restart: always
+    restart: unless-stopped
     volumes:
       # This directory must have cert files
       - ./volumes/web/cert:/cert:ro
       - /etc/localtime:/etc/localtime:ro
-    environment:
-      - MATTERMOST_ENABLE_SSL=false
-      - PLATFORM_PORT_80_TCP_PORT=80
+    depends_on:
+      - app
diff --git a/mattermost/web/Dockerfile b/mattermost/web/Dockerfile
index af26369a..4038b66c 100644
--- a/mattermost/web/Dockerfile
+++ b/mattermost/web/Dockerfile
@@ -1,22 +1,9 @@
-FROM ubuntu:14.04
+FROM nginx:mainline
 
-RUN apt-get update && apt-get install -y nginx
-
-RUN rm /etc/nginx/sites-enabled/default
-
-COPY mattermost /etc/nginx/sites-available/
-COPY mattermost-ssl /etc/nginx/sites-available/
-ADD docker-entry.sh /
+RUN rm /etc/nginx/conf.d/default.conf
+COPY ./mattermost /etc/nginx/sites-available/
+COPY ./mattermost-ssl /etc/nginx/sites-available/
 
+COPY docker-entry.sh /
 RUN chmod +x /docker-entry.sh
-
-# You can see the logs using `docker-compose logs web`.
-RUN ln -sf /dev/stdout /var/log/nginx/access.log
-RUN ln -sf /dev/stderr /var/log/nginx/error.log
-
-# Define working directory.
-WORKDIR /etc/nginx
-
 ENTRYPOINT /docker-entry.sh
-
-EXPOSE 80 443
diff --git a/mattermost/web/docker-entry.sh b/mattermost/web/docker-entry.sh
index 4f90a5b4..17b76efb 100644
--- a/mattermost/web/docker-entry.sh
+++ b/mattermost/web/docker-entry.sh
@@ -1,9 +1,9 @@
 #!/bin/bash
-echo Starting Nginx
-sed -Ei "s/APP_PORT/$PLATFORM_PORT_80_TCP_PORT/" /etc/nginx/sites-available/mattermost
-sed -Ei "s/APP_PORT/$PLATFORM_PORT_80_TCP_PORT/" /etc/nginx/sites-available/mattermost-ssl
-if [ "$MATTERMOST_ENABLE_SSL" = true ]; then
-    ssl="-ssl"
+if [ -f "/cert/cert.pem" -a -f "/cert/key-no-password.pem" ]; then
+  echo "found certificate and key, linking ssl config"
+  ssl="-ssl"
+else
+  echo "linking plain config"
 fi
-ln -s /etc/nginx/sites-available/mattermost$ssl /etc/nginx/sites-enabled/mattermost
+ln -s /etc/nginx/sites-available/mattermost$ssl /etc/nginx/conf.d/mattermost.conf
 nginx -g 'daemon off;'
diff --git a/mattermost/web/mattermost b/mattermost/web/mattermost
index 69a64ec5..0c428acb 100644
--- a/mattermost/web/mattermost
+++ b/mattermost/web/mattermost
@@ -17,6 +17,6 @@ server {
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
         proxy_set_header X-Frame-Options SAMEORIGIN;
-        proxy_pass http://app:APP_PORT;
+        proxy_pass http://app:80;
     }
 }
diff --git a/mattermost/web/mattermost-ssl b/mattermost/web/mattermost-ssl
index ac28a9b5..101ab2e1 100644
--- a/mattermost/web/mattermost-ssl
+++ b/mattermost/web/mattermost-ssl
@@ -32,7 +32,7 @@ server {
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
         proxy_set_header X-Frame-Options SAMEORIGIN;
-        proxy_pass http://app:APP_PORT;
+        proxy_pass http://app:80;
     }
 }
 
-- 
GitLab