├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── check_prosody_update.sh ├── entrypoint.sh ├── prosody.list ├── test ├── docker-compose.yml └── test.sh └── update-modules.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | test/ 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | MAINTAINER Victor Kulichenko 3 | COPY prosody.list /etc/apt/sources.list.d/ 4 | COPY ./entrypoint.sh /usr/bin/entrypoint.sh 5 | COPY ./update-modules.sh /usr/bin/update-modules 6 | COPY ./check_prosody_update.sh /usr/bin/check_prosody_update 7 | ARG PROSODY_VERSION 8 | ENV PROSODY_VERSION=${PROSODY_VERSION} \ 9 | PUID=${PUID:-1000} PGID=${PGID:-1000} \ 10 | PROSODY_MODULES=/usr/lib/prosody/modules-community \ 11 | CUSTOM_MODULES=/usr/lib/prosody/modules-custom 12 | 13 | # create prosody user with uid and gid predefined 14 | RUN groupadd -g $PGID -r prosody && useradd -b /var/lib -m -g $PGID -u $PUID -r -s /bin/bash prosody 15 | 16 | # install prosody, mercurial, and recommended dependencies, prosody-modules locations, tweak and preserve config 17 | ADD https://prosody.im/files/prosody-debian-packages.key /root/key 18 | RUN set -x \ 19 | && apt-key add /root/key && rm /root/key \ 20 | && apt-get update -qq \ 21 | && echo prosody-migrator${PROSODY_VERSION:--0.9} | sed -e 's/prosody-migrator-0.9//' \ 22 | | xargs apt-get install -qy telnet \ 23 | apt-utils mercurial lua-sec lua-event lua-zlib lua-ldap \ 24 | lua-dbi-mysql lua-dbi-postgresql lua-dbi-sqlite3 lua-bitop \ 25 | prosody${PROSODY_VERSION} \ 26 | && apt-get purge apt-utils -qy \ 27 | && apt-get clean && rm -Rf /var/lib/apt/lists \ 28 | && sed -i -e '1s/^/daemonize = false;\n/' -e 's/daemonize = true/-- daemonize = true/g' /etc/prosody/prosody.cfg.lua \ 29 | && perl -i -pe '$_ = qq[\n-- These paths are searched in the order specified, and before the default path\nplugin_paths = { \"$ENV{CUSTOM_MODULES}\", \"$ENV{PROSODY_MODULES}\" }\n\n$_] if $_ eq qq[modules_enabled = {\n]' \ 30 | /etc/prosody/prosody.cfg.lua \ 31 | && perl -i -pe 'BEGIN{undef $/;} s/^log = {.*?^}$/log = {\n {levels = {min = "info"}, to = "console"};\n}/smg' /etc/prosody/prosody.cfg.lua \ 32 | && mkdir -p /var/run/prosody && chown prosody:adm /var/run/prosody \ 33 | && cp -Rv /etc/prosody /etc/prosody.default && chown prosody:prosody -Rv /etc/prosody /etc/prosody.default \ 34 | && mkdir -p "$PROSODY_MODULES" && chown prosody:prosody -R "$PROSODY_MODULES" && mkdir -p "$CUSTOM_MODULES" && chown prosody:prosody -R "$CUSTOM_MODULES" \ 35 | && chmod 755 /usr/bin/entrypoint.sh /usr/bin/update-modules /usr/bin/check_prosody_update 36 | 37 | VOLUME ["/etc/prosody", "/var/lib/prosody", "/var/log/prosody", "$PROSODY_MODULES", "$CUSTOM_MODULES"] 38 | 39 | USER prosody 40 | 41 | ENTRYPOINT ["/usr/bin/entrypoint.sh"] 42 | 43 | EXPOSE 80 443 5222 5269 5347 5280 5281 44 | ENV __FLUSH_LOG yes 45 | CMD ["prosody"] 46 | 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Victor Kulichenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![](https://img.shields.io/docker/stars/unclev/prosody-docker-extended.svg)](https://hub.docker.com/r/unclev/prosody-docker-extended 'DockerHub') [![](https://img.shields.io/docker/pulls/unclev/prosody-docker-extended.svg)](https://hub.docker.com/r/unclev/prosody-docker-extended 'DockerHub') 2 | # prosody-docker-extended 3 | Docker image building system for the Prosody XMPP server with Community Modules and telnet console. 4 | This project was inspired by the [official Prosody Docker](https://github.com/prosody/prosody-docker/) and particularly to overcome this issue prosody/prosody-docker#29. 5 | 6 | Important! This branch is based on Ubuntu 16.04 _xenial_. See the issue [#15](https://github.com/unclev/prosody-docker-extended/issues/15) on the currently supported versions. 7 | 8 | ## Building 9 | 10 | First, clone this repository and change directory into `prosody-docker-extended/`. Then run: 11 | 12 | ``` 13 | docker build --build-arg PROSODY_VERSION="" --rm=true -t unclev/prosody-docker-extended:stable . 14 | ``` 15 | 16 | Where PROSODY_VERSION can also be `-trunk`, `-0.11`, `-0.10`, `-0.9` for nightly builds. 17 | 18 | It is available at [Docker Hub](https://hub.docker.com/r/unclev/prosody-docker-extended/). 19 | The tags are: latest, 0.10, 0.9, for prosody-trunk, prosody-0.10, prosody-0.9 accordingly, "stable" tag for prosody with no version specified (as per above). 20 | 21 | The [Docker Hub](https://hub.docker.com/r/unclev/prosody-docker-extended/) images are now re-builds within an hour after each nightly build in the official Prosody deb [repository](https://prosody.im/download/package_repository). 22 | 23 | ## prosody-docker-extended features 24 | ### Ports 25 | 26 | The image exposes the following ports to the docker host: 27 | 28 | * __80__: HTTP port 29 | * __443__ HTTPS port 30 | * __5222__: c2s port 31 | * __5269__: s2s port 32 | * __5347__: XMPP component port 33 | * __5280__: BOSH / websocket port 34 | * __5281__: Secure BOSH / websocket port 35 | 36 | Note: These default ports can be changed in your configuration file. Therefore if you change these ports will not be exposed. 37 | 38 | ### Volumes 39 | Volumes can be mounted at the following locations for adding in files: 40 | 41 | * __/etc/prosody__: 42 | * Prosody configuration file(s) 43 | * SSL certificates 44 | * Note: the [starter](https://github.com/unclev/prosody-docker-extended/blob/master/entrypoint.sh#L7) copies the pre-configured at build time data into this location if it empty. 45 | * __/var/lib/prosody__: 46 | * Prosody internal data storage (see [Data storage](https://prosody.im/doc/storage) at the Prosody web site) 47 | * __/var/log/prosody__: 48 | * Log files for prosody - by default it is not used by prosody-docker-extended container, logs go to console and visible via [docker logs](https://docs.docker.com/engine/reference/commandline/logs/). 49 | * Note: This location can be changed in the configuration, update to match 50 | * Also note: The log directory on the host (/logs/prosody in the example below) must be writeable by the prosody user 51 | * __/usr/lib/prosody/modules-community__: 52 | * Location for including community modules 53 | * Note: The image has it pre-configured in the config file, the [starter](https://github.com/unclev/prosody-docker-extended/blob/master/entrypoint.sh#L21-L22) clones https://hg.prosody.im/prosody-modules/ into this location if it is empty. 54 | * __/usr/lib/prosody/modules-custom__: 55 | * Location for including additional modules 56 | * The image has the modules locations pre-configured as per [installing_modules](http://prosody.im/doc/installing_modules#paths) at the Prosody web site. 57 | 58 | ```lua 59 | -- These paths are searched in the order specified, and before the default path 60 | plugin_paths = { "/usr/lib/prosody/modules-custom", "/usr/lib/prosody/modules-community" } 61 | ``` 62 | ### Prosody user 63 | There is a user with uid=1000(prosody) gid=1000(prosody) groups=1000(prosody) in the __prosody-docker-extended__ image. 64 | 65 | #### Ownership issue 66 | 67 | As _Prosody_ starts in behalf of the `prosody` user (1000:1000) inside the container, it expects the configured directories are owned by `prosody`. 68 | 69 | However, if volumes do no exist, they are creaded by docker as `root` user, and this causes issues (#6, #7, #16). 70 | 71 | As a **workaround** it is suggested creating the directories you bind before `docker run -d ... unclev/prosody-docker-extended`. 72 | 73 | So for the [example](#examples) below it is 74 | 75 | ```bash 76 | sudo -u '#1000' -g '#1000' mkdir -pv /srv/prosody/{config,data,log,modules/community,modules/custom} 77 | ``` 78 | 79 | If you have already had directories created, - change their ownership: 80 | 81 | ```bash 82 | sudo chown -Rv 1000:1000 /srv/prosody 83 | ``` 84 | 85 | In Kubernetes you can use `fsGroup` and make it writable. (See [this Stack Overflow answer](https://stackoverflow.com/a/46769504)). 86 | 87 | Ownership is not an issue when creating volumes those are not bind mounts. 88 | 89 | ### Adding a jabber user at startup 90 | For compatibility with prosody/prosody-docker a user can be created by using environment variables `LOCAL`, `DOMAIN`, and `PASSWORD`. This performs the following action on startup: 91 | > prosodyctl register *local* *domain* *password* 92 | 93 | Prosody will not check the user exists before running the command (i.e. existing users will be overwritten). It is expected that [mod_admin_adhoc](http://prosody.im/doc/modules/mod_admin_adhoc) will then be in place for managing users (and the server). 94 | 95 | ### Examples 96 | 97 | Before you start, - [create the directories](#ownership-issue) you want to bind. 98 | 99 | ```bash 100 | docker run -d \ 101 | --name prosody_xmpp_server \ 102 | --hostname shakespeare.lit \ 103 | -p 5222:5222 \ 104 | -p 5269:5269 \ 105 | -p localhost:5347:5347 \ 106 | -e LOCAL=romeo \ 107 | -e DOMAIN=shakespeare.lit \ 108 | -e PASSWORD=juliet4ever \ 109 | -v /srv/prosody/config:/etc/prosody \ 110 | -v /srv/prosody/data:/var/lib/prosody \ 111 | -v /srv/prosody/log:/var/log/prosody \ 112 | -v /srv/prosody/modules/community:/usr/lib/prosody/modules-community \ 113 | -v /srv/prosody/modules/custom:/usr/lib/prosody/modules-custom \ 114 | unclev/prosody-docker-extended 115 | ``` 116 | 117 | docker-compose.yml (v1) with PostgreSQL backend: 118 | 119 | ```yaml 120 | sql: 121 | image: postgres 122 | restart: always 123 | env_file: /srv/prosody/.env 124 | ports: 125 | - '5432:5432' 126 | volumes: 127 | - '/srv/prosody/db/postgresql:/var/lib/postgresql/prosody' 128 | 129 | xmpp_server: 130 | image: unclev/prosody-docker-extended:0.10 131 | restart: unless-stopped 132 | hostname: shakespeare.lit 133 | ports: 134 | - 5222:5222 135 | - 5269:5269 136 | - 5347:5347 137 | - 5280:5280 138 | env_file: /srv/prosody/.env 139 | links: 140 | - sql:sql 141 | volumes: 142 | - '/srv/prosody/config:/etc/prosody' 143 | - '/srv/prosody/data:/var/lib/prosody' 144 | - '/srv/prosody/log:/var/log/prosody' 145 | - '/srv/prosody/modules/community:/usr/lib/prosody/modules-community' 146 | - '/srv/prosody/modules/custom:/usr/lib/prosody/modules-custom' 147 | ``` 148 | 149 | ### Starting the container shell 150 | Connect to a linux shell of a running __prosody-docker-extended__ container (or any other executable resides in the container) is easy: 151 | ```bash 152 | docker exec -it prosody_xmpp_server bash 153 | ``` 154 | or with docker-compose 155 | ```bash 156 | docker-compose exec xmpp_server bash 157 | ``` 158 | 159 | this brings linux shell with *prosody* user. 160 | 161 | Explicitly specify `--user root` if you want root shell. See [docker exec](https://docs.docker.com/engine/reference/commandline/exec/) for more details. 162 | 163 | ### Telnet console 164 | __prosody-docker-extended__ comes with telnet. Enabling [mod_admin_telnet](https://prosody.im/doc/modules/mod_admin_telnet) plugin (as of now it is not enabled by default) starts a telnet console to let you communicate with a running prosody server. 165 | ```bash 166 | docker exec -it prosody_xmpp_server telnet localhost 5582 167 | ``` 168 | 169 | or with docker-compose 170 | 171 | ```bash 172 | docker-compose exec xmpp_server telnet localhost 5582 173 | ``` 174 | For information on the telnet console see [Console](https://prosody.im/doc/console) in the Prosody documentation. 175 | 176 | It does not make sense requesting __server:shutdown__ via the telnet console as in most configurations a container with the server restarts. 177 | 178 | ### prosodyctl 179 | Using [prosodyctl](https://prosody.im/doc/prosodyctl) to control the server is aslo possible. 180 | See the Prosody documentation: [prosodyctl](https://prosody.im/doc/prosodyctl). 181 | 182 | It does not make sense requesting __start__, __stop__, __restart__ commands of *prosodyctl*, as prosody process is not started as a daemon within a container. 183 | 184 | Note: do not change the pre-defined 185 | ```lua 186 | daemonize = false; 187 | ``` 188 | setting in the prosody.cfg.lua. 189 | 190 | __To restart the server__ you can stop, remove, and re-start the container itself. For example, the only *prosody_xmpp_server_1* container with docker-compose: 191 | ``` 192 | victor@unclev:/srv/prosody$ docker-compose stop xmpp_server && docker-compose rm -f xmpp_server && docker-compose up -d 193 | ``` 194 | or just 195 | ```bash 196 | docker-compose down && docker-compose up -d 197 | ``` 198 | the last stops and re-starts all the services in the docker composition. 199 | 200 | ### Community modules 201 | For information on community modules address the Prosody documentation: [community modules](https://prosody.im/community_modules). 202 | 203 | The __prosody-docker-extended__ image comes with [Mercurial SCM](https://www.mercurial-scm.org/) installed in it. 204 | The container clones https://hg.prosody.im/prosody-modules/ into `/usr/lib/prosody/modules-community` when it starts in the name of the *prosody* user. 205 | Normally you should map `/usr/lib/prosody/modules-community` to a persistent location (on your docker host or a data container). 206 | 207 | Even though the repository support within the image is very limited by (some modules may add files into their folders within the repo, which may prevent the repo from being updated). However, you can control [community modules](https://hg.prosody.im/prosody-modules/) from the container shell. 208 | ``` 209 | victor@unclev:/srv/prosody$ docker-compose exec xmpp_server bash 210 | prosody@unclev:/$ cd /usr/lib/prosody/modules-community 211 | prosody@unclev:/usr/lib/prosody/modules-community$ hg status 212 | ? mod_admin_web/admin_web/www_files/css/bootstrap-1.4.0.min.css 213 | ? mod_admin_web/admin_web/www_files/js/adhoc.js 214 | ? mod_admin_web/admin_web/www_files/js/jquery-1.10.2.min.js 215 | ? mod_admin_web/admin_web/www_files/js/strophe.min.js 216 | ? mod_mam_archive/SciTE.properties 217 | prosody@unclev:/usr/lib/prosody/modules-community$ hg pull --update 218 | pulling from https://hg.prosody.im/prosody-modules/ 219 | searching for changes 220 | no changes found 221 | ``` 222 | 223 | ### Custom modules 224 | As a workaround you can put modules being used in your persistent location and map `/usr/lib/prosody/modules-custom` to it. 225 | 226 | The __prosody-docker-extended__ image is configured to look for modules under this location first. 227 | 228 | ### Logs 229 | The Prosody server within the __prosody-docker-extended__ image is configured to log to "console" (see [advanced_logging](https://prosody.im/doc/advanced_logging) in the Prosody documentation). 230 | This prevents contamination of the newly created container with such garbage. 231 | 232 | Use mapping of `/var/log/prosody` directory want set up logs in a persistent location (likely - your docker host). 233 | 234 | There is an example in [Information for packagers - logging](https://prosody.im/doc/packagers#logging) in the Prosody documentation. 235 | ```lua 236 | log = { 237 | -- Log all error messages to prosody.err 238 | { levels = { min = "error" }, to = "file", filename = "/var/log/prosody/prosody.err" }; 239 | -- Log everything of level "info" and higher (that is, all except "debug" messages) 240 | -- to prosody.log 241 | { levels = { min = "info" }, to = "file", filename = "/var/log/prosody/prosody.log" }; 242 | } 243 | ``` 244 | __Log rotation__ is supposed to be set up on your docker host. The prosody-docker-extended image itself does not support log rotation. 245 | 246 | ## Configuring Prosody IM server 247 | Configuring Prosody IM XMPP communication server resided within the __prosody-docker-extended__ container is generally the same as configuring a standalone Prosody IM server, 248 | but please don't forget specifying internal container paths, - not the external mapped paths, in the prosody config. 249 | Please see the official Prosody IM documentation on [configuring Prosody](https://prosody.im/doc/configure). 250 | -------------------------------------------------------------------------------- /check_prosody_update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ( apt update -qq && apt list --upgradable ) 2> /dev/null | grep prosody 3 | 4 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | 5 | if [[ $(id -u) -eq $(id -u prosody) ]]; then 6 | if [[ -z $(ls -A /etc/prosody | head -1) ]] ; then 7 | cp -Rv /etc/prosody.default/* /etc/prosody/ 8 | fi 9 | if [[ -n $DOMAIN ]]; then 10 | # tweak config 11 | sed -i "s/example.com/$DOMAIN/g" /etc/prosody/prosody.cfg.lua 12 | sed -i 's/enabled = false -- Remove this line to enable/enabled = true -- false to disable/' /etc/prosody/prosody.cfg.lua 13 | # copy default key pair if not exists 14 | if [[ ! -f /etc/prosody/certs/$DOMAIN.key && -f /etc/prosody/certs/localhost.key ]]; then 15 | cp /etc/prosody/certs/localhost.key /etc/prosody/certs/$DOMAIN.key 16 | fi 17 | if [[ ! -f /etc/prosody/certs/$DOMAIN.crt && -f /etc/prosody/certs/localhost.crt ]]; then 18 | cp /etc/prosody/certs/localhost.crt /etc/prosody/certs/$DOMAIN.crt 19 | fi 20 | fi 21 | if [ -z $(ls -A ${PROSODY_MODULES} | head -1) ]; then 22 | /usr/bin/update-modules 23 | fi 24 | if [[ $1 == "prosody" && -n $LOCAL && -n $PASSWORD && -n $DOMAIN ]]; then 25 | prosodyctl register $LOCAL $DOMAIN $PASSWORD 26 | fi 27 | fi 28 | exec "$@" 29 | -------------------------------------------------------------------------------- /prosody.list: -------------------------------------------------------------------------------- 1 | deb http://packages.prosody.im/debian xenial main 2 | 3 | -------------------------------------------------------------------------------- /test/docker-compose.yml: -------------------------------------------------------------------------------- 1 | xmpp_server: 2 | image: unclev/prosody-docker-extended:stable 3 | #build: ./build.local 4 | restart: unless-stopped 5 | hostname: unclev.ru 6 | #ports: 7 | # - 5222:5222 8 | # - 5269:5269 9 | # - 5347:5347 10 | # - 5280:5280 11 | # - 5281:5281 12 | # - 5380:80 13 | volumes: 14 | - './config:/etc/prosody' 15 | - './data:/var/lib/prosody' 16 | 17 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | mkdir -pv config data && rm -Rv config data && mkdir -pv config data && docker-compose up 3 | 4 | -------------------------------------------------------------------------------- /update-modules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | 5 | if [[ -z $(ls -A ${PROSODY_MODULES} | head -1) ]]; then 6 | hg clone https://hg.prosody.im/prosody-modules/ "$PROSODY_MODULES" || true 7 | else 8 | cd "$PROSODY_MODULES" 9 | hg pull --update || true 10 | cd - 11 | fi 12 | 13 | --------------------------------------------------------------------------------