diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index c983761983..af412c25ea 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,4 +1,5 @@ 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 valgrind -ENTRYPOINT [ "bash" ] +RUN apk add --no-cache wget git cmake make gcc g++ gdb zlib-dev mariadb-dev ca-certificates linux-headers bash valgrind netcat-openbsd +RUN wget https://raw.githubusercontent.com/eficode/wait-for/v2.2.2/wait-for -O /bin/wait-for && chmod +x /bin/wait-for +ENTRYPOINT [ ] diff --git a/tools/docker/README.md b/tools/docker/README.md index 1a6404b1a5..a821180f0e 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -5,9 +5,20 @@ Note that this Dockerized environment **is not suitable** for production deploym ### 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 +2. `docker-compose run builder bash` in order to run aditional build or shell scripts within the linux context. 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 +5. All commands expect you to have change directory to this directory, `$projectRoot/tools/docker`. +6. Change the value of `BUILDER_CONFIGURE` environment variable of the `builder` service in order to change the parameters sent to the `./configure` command +> If you have already compiled the project once, you might want to connect directly to the builder service (see 2.) and run commands from there (see 3.). +7. If you want the builder to build your project on each start change line 8 from +```bash + export runBuild=0; +``` +to +```bash + export runBuild=1; +``` #### Tips & tricks for local development :beginner: diff --git a/tools/docker/asset/char_conf.txt b/tools/docker/asset/char_conf.txt index e66bfe63cc..32cb5b9116 100644 --- a/tools/docker/asset/char_conf.txt +++ b/tools/docker/asset/char_conf.txt @@ -1,2 +1,2 @@ -login_ip: 127.0.0.1 +login_ip: login char_ip: 127.0.0.1 diff --git a/tools/docker/asset/map_conf.txt b/tools/docker/asset/map_conf.txt index e7fe50ab48..cf6852e044 100644 --- a/tools/docker/asset/map_conf.txt +++ b/tools/docker/asset/map_conf.txt @@ -1,2 +1,2 @@ -char_ip: 127.0.0.1 +char_ip: char map_ip: 127.0.0.1 diff --git a/tools/docker/builder.sh b/tools/docker/builder.sh new file mode 100755 index 0000000000..be150dd3b8 --- /dev/null +++ b/tools/docker/builder.sh @@ -0,0 +1,21 @@ +if [ ! -f /rathena/login-server ]; then + export runBuild=1; +elif [ ! -f /rathena/char-server ]; then + export runBuild=1; +elif [ ! -f /rathena/map-server ]; then + export runBuild=1; +else + export runBuild=0; +fi + +if [ "${runBuild}" -eq "1" ]; then + ### checking that ./configure has ran by looking for make file + if [ ! -f /rathena/make ]; then + echo "Warning: ./configure will be executed with provided values"; + echo "Make sure you have set the variables you want in the docker-compose.yml file"; + echo $BUILDER_CONFIGURE + ./configure $BUILDER_CONFIGURE + fi + + make clean server; +fi \ No newline at end of file diff --git a/tools/docker/docker-compose.yml b/tools/docker/docker-compose.yml index 0907d7e397..775b7d4fd9 100644 --- a/tools/docker/docker-compose.yml +++ b/tools/docker/docker-compose.yml @@ -14,12 +14,30 @@ services: MYSQL_DATABASE: ragnarok MYSQL_USER: ragnarok MYSQL_PASSWORD: ragnarok - server: + + builder: image: "rathena:local" - container_name: "rathena" + container_name: "rathena-builder" + command: "/rathena/tools/docker/builder.sh" + 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 + environment: + BUILDER_CONFIGURE: "--enable-packetver=20211103" + + login: + image: "rathena:local" + container_name: "rathena-login" + command: sh -c "/bin/wait-for db:3306 -- /rathena/login-server" ports: - - "5121:5121" # map server - - "6121:6121" # char server - "6900:6900" # login server volumes: - "../..:/rathena" # mount git repo directory inside container @@ -34,6 +52,44 @@ services: dockerfile: Dockerfile depends_on: - db + char: + image: "rathena:local" + container_name: "rathena-char" + command: sh -c "/bin/wait-for db:3306 -- /rathena/char-server" + ports: + - "6121:6121" # char 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: + - login + map: + image: "rathena:local" + container_name: "rathena-map" + command: sh -c "/bin/wait-for db:3306 -- /rathena/map-server" + ports: + - "5121:5121" # map 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: + - char volumes: rathenadb: