diff --git a/deprecated/mattermost-cleaner/Dockerfile b/deprecated/mattermost-cleaner/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..df352b2b535dcb1020ed33d1cbc46fb0b7ba7bba --- /dev/null +++ b/deprecated/mattermost-cleaner/Dockerfile @@ -0,0 +1,12 @@ +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"] diff --git a/deprecated/mattermost-cleaner/README.md b/deprecated/mattermost-cleaner/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1d25c9d01317d7d164b524cd03cfc3281f006a32 --- /dev/null +++ b/deprecated/mattermost-cleaner/README.md @@ -0,0 +1,51 @@ +# 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 +``` diff --git a/deprecated/mattermost-cleaner/cron.sh b/deprecated/mattermost-cleaner/cron.sh new file mode 100755 index 0000000000000000000000000000000000000000..0830d04bff973889094640ff6bd98f035f297f8c --- /dev/null +++ b/deprecated/mattermost-cleaner/cron.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +sh psqlcmd.sh +echo "${CRON_TIME} /psqlcmd.sh" > /crontab.conf +crontab /crontab.conf +exec cron -f diff --git a/deprecated/mattermost-cleaner/psqlcmd.sh b/deprecated/mattermost-cleaner/psqlcmd.sh new file mode 100755 index 0000000000000000000000000000000000000000..6cbf330c2ed894ee6cefbbca9dce24e00207f70c --- /dev/null +++ b/deprecated/mattermost-cleaner/psqlcmd.sh @@ -0,0 +1,17 @@ +#!/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}"