Verified Commit 94991696 authored by Quentin Duchemin's avatar Quentin Duchemin
Browse files

Move mattermost-cleaner

parent 6ef5575b
FROM registry.picasoft.net/pica-debian
MAINTAINER stephane.crozat@utc.fr
RUN apt-get update && \
apt-get install -y --no-install-recommends postgresql-client cron && \
apt-get clean
ENV CRON_TIME="0 * * * *"
COPY cron.sh /cron.sh
COPY psqlcmd.sh /psqlcmd.sh
CMD ["/cron.sh"]
# mattermost-cleaner
This image runs a `cron` to delete automatic messages from Mattermost teams (alpha version, only run on one team).
Delete command is run once when container starts and then every hour (depending on parameter) via `cron`.
**Warning** The commande delete directly data from database, which is bad pratice ; see [here](https://docs.mattermost.com/install/troubleshooting.html#important-notes) and [there](https://docs.mattermost.com/deployment/on-boarding.html#do-not-manipulate-the-mattermost-database)
## Usage:
```bash
$ docker run -d \
--name mattermost-cleaner \
--env POSTGRES_HOST=mattermost-db \
--env POSTGRES_PORT=5432 \
--env POSTGRES_USER=mattermost \
--env POSTGRES_PASS=password \
--env POSTGRES_DB=mattermost \
--env MATTERMOST_TEAM=team \
--net docker_default \
--link mattermost-db:mattermost-db \
registry.picasoft.net:5000/mattermost-cleaner:alpha
```
## Parameters
Here are the different parameters
- `POSTGRES_HOST` the name of the container
- `POSTGRES_PORT` the port number of the postgres database
- `POSTGRES_USER` the username of the postgres database
- `POSTGRES_PASS` the password of the postgres database
- `POSTGRES_DB` the name of the postgres database
- `CRON_TIME` the interval of cron job to run postgresdump. `0 * * * *` by default, which is every hour
## Docker-compose
```yaml
version: "2"
services:
mattermost-cleaner:
image: registry.picasoft.net:5000/mattermost-cleaner:alpha
container_name: mattermost-cleaner
links:
- mattermost-db:mattermost-db
environment:
- POSTGRES_HOST=mattermost-db
- POSTGRES_PORT=5432
- POSTGRES_USER=mattermost
- POSTGRES_PASS=password
- POSTGRES_DB=mattermost
- MATTERMOST_TEAM=team
```
#!/usr/bin/env bash
sh psqlcmd.sh
echo "${CRON_TIME} /psqlcmd.sh" > /crontab.conf
crontab /crontab.conf
exec cron -f
#!/usr/bin/env bash
[ -z "${POSTGRES_HOST}" ] && { echo "=> POSTGRES_HOST cannot be empty" && exit 1; }
[ -z "${POSTGRES_PORT}" ] && { echo "=> POSTGRES_PORT cannot be empty" && exit 1; }
[ -z "${POSTGRES_USER}" ] && { echo "=> POSTGRES_USER cannot be empty" && exit 1; }
[ -z "${POSTGRES_PASS}" ] && { echo "=> POSTGRES_PASS cannot be empty" && exit 1; }
[ -z "${POSTGRES_DB}" ] && { echo "=> POSTGRES_DB cannot be empty" && exit 1; }
[ -z "${MATTERMOST_TEAM}" ] && { echo "=> MATTERMOST_TEAM cannot be empty" && exit 1; }
export PGHOST=$POSTGRES_HOST
export PGPORT=$POSTGRES_PORT
export PGDATABASE=$POSTGRES_DB
export PGUSER=$POSTGRES_USER
export PGPASSWORD=$POSTGRES_PASS
SQL_CMD="DELETE FROM posts WHERE id IN (SELECT p.id FROM posts p LEFT JOIN channels c ON p.channelid=c.id LEFT JOIN teams t ON c.teamid=t.id WHERE (p.type='system_join_channel' OR p.type='system_join_team') AND t.name = '${MATTERMOST_TEAM}')"
psql -c "${SQL_CMD}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment