From 84bd0821c57e8df5f15b237946779071fb573f14 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Mon, 22 Aug 2016 17:24:14 +0530 Subject: [PATCH] Add znc application --- znc/Dockerfile | 36 +++++++++++++++ znc/README.md | 45 +++++++++++++++++++ znc/cccp.yml | 5 +++ znc/root/usr/bin/container-entrypoint | 2 + znc/root/usr/bin/generate_znc_conf | 18 ++++++++ znc/root/usr/bin/run-znc | 31 +++++++++++++ .../container-scripts/znc/znc.conf.default | 37 +++++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 znc/Dockerfile create mode 100644 znc/README.md create mode 100644 znc/cccp.yml create mode 100755 znc/root/usr/bin/container-entrypoint create mode 100755 znc/root/usr/bin/generate_znc_conf create mode 100755 znc/root/usr/bin/run-znc create mode 100644 znc/root/usr/share/container-scripts/znc/znc.conf.default diff --git a/znc/Dockerfile b/znc/Dockerfile new file mode 100644 index 00000000..86e55360 --- /dev/null +++ b/znc/Dockerfile @@ -0,0 +1,36 @@ +FROM centos:latest +MAINTAINER http://www.centos.org + +ENV ZNC_VERSION=1.6.3 \ + DATADIR=/var/lib/znc-data + +LABEL summary="ZNC is an IRC bouncer" \ + io.k8s.description="ZNC is an IRC bouncer" \ + io.k8s.display-name="ZNC 1.6.3" \ + io.openshift.expose-services="6667:znc" \ + io.openshift.tags="znc,ircbouncer" \ + Vendor="CentOS" \ + License=GPLv2 \ + Version=1.6.3 + + +EXPOSE 6667 + +RUN INSTALL_PKGS="rsync tar gettext hostname bind-utils policycoreutils znc znc-devel" && \ + yum -y install epel-release && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + yum clean all && \ + mkdir -p /var/lib/znc-data && chown -R znc.0 /var/lib/znc-data && \ + rpm -q --qf '%{version}' znc | grep -e '1\.6\.3' && \ + test "$(id znc)" = "uid=997(znc) gid=996(znc) groups=996(znc)" + +ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/znc + +ADD root / + +VOLUME ["/var/lib/znc-data"] + +USER 997 +ENTRYPOINT ["container-entrypoint"] +CMD ["run-znc"] diff --git a/znc/README.md b/znc/README.md new file mode 100644 index 00000000..e393767f --- /dev/null +++ b/znc/README.md @@ -0,0 +1,45 @@ +ZNC Docker image +==================== + +This container image includes ZNC-1.6.3 for OpenShift and general usage. + +Environment variables and volumes +---------------------------------- + +The following environment variable influence the ZNC configuration file (and optional) + +| Variable name | Description | Default +| :-------------------- | -------------------------------- | ------------------------- +| `ZNC_ADMIN_PASSWORD` | Sets password for ZNC admin User | admin + +You can also set the following mount points by passing the `-v /host:/container` flag to Docker. + +| Volume mount point | Description | +| :----------------------- | ------------------ | +| `/var/lib/znc-data` | ZNC data directory | + +**Notice: When mouting a directory from the host into the container, ensure that the mounted +directory has the appropriate permissions and that the owner and group of the directory +matches the user UID which is running inside the container.** + +Usage +--------------------------------- + +For this, we will assume that you are using the `znc` image. +If you don't want to store the optional variable and data directory then execute the following command: + +``` +$ docker run -d --name znc -p 6667:6667 znc +``` + +This will create a container named `znc` running znc sever with `admin` as user +and `admin` credentials. Port 6667 will be exposed and mapped +to the host. If you want your ZNC to be persistent across container executions, +also add a `-v /host/znc/data:/var/lib/znc-data` argument. This will be the ZNC +data directory. + + +ZNC admin user +--------------------------------- +The admin user has `admin` password set by default. +You can set it by setting the `ZNC_ADMIN_PASSWORD` environment variable. diff --git a/znc/cccp.yml b/znc/cccp.yml new file mode 100644 index 00000000..47030916 --- /dev/null +++ b/znc/cccp.yml @@ -0,0 +1,5 @@ +# This is for the purpose of building the container through the CentOS Communnity +# # Container Pipeline. https://github.com/CentOS/container-index + +job-id: znc +test-skip: true diff --git a/znc/root/usr/bin/container-entrypoint b/znc/root/usr/bin/container-entrypoint new file mode 100755 index 00000000..9d8ad4d3 --- /dev/null +++ b/znc/root/usr/bin/container-entrypoint @@ -0,0 +1,2 @@ +#!/bin/bash +exec "$@" diff --git a/znc/root/usr/bin/generate_znc_conf b/znc/root/usr/bin/generate_znc_conf new file mode 100755 index 00000000..cce2dbb2 --- /dev/null +++ b/znc/root/usr/bin/generate_znc_conf @@ -0,0 +1,18 @@ +#!/usr/bin/python3 + +import hashlib +import string +import os +from random import SystemRandom + +raw_password = os.getenv('ZNC_ADMIN_PASSWORD', 'admin') + +salt_chars = string.ascii_letters + string.digits +random = SystemRandom() +salt = "".join([random.choice(salt_chars) for i in range(20)]) +hash_password = "sha256#{hash}#{salt}#".format( + hash=hashlib.sha256((raw_password+salt).encode('utf-8')).hexdigest(), + salt=salt) + +print("{0}={1}".format('ADMIN_PASS', hash_password)) + diff --git a/znc/root/usr/bin/run-znc b/znc/root/usr/bin/run-znc new file mode 100755 index 00000000..39da83bc --- /dev/null +++ b/znc/root/usr/bin/run-znc @@ -0,0 +1,31 @@ +#!/bin/bash + +# Build modules from source. +if [ -d "${DATADIR}/modules" ]; then + # Store current directory. + cwd="$(pwd)" + + # Find module sources. + modules=$(find "${DATADIR}/modules" -name "*.cpp") + + # Build modules. + for module in $modules; do + echo "Building module $module..." + cd "$(dirname "$module")" + znc-buildmod "$module" + done + + # Go back to original directory. + cd "$cwd" +fi + +# Create default config if it doesn't exist +if [ ! -f "${DATADIR}/configs/znc.conf" ]; then + echo "Creating a default configuration..." + genrated=$(generate_znc_conf); export $genrated + mkdir -p "${DATADIR}/configs" + envsubst < ${CONTAINER_SCRIPTS_PATH}/znc.conf.default > ${DATADIR}/configs/znc.conf +fi + +# Start ZNC. +znc --foreground --datadir="$DATADIR" $@ diff --git a/znc/root/usr/share/container-scripts/znc/znc.conf.default b/znc/root/usr/share/container-scripts/znc/znc.conf.default new file mode 100644 index 00000000..8af6cdbb --- /dev/null +++ b/znc/root/usr/share/container-scripts/znc/znc.conf.default @@ -0,0 +1,37 @@ +// WARNING +// +// Do NOT edit this file while ZNC is running! +// Use webadmin or *controlpanel instead. +// +// Altering this file by hand will forfeit all support. +// +// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash. +// Also check http://en.znc.in/wiki/Configuration +ProtectWebSessions = true +ServerThrottle = 30 +LoadModule = webadmin +Version = 1.6.1 + + + Port = 6667 + IPv4 = true + IPv6 = true + SSL = false + + + + Pass = ${ADMIN_PASS} + Admin = true + Nick = admin + AltNick = admin_ + Ident = admin + RealName = Got ZNC? + Buffer = 50 + AutoClearChanBuffer = true + ChanModes = +stn + + LoadModule = chansaver + LoadModule = controlpanel + LoadModule = perform + +