Production Hardening (#241)
This commit is contained in:
parent
4f0a5376f3
commit
f79bbea7a4
@ -12,11 +12,13 @@ install:
|
|||||||
- sleep 30
|
- sleep 30
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- BUILD="docker-compose up -d"
|
- 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: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:8000 --name app mattermost-prod-app"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- curl -sSf http://localhost > /dev/null
|
- curl -sSf http://localhost > /dev/null
|
||||||
|
- docker ps -a | grep app | grep healthy
|
||||||
|
- docker ps -a | grep db | grep healthy
|
||||||
|
|
||||||
after_failure:
|
after_failure:
|
||||||
- timeout 3s docker-compose logs app db web
|
- timeout 3s docker-compose logs app db web
|
||||||
|
@ -16,8 +16,8 @@ The following instructions deploy Mattermost in a production configuration using
|
|||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
* [docker] (version `1.10.0+`)
|
* [docker] (version `1.12+`)
|
||||||
* [docker-compose] (version `1.6.0+` to support Compose file version `2.0`)
|
* [docker-compose] (version `1.10.0+` to support Compose file version `3.0`)
|
||||||
|
|
||||||
### Choose Edition to Install
|
### Choose Edition to Install
|
||||||
|
|
||||||
@ -86,7 +86,10 @@ them you may generate a self-signed SSL certificate.
|
|||||||
### Starting/Stopping Docker
|
### Starting/Stopping Docker
|
||||||
|
|
||||||
#### Start
|
#### 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
|
docker-compose start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ ENV MM_VERSION=4.9.0
|
|||||||
|
|
||||||
# Build argument to set Mattermost edition
|
# Build argument to set Mattermost edition
|
||||||
ARG edition=enterprise
|
ARG edition=enterprise
|
||||||
|
ARG PUID=2000
|
||||||
|
ARG PGID=2000
|
||||||
|
|
||||||
|
|
||||||
# Install some needed packages
|
# Install some needed packages
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
@ -27,14 +30,24 @@ RUN mkdir -p /mattermost/data \
|
|||||||
&& cp /mattermost/config/config.json /config.json.save \
|
&& cp /mattermost/config/config.json /config.json.save \
|
||||||
&& rm -rf /mattermost/config/config.json
|
&& 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
|
# Configure entrypoint and command
|
||||||
COPY entrypoint.sh /
|
COPY entrypoint.sh /
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
WORKDIR /mattermost
|
WORKDIR /mattermost
|
||||||
CMD ["platform"]
|
CMD ["platform"]
|
||||||
|
|
||||||
# Expose port 80 of the container
|
# Expose port 8000 of the container
|
||||||
EXPOSE 80
|
EXPOSE 8000
|
||||||
|
|
||||||
# Use a volume for the data directory
|
# Declare volumes for mount point directories
|
||||||
VOLUME /mattermost/data
|
VOLUME ["/mattermost/data", "/mattermost/logs", "/mattermost/config"]
|
||||||
|
@ -35,7 +35,7 @@ if [ "$1" = 'platform' ]; then
|
|||||||
# Copy default configuration file
|
# Copy default configuration file
|
||||||
cp /config.json.save $MM_CONFIG
|
cp /config.json.save $MM_CONFIG
|
||||||
# Substitue some parameters with jq
|
# 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.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 '.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
|
jq '.FileSettings.Directory = "/mattermost/data/"' $MM_CONFIG > $MM_CONFIG.tmp && mv $MM_CONFIG.tmp $MM_CONFIG
|
||||||
|
@ -18,7 +18,12 @@ RUN apk add --no-cache \
|
|||||||
# Add wale script
|
# Add wale script
|
||||||
COPY setup-wale.sh /docker-entrypoint-initdb.d/
|
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
|
# Add and configure entrypoint and command
|
||||||
COPY entrypoint.sh /
|
COPY entrypoint.sh /
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
CMD ["postgres"]
|
CMD ["postgres"]
|
||||||
|
|
||||||
|
VOLUME ["/var/run/postgresql", "/usr/share/postgresql/", "/var/lib/postgresql/data", "/tmp"]
|
||||||
|
@ -4,6 +4,7 @@ services:
|
|||||||
|
|
||||||
db:
|
db:
|
||||||
build: db
|
build: db
|
||||||
|
read_only: true
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
|
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
|
||||||
@ -21,9 +22,11 @@ services:
|
|||||||
app:
|
app:
|
||||||
build:
|
build:
|
||||||
context: app
|
context: app
|
||||||
# comment out 2 following lines for team edition
|
# comment out following lines for team edition or change UID/GID
|
||||||
# args:
|
# args:
|
||||||
# - edition=team
|
# - edition=team
|
||||||
|
# - PUID=1000
|
||||||
|
# - PGID=1000
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- ./volumes/app/mattermost/config:/mattermost/config:rw
|
- ./volumes/app/mattermost/config:/mattermost/config:rw
|
||||||
@ -43,6 +46,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
- "443:443"
|
- "443:443"
|
||||||
|
read_only: true
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
# This directory must have cert files if you want to enable SSL
|
# This directory must have cert files if you want to enable SSL
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
FROM nginx:mainline-alpine
|
FROM nginx:mainline-alpine
|
||||||
|
|
||||||
# Remove default configuration and add our custom Nginx configuration files
|
# Remove default configuration and add our custom Nginx configuration files
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
RUN rm /etc/nginx/conf.d/default.conf \
|
||||||
COPY ./mattermost /etc/nginx/sites-available/
|
&& apk add --no-cache curl
|
||||||
COPY ./mattermost-ssl /etc/nginx/sites-available/
|
|
||||||
|
COPY ["./mattermost", "./mattermost-ssl", "/etc/nginx/sites-available/"]
|
||||||
COPY ./security.conf /etc/nginx/conf.d/
|
COPY ./security.conf /etc/nginx/conf.d/
|
||||||
|
|
||||||
# Add and setup entrypoint
|
# Add and setup entrypoint
|
||||||
COPY entrypoint.sh /
|
COPY entrypoint.sh /
|
||||||
|
|
||||||
|
#Healthcheck to make sure container is ready
|
||||||
|
HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
|
VOLUME ["/var/run", "/etc/nginx/conf.d/", "/var/cache/nginx/"]
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Define default value for app container hostname and port
|
# Define default value for app container hostname and port
|
||||||
APP_HOST=${APP_HOST:-app}
|
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)
|
# Check if SSL should be enabled (if certificates exists)
|
||||||
if [ -f "/cert/cert.pem" -a -f "/cert/key-no-password.pem" ]; then
|
if [ -f "/cert/cert.pem" -a -f "/cert/key-no-password.pem" ]; then
|
||||||
|
Reference in New Issue
Block a user