diff --git a/.travis.yml b/.travis.yml index bdd6e6c..ae6637a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,13 @@ install: - sleep 30 env: - - BUILD="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:80 --name app mattermost-prod-app" + - BUILD="mkdir -p ./volumes/app/mattermost/{data,logs,config} && 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: - curl -sSf http://localhost > /dev/null + - docker ps -a | grep app | grep healthy + - docker ps -a | grep db | grep healthy after_failure: - timeout 3s docker-compose logs app db web diff --git a/README.md b/README.md index 7368dc8..028215e 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ The following instructions deploy Mattermost in a production configuration using ### Requirements -* [docker] (version `1.10.0+`) -* [docker-compose] (version `1.6.0+` to support Compose file version `2.0`) +* [docker] (version `1.12+`) +* [docker-compose] (version `1.10.0+` to support Compose file version `3.0`) ### Choose Edition to Install @@ -86,7 +86,10 @@ them you may generate a self-signed SSL certificate. ### Starting/Stopping Docker #### 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} +chown -R 2000:2000 ./volumes/app/mattermost/ docker-compose start ``` diff --git a/app/Dockerfile b/app/Dockerfile index 34e1b38..5aedc2e 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -6,6 +6,9 @@ ENV MM_VERSION=4.9.0 # Build argument to set Mattermost edition ARG edition=enterprise +ARG PUID=2000 +ARG PGID=2000 + # Install some needed packages RUN apk add --no-cache \ @@ -27,14 +30,24 @@ RUN mkdir -p /mattermost/data \ && cp /mattermost/config/config.json /config.json.save \ && rm -rf /mattermost/config/config.json +# Get ready for production +RUN addgroup -g ${PGID} mattermost \ + && adduser -D -u ${PUID} -G mattermost -h /mattermost -D mattermost \ + && chown -R mattermost:mattermost /mattermost /config.json.save + +USER mattermost + +#Healthcheck to make sure container is ready +HEALTHCHECK CMD curl --fail http://localhost:8000 || exit 1 + # Configure entrypoint and command COPY entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] WORKDIR /mattermost CMD ["platform"] -# Expose port 80 of the container -EXPOSE 80 +# Expose port 8000 of the container +EXPOSE 8000 -# Use a volume for the data directory -VOLUME /mattermost/data +# Declare volumes for mount point directories +VOLUME ["/mattermost/data", "/mattermost/logs", "/mattermost/config"] diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 293055c..99a2dfe 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -35,7 +35,7 @@ if [ "$1" = 'platform' ]; then # Copy default configuration file cp /config.json.save $MM_CONFIG # Substitue some parameters with jq - jq '.ServiceSettings.ListenAddress = ":80"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG + jq '.ServiceSettings.ListenAddress = ":8000"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG jq '.LogSettings.EnableConsole = false' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG jq '.LogSettings.ConsoleLevel = "INFO"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG jq '.FileSettings.Directory = "/mattermost/data/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG diff --git a/db/Dockerfile b/db/Dockerfile index 40ebe66..37aaeab 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -18,7 +18,12 @@ RUN apk add --no-cache \ # Add wale script COPY setup-wale.sh /docker-entrypoint-initdb.d/ +#Healthcheck to make sure container is ready +HEALTHCHECK CMD pg_isready -U postgres || exit 1 + # Add and configure entrypoint and command COPY entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] CMD ["postgres"] + +VOLUME ["/var/run/postgresql", "/usr/share/postgresql/", "/var/lib/postgresql/data", "/tmp"] diff --git a/docker-compose.yml b/docker-compose.yml index 94ce06a..9ef8936 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: db: build: db + read_only: true restart: unless-stopped volumes: - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data @@ -21,9 +22,11 @@ services: app: build: context: app - # comment out 2 following lines for team edition + # comment out following lines for team edition or change UID/GID # args: # - edition=team + # - PUID=1000 + # - PGID=1000 restart: unless-stopped volumes: - ./volumes/app/mattermost/config:/mattermost/config:rw @@ -43,6 +46,7 @@ services: ports: - "80:80" - "443:443" + read_only: true restart: unless-stopped volumes: # This directory must have cert files if you want to enable SSL diff --git a/web/Dockerfile b/web/Dockerfile index 5a99435..a138e0c 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,11 +1,19 @@ FROM nginx:mainline-alpine # Remove default configuration and add our custom Nginx configuration files -RUN rm /etc/nginx/conf.d/default.conf -COPY ./mattermost /etc/nginx/sites-available/ -COPY ./mattermost-ssl /etc/nginx/sites-available/ +RUN rm /etc/nginx/conf.d/default.conf \ + && apk add --no-cache curl + +COPY ["./mattermost", "./mattermost-ssl", "/etc/nginx/sites-available/"] COPY ./security.conf /etc/nginx/conf.d/ # Add and setup entrypoint COPY entrypoint.sh / + +#Healthcheck to make sure container is ready +HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1 + ENTRYPOINT ["/entrypoint.sh"] + +VOLUME ["/var/run", "/etc/nginx/conf.d/", "/var/cache/nginx/"] + diff --git a/web/entrypoint.sh b/web/entrypoint.sh index 4e26d4c..2f9839d 100755 --- a/web/entrypoint.sh +++ b/web/entrypoint.sh @@ -2,7 +2,7 @@ # Define default value for app container hostname and port APP_HOST=${APP_HOST:-app} -APP_PORT_NUMBER=${APP_PORT_NUMBER:-80} +APP_PORT_NUMBER=${APP_PORT_NUMBER:-8000} # Check if SSL should be enabled (if certificates exists) if [ -f "/cert/cert.pem" -a -f "/cert/key-no-password.pem" ]; then