Docker

From Bebot Wiki 2
Revision as of 20:15, 7 December 2023 by B3b0tUzR (talk | contribs)
Jump to navigationJump to search
Docker

So using Docker can save you some installation hassle, but you'll need to have it installed properly - depending on system hosting your bot(s) :

Windows => https://docs.docker.com/desktop/install/windows-install/

Linux => https://docs.docker.com/desktop/install/linux-install/

Mac => https://docs.docker.com/desktop/install/mac-install/

Note : if you're not a Linux/PHP/SQL expert this will save you time but beware that understanding Docker also some requires practice of its own ...


Build

Once the software is installed, you'll have to build a container based on Bebot itself + docker elements.


So you can download Bebot code (either from Official/Stable or Sandbox/Dev) as .zip (or using git pull command).

NOTE : you can already edit files in Conf/ folder (if you know /howwhat to do !). Otherwise you'll do it interactively later.


Once done you'll have a Bebot folder (let's name it "befolder" for later reference) in which you will create 2 text files :


"Dockerfile" (with no extension)

FROM alpine:latest
ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["/bebot/docker-entrypoint.sh"]
RUN apk --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ add \
    php82-cli php82-sqlite3 php82-phar php82-curl php82-sockets php82-pdo php82-pdo_sqlite \
    php82-pdo_mysql php82-mbstring php82-ctype php82-bcmath php82-json php82-posix php82-simplexml \
	php82-dom php82-pcntl php82-zip php82-opcache php82-fileinfo php82-mysqli \
	tini \
    sudo \
    && \
    adduser -h /bebot -s /bin/false -D -H bebot
COPY --chown=bebot:bebot . /bebot
RUN sudo ln -s /usr/bin/php82 /usr/bin/php8
USER bebot
WORKDIR /bebot


"docker-entrypoint.sh"

#!/bin/ash
# shellcheck shell=dash
errorMessage() {
	echo "$*"
	exit 1
}
EXITCODE=255
while [ "$EXITCODE" -eq 255 ]; do
	trap "" TERM
	# shellcheck disable=SC2086
	/usr/bin/php8  StartBot.php "$@"
	EXITCODE=$?
	trap - TERM
done
exit $EXITCODE


Then in command line, you'll move into that folder to send the following command :

docker build -t bebot-buildname .

(you can change "buildname" for anything you like but then you'll replace it below accordingly)


If all goes fine you should see something like "Building X.Ys (10/10) FINISHED" and several blue lines starting with "=>".


NOTE : if you already have a SQL server you can use it & skip to "Run" below. Otherwise you must run a container for Database.

The principle is then nearly the same. First obtain the base files by doing :

docker pull mariadb:X.Y

(where X.Y is the version you want like 10.2 for example)


Run

We're now ready to run our container(s) : 1 only if we want Bebot + your usual SQL server, or 2 for Bebot + SQL both as Docker containers.


For SQL (optional) :

docker run --name mariadb-containername -e MYSQL_ROOT_PASSWORD=mypass -p 3306:3306 -d mariadb:X.Y --restart=always

(where X.Y is the version you pulled earlier ; you can change "buildname" for anything you like but then you'll replace it below accordingly)


For Bebot (mandatory) :

Windows :

docker run -d --rm --name bebot-containername --memory=128M -v C:\Folder\befolder\conf:\bebot\Conf -v C:\Folder\befolder\conf\log:\bebot\log -v C:\Folder\befolder\conf\Commodities:\bebot\Commodities bebot-buildname

(you must replace "buildname" and "C:\Folder\befolder" accordingly to your system ; "containername" is free to choose ; all path use antislashes \)

Mac/Linux :

docker run -d --rm --name bebot-containername --memory=128M -v /path/to/befolder/conf:/bebot/Conf -v /path/to/befolder/log:/bebot/log     -v /path/to/befolder/Commodities:/bebot/Commodities bebot-buildname

(you must replace "buildname" and "/path/to/befolder" accordingly to your system ; "containername" is free to choose ; all path use slashes /)


Control

Now to control if your container(s) run properly, and to control them you have a set of commands.

To show a list of running container(s) :

docker ps

To see realtime life of the Bebot :

docker logs -f <full-containername>

(Ctrl+c to exit) To enter a given container interactively :

docker exec -it <full-containername>

Once inside, you command line window becomes the bot itself ; so you can see what the bot does realtime (sent & received datas, etc).

NOTE : if it's bot's 1st run & you didn't edit Conf/ files earlier, it's time to fill all infos (account/pass, char, game server, mysql credentials, etc).

If the bot is set correctly it should go online in the game and become reachable/responsive as expected.

To exit the entered container :

Ctrl+p Ctrl+q

To stop a given container :

docker stop <full-containername>

(or Ctrl+c while entered in interactive mode upper)


Conclusion

This guide is a work in progress and will evolve as we find improvements or tricks.