3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-06 03:59:31 +01:00

Add Dockerfile and Docker guide

This commit is contained in:
Pragmatic Software 2024-03-31 15:16:25 -07:00
parent a923b505fa
commit b40955a16e
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
5 changed files with 166 additions and 1 deletions

59
Docker/Dockerfile Normal file
View File

@ -0,0 +1,59 @@
# File: Dockerfile
#
# Purpose: Builds a Docker/Podman/etc image of PBot.
# SPDX-FileCopyrightText: 2024 Pragmatic Software <pragma78@gmail.com>
# 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"]

73
Docker/README.md Normal file
View File

@ -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 `<server>-<nick>` 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.

28
Docker/entrypoint.sh Executable file
View File

@ -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 <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
if ! mountpoint -q /opt/pbot/persist-data; then
cat <<EOF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You did not specify a location on the host machine
to store your data. This means NOTHING will persist
if this docker container is deleted or updated, such
as factoids, message history, users, bans, etc.
In other words, you will LOSE YOUR DATA!
Run the container with the -v option:
docker ... -v /path/to/your/data/:/opt/pbot/persist-data
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EOF
exit 1
fi
cd /opt/pbot/
exec bin/pbot data_dir=persist-data "$@"

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
from __future__ import print_function from __future__ import print_function
import sys import sys

View File

@ -2,6 +2,7 @@
<!-- md-toc-begin --> <!-- md-toc-begin -->
* [Installation](#installation) * [Installation](#installation)
* [Docker](#docker)
* [Installing Perl](#installing-perl) * [Installing Perl](#installing-perl)
* [Installing PBot](#installing-pbot) * [Installing PBot](#installing-pbot)
* [git (recommended)](#git-recommended) * [git (recommended)](#git-recommended)
@ -42,6 +43,10 @@
## Installation ## 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 ### Installing Perl
PBot uses the [Perl programming language](https://www.perl.org/). Perl is usually 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 part of a base Linux install. If you do not have Perl installed, please see your