Improve docker-compose tool (#6344)

This commit is contained in:
Danilo Lemes 2022-02-06 07:49:58 +00:00 committed by GitHub
parent 6ccf15330e
commit 70220e16f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 98 additions and 9 deletions

View File

@ -1,4 +1,5 @@
FROM alpine:3.11 FROM alpine:3.11
WORKDIR /rathena WORKDIR /rathena
RUN apk add --no-cache git cmake make gcc g++ gdb zlib-dev mariadb-dev ca-certificates linux-headers bash valgrind RUN apk add --no-cache wget git cmake make gcc g++ gdb zlib-dev mariadb-dev ca-certificates linux-headers bash valgrind netcat-openbsd
ENTRYPOINT [ "bash" ] RUN wget https://raw.githubusercontent.com/eficode/wait-for/v2.2.2/wait-for -O /bin/wait-for && chmod +x /bin/wait-for
ENTRYPOINT [ ]

View File

@ -5,9 +5,20 @@ Note that this Dockerized environment **is not suitable** for production deploym
### How to setup a local development environment :computer: ### 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) 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 ...) 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 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: #### Tips & tricks for local development :beginner:

View File

@ -1,2 +1,2 @@
login_ip: 127.0.0.1 login_ip: login
char_ip: 127.0.0.1 char_ip: 127.0.0.1

View File

@ -1,2 +1,2 @@
char_ip: 127.0.0.1 char_ip: char
map_ip: 127.0.0.1 map_ip: 127.0.0.1

21
tools/docker/builder.sh Executable file
View File

@ -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

View File

@ -14,12 +14,30 @@ services:
MYSQL_DATABASE: ragnarok MYSQL_DATABASE: ragnarok
MYSQL_USER: ragnarok MYSQL_USER: ragnarok
MYSQL_PASSWORD: ragnarok MYSQL_PASSWORD: ragnarok
server:
builder:
image: "rathena:local" 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: ports:
- "5121:5121" # map server
- "6121:6121" # char server
- "6900:6900" # login server - "6900:6900" # login server
volumes: volumes:
- "../..:/rathena" # mount git repo directory inside container - "../..:/rathena" # mount git repo directory inside container
@ -34,6 +52,44 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
depends_on: depends_on:
- db - 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: volumes:
rathenadb: rathenadb: