From b40955a16e29836a7713a54887dced0e85e94aee Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 31 Mar 2024 15:16:25 -0700 Subject: [PATCH] Add Dockerfile and Docker guide --- Docker/Dockerfile | 59 ++++++++++++++++++++++++++++++++++ Docker/README.md | 73 ++++++++++++++++++++++++++++++++++++++++++ Docker/entrypoint.sh | 28 ++++++++++++++++ applets/paren/paren.py | 2 +- doc/QuickStart.md | 5 +++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 Docker/Dockerfile create mode 100644 Docker/README.md create mode 100755 Docker/entrypoint.sh diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 00000000..33a1d2cc --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,59 @@ +# File: Dockerfile +# +# Purpose: Builds a Docker/Podman/etc image of PBot. + +# SPDX-FileCopyrightText: 2024 Pragmatic Software +# SPDX-License-Identifier: MIT + +# Perl image on Debian 12 bookworm +FROM perl:5.36-bookworm + +# There is some initial set-up that must be done as root +USER root + +# add contrib to debian.sources +RUN sed -i 's/^Components: main$/& contrib/' /etc/apt/sources.list.d/debian.sources + +# Install necessary packages +RUN apt update && apt-get -y --no-install-recommends install \ + cpanminus gcc g++ libssl-dev libexpat1-dev zlib1g libdbd-sqlite3-perl \ + python3 pip + +# translate-shell +RUN apt-get -y --no-install-recommends install \ + libfribidi0 libfribidi-bin gawk libsigsegv2 translate-shell + +# qalculate +RUN apt-get -y install qalc \ + && qalc 1+1 \ + && sed -i \ + -e 's/save_mode_on_exit=1/save_mode_on_exit=0/' \ + -e 's/auto_update_exchange_rates=-1/auto_update_exchange_rates=1/' \ + -e 's/colorize=1/colorize=0/' \ + -e 's/abbreviate_names=1/abbreviate_names=0/' ~/.config/qalculate/qalc.cfg + +# wiktionary +RUN pip install git+https://github.com/pragma-/WiktionaryParser --break-system-packages + +# unicode +RUN pip install git+https://github.com/garabik/unicode --break-system-packages + +# paren/prec +RUN pip install 'pycparser==2.10' --break-system-packages + +WORKDIR /opt + +# Get PBot from GitHub +RUN git clone --depth=1 --recursive https://github.com/pragma-/pbot + +WORKDIR /opt/pbot + +# Install PBot CPAN depedencies +RUN cpanm -n --installdeps . --with-all-features --without-feature=compiler_vm_win32 + +# Compile qrpn +RUN gcc -Os -march=native /opt/pbot/applets/qrpn/qrpn.c -o /opt/pbot/applets/qrpn/qrpn -lm + +COPY entrypoint.sh /opt/pbot/bin/ + +ENTRYPOINT ["/opt/pbot/bin/entrypoint.sh"] diff --git a/Docker/README.md b/Docker/README.md new file mode 100644 index 00000000..d09b4017 --- /dev/null +++ b/Docker/README.md @@ -0,0 +1,73 @@ +Install docker: + + zypper install docker docker-compose docker-compose-switch + +If not using openSUSE, replace `zypper` with appropriate package manager, e.g. `apt`, `yum`, `dnf`, `apk`, etc. + +To start docker daemon during boot: + + sudo systemctl enable docker + +Restart docker daemon: + + sudo systemctl restart docker + +Verify docker is running: + + docker version + +Join docker group: + + sudo usermod -G docker -a $USER + +Log in to the docker group: + + newgrp docker + +If the above does not work, e.g. because you are in a tmux session, you can `su $USER` instead. + +Build image: + + docker build . -t pbot + +Copy data directory. The `$DATA_DIR` should be a unique name identifying the purpose of the bot, i.e. its name or the IRC server. + + copy -r ../data $DATA_DIR + +I like to use `-` when naming my data directories. For example: + + copy -r ../data ircnet-candide + copy -r ../data libera-candide + copy -r ../data libera-cantest + +Create and start a new container the for the first time with options configuring the botnick and IRC server. We will use the `-ti` +flags for `docker run` so we can access PBot's terminal console to run commands like `useradd` to create +your bot-admin account, etc. + +See [Configuration](../doc/QuickStart.md#configuration) in the [QuickStart guide](../doc/QuickStart.md) for +more information about the available configuration options. + +`$DATA_DIR` here must be the full path, i.e. `$HOME/pbot/Docker/libera-candide`. + + docker run --name pbot -ti -v $DATA_DIR:/opt/pbot/persist-data pbot irc.botnick=$NICK irc.server=$SERVER irc.port=$PORT + +For example, to connect securely via TLS to irc.libera.chat with botnick `coolbot`: + + docker run --name pbot -ti -v $DATA_DIR:/opt/pbot/persist-data pbot irc.botnick=coolbot irc.server=irc.libera.chat irc.port=6697 irc.tls=1 + +Follow the steps in [Additional configuration](../doc/QuickStart.md#additional-configuration) in the [QuickStart guide](../doc/QuickStart.md) +to create your bot-admin account, add channels, etc. + +To shutdown the bot, press `^C` (ctrl-c) or enter `die` into the PBot terminal console. + +To start the bot again in the future: + + docker start pbot + +This will start the bot in the background. You can reattach to its PBot terminal console with: + + docker attach --detach-keys="ctrl-x" pbot + +Press `^X` (ctrl-x) to detach or `^C` (ctrl-c) to shutdown the bot. + +See [Further Reading](../doc/QuickStart.md#further-reading) in the [QuickStart guide](../doc/QuickStart.md) for additional information. diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.sh new file mode 100755 index 00000000..167371b8 --- /dev/null +++ b/Docker/entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# File: entrypoint.sh +# Purpose: Docker/Podman/etc entry-point. Ensures user has mounted data, etc. + +# SPDX-FileCopyrightText: 2001-2023 Pragmatic Software +# SPDX-License-Identifier: MIT + +if ! mountpoint -q /opt/pbot/persist-data; then + cat < * [Installation](#installation) + * [Docker](#docker) * [Installing Perl](#installing-perl) * [Installing PBot](#installing-pbot) * [git (recommended)](#git-recommended) @@ -42,6 +43,10 @@ ## Installation +### Docker +If you prefer to use Docker/Podman/etc to run PBot, follow the [Docker guide](../Docker/README.md) instead. +The set-up is much easier and will install packages/dependencies into a container instead. + ### Installing Perl PBot uses the [Perl programming language](https://www.perl.org/). Perl is usually part of a base Linux install. If you do not have Perl installed, please see your