From 629c7b50f34d82d6dfd39b09d0cfe9792ad85d33 Mon Sep 17 00:00:00 2001 From: lighta Date: Thu, 26 Nov 2020 19:58:09 +0100 Subject: [PATCH] Latiosu feat/docker (#5572) * Add dockerised local development environment * Enable tini (--init) for server container See https://docs.docker.com/compose/compose-file/#init for details * Add local development environment documentation * Add a tip for how-to connect a client on the same machine * Add specialized tools/docker folder Co-authored-by: Eric --- .github/CONTRIBUTING.md | 8 +++++++ tools/docker/Dockerfile | 4 ++++ tools/docker/README.md | 29 +++++++++++++++++++++++ tools/docker/asset/char_conf.txt | 2 ++ tools/docker/asset/inter_conf.txt | 5 ++++ tools/docker/asset/map_conf.txt | 2 ++ tools/docker/docker-compose.yml | 39 +++++++++++++++++++++++++++++++ 7 files changed, 89 insertions(+) create mode 100644 tools/docker/Dockerfile create mode 100644 tools/docker/README.md create mode 100644 tools/docker/asset/char_conf.txt create mode 100644 tools/docker/asset/inter_conf.txt create mode 100644 tools/docker/asset/map_conf.txt create mode 100644 tools/docker/docker-compose.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f6d7178e46..daa63b1f64 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -7,6 +7,7 @@ Table of Contents * [Reporting Bugs](#reporting-bugs) * [Suggesting Enhancements](#suggesting-enhancements) * [Issue Labels](#issue-labels) + * [Local Development Environment](#local-development-environment) * [Become a Team Member](#become-a-team-member) Reporting Bugs @@ -161,6 +162,13 @@ For the most part you as a user will have no reason to worry about the **Milesto [search-rathena-label-typemaintenance]: https://github.com/rathena/rathena/issues?q=is%3Aissue+is%3Aopen+label%3Atype%3Amaintenance [search-rathena-label-typequestion]: https://github.com/rathena/rathena/issues?q=is%3Aissue+is%3Aopen+label%3Atype%3Aquestion +Local Development Environment +----------------------------- + +Developers can get up and running quickly with a Dockerized development environment that installs all dependencies needed to run and develop on rAthena. +See tools/docker/README.md for details + + Become a Team Member -------------------- diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile new file mode 100644 index 0000000000..c1004538a2 --- /dev/null +++ b/tools/docker/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine:3.11 +WORKDIR /rathena +RUN apk add --no-cache git cmake make gcc g++ gdb zlib-dev mariadb-dev ca-certificates linux-headers bash +ENTRYPOINT [ "bash" ] diff --git a/tools/docker/README.md b/tools/docker/README.md new file mode 100644 index 0000000000..1a6404b1a5 --- /dev/null +++ b/tools/docker/README.md @@ -0,0 +1,29 @@ +# Docker + +Note that this Dockerized environment **is not suitable** for production deployments, see [Installations](https://github.com/rathena/rathena/wiki/installations) instead. + +### How to setup a local development environment :computer: + +1. `docker-compose up -d` to spin up dev container and database (ensure port `3306` is free) +2. `docker exec -it rathena bash` to connect to dev container +3. All rAthena development commands can be executed inside the dev container, such as compiling (`./configure`, `make clean server`) and starting the server (`./athena-start`, `gdb map-server`, etc ...) +4. `docker-compose down` outside the dev container when done to close database and free resources + +#### Tips & tricks for local development :beginner: + +- Ensure you don't have a database running locally and listening on port `3306` this will cause the database container to fail starting up. +- All file edits within the repository are reflected inside the container, so you can develop in your preferred text editor or IDE. + - Files into ./asset take precedence over conf/import/ counterpart +- Connect to the local database with following credentials: + - Host: `localhost` + - Port: `3306` + - User: `ragnarok` + - Password: `ragnarok` +- On first start up all `/sql-files/*.sql` files are imported into the database. This does not happen on future start ups unless the volume has been deleted. +- Database is saved to local disk so state is persisted between shutdowns and start ups. To fully erase your database and start fresh, delete the volume with `docker-compose down --volumes` +- Check the status of containers with `docker-compose ps` +- If you have modified the `Dockerfile`, be sure to rebuild the docker image with `docker-compose build` + +### F.A.Q + +`ls: can't open '.': Permission denied` turn off selinux. diff --git a/tools/docker/asset/char_conf.txt b/tools/docker/asset/char_conf.txt new file mode 100644 index 0000000000..e66bfe63cc --- /dev/null +++ b/tools/docker/asset/char_conf.txt @@ -0,0 +1,2 @@ +login_ip: 127.0.0.1 +char_ip: 127.0.0.1 diff --git a/tools/docker/asset/inter_conf.txt b/tools/docker/asset/inter_conf.txt new file mode 100644 index 0000000000..77678cec05 --- /dev/null +++ b/tools/docker/asset/inter_conf.txt @@ -0,0 +1,5 @@ +login_server_ip: db +ipban_db_ip: db +char_server_ip: db +map_server_ip: db +log_db_ip: db diff --git a/tools/docker/asset/map_conf.txt b/tools/docker/asset/map_conf.txt new file mode 100644 index 0000000000..e7fe50ab48 --- /dev/null +++ b/tools/docker/asset/map_conf.txt @@ -0,0 +1,2 @@ +char_ip: 127.0.0.1 +map_ip: 127.0.0.1 diff --git a/tools/docker/docker-compose.yml b/tools/docker/docker-compose.yml new file mode 100644 index 0000000000..0907d7e397 --- /dev/null +++ b/tools/docker/docker-compose.yml @@ -0,0 +1,39 @@ +version: "3.7" + +services: + db: + image: "mariadb:bionic" + container_name: "rathena_db" + ports: + - "3306:3306" # allow DB connections from host + volumes: + - "rathenadb:/var/lib/mysql" # save database to local disk + - "../../sql-files/:/docker-entrypoint-initdb.d" # initialize db with ./sql-files + environment: + MYSQL_ROOT_PASSWORD: ragnarok + MYSQL_DATABASE: ragnarok + MYSQL_USER: ragnarok + MYSQL_PASSWORD: ragnarok + server: + image: "rathena:local" + container_name: "rathena" + ports: + - "5121:5121" # map server + - "6121:6121" # char server + - "6900:6900" # login server + volumes: + - "../..:/rathena" # mount git repo directory inside container + - "./asset/inter_conf.txt:/rathena/conf/import/inter_conf.txt" # load db connection + - "./asset/char_conf.txt:/rathena/conf/import/char_conf.txt" #localdev login-char relation + - "./asset/map_conf.txt:/rathena/conf/import/map_conf.txt" #localdev char-map relation + init: true # helps with signal forwarding and process reaping + tty: true + stdin_open: true + build: + context: . + dockerfile: Dockerfile + depends_on: + - db + +volumes: + rathenadb: