Skip to content

Commit

Permalink
Add support for arm64.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeleveringham committed Oct 2, 2023
1 parent 0404897 commit 6d14ae9
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ DISCORD_CHANNEL_ID=
SERVER_INSTALL_DIRECTORY=
SERVER_TYPE=bedrock
JAVA_MEMORY_MIN=1024
JAVA_MEMORY_MAX=1024
JAVA_MEMORY_MAX=1024
IS_ARM64=false
12 changes: 12 additions & 0 deletions Dockerfile-bedrock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ ENV PATH="${PATH}:/root/.local/bin"
RUN wget "https://minecraft.azureedge.net/bin-linux/bedrock-server-1.20.15.01.zip" -O server.zip
RUN unzip server.zip -d server/

ARG TARGETARCH
RUN if [ "$TARGETARCH" != "arm64" ] ; then \
echo "Not targetting arm64, skipping box64 install" \
; else \
apt install -y git build-essential cmake && \
git clone https://github.com/ptitSeb/box64.git && \
cd box64 && mkdir build && cd build && \
cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo && \
make -j$(nproc) && make install && \
cd /craftlink \
; fi

COPY poetry.lock pyproject.toml ./
COPY . .

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ Optional arguments:
- `-y`, `--server-type`, `SERVER_TYPE` - Type of server to be run ("bedrock" or "java"), defaults to bedrock.
- `-m`, `--java-memory-min`, `JAVA_MEMORY_MIN` - (Java only) minimum server memory to allocate, defaults to 1024.
- `-x`, `--java-memory-max`, `JAVA_MEMORY_MAX` - (Java only) maximum server memory to allocate, defaults to 1024.
- `-is-arm64`, `IS_ARM64` - Flag to indicate running on arm64 architecture.

### ARM64 and Bedrock

You must use the switch `--isarm-64` and set the environment variable `IS_ARM64`
so the command is dispatched correctly.

The Bedrock binary is meant for x86_64 architecture; to get it to run
on arm64 devices, [`box64`](https://github.com/ptitSeb/box64) emulation is used.

If building the Bedrock Docker image, specify `--platform=linux/arm64` and
`box64` will be installed automatically.

Otherwise, ensure your system has `box64` installed and available in the `PATH`.

(Shoutout to [this issue comment](https://github.com/itzg/docker-minecraft-bedrock-server/issues/140#issuecomment-1126406059)
from [`docker-minecraft-bedrock-server`](https://github.com/itzg/docker-minecraft-bedrock-server)
for pointing me in the right direction here.)

### Docker

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
# Server directory env var inside the container will be different.
environment:
SERVER_INSTALL_DIRECTORY: "/craftlink/server/"
# Uncomment this if using image on arm64 arch machine.
#IS_ARM64: "true"
volumes:
- "${SERVER_INSTALL_DIRECTORY}/allowlist.json:/craftlink/server/allowlist.json"
- "${SERVER_INSTALL_DIRECTORY}/permissions.json:/craftlink/server/permissions.json"
Expand Down
2 changes: 2 additions & 0 deletions src/craftlink/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
channel_id: str,
server_type: str,
java_mem_range: tuple[int],
use_box64: bool,
) -> None:
self.token = token
self.server_type = server_type
Expand All @@ -31,6 +32,7 @@ def __init__(
self.server_message_queue,
server_type,
java_mem_range,
use_box64,
)
self.channel_id = int(channel_id)
intents = discord.Intents.default()
Expand Down
5 changes: 5 additions & 0 deletions src/craftlink/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def __init__(
server_message_queue: deque,
server_type: str,
java_mem_range: tuple[int],
use_box64: bool,
) -> None:
self.server_type = server_type
self.use_box64 = use_box64
self.server_proc = None
self.server_message_queue = server_message_queue
if not server_path.is_dir():
Expand Down Expand Up @@ -166,8 +168,11 @@ async def _cmd_startserver(self, *args) -> str:
return "The server is already running."
if self.server_type == "bedrock":
server_cmd = [self.server_cmd]
if self.use_box64:
server_cmd.insert(0, "box64")
elif self.server_type == "java":
server_cmd = self.server_cmd.split(" ")
LOGGER.info(f"Starting process: {' '.join(server_cmd)}")
self.server_proc = (
await asyncio.subprocess.create_subprocess_exec(
*server_cmd,
Expand Down
13 changes: 13 additions & 0 deletions src/craftlink/console.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import json
import logging
import os
from argparse import ArgumentParser
Expand All @@ -21,6 +22,7 @@ async def amain(options):
channel_id=options.channel_id,
server_type=options.server_type,
java_mem_range=(options.java_memory_min, options.java_memory_max),
use_box64=options.is_arm64,
) as bot:
await bot.run()

Expand Down Expand Up @@ -72,7 +74,18 @@ def main():
required=False,
help="(Java only) maximum server memory to allocate, defaults to 1024.",
)
parser.add_argument(
"--is-arm64",
action="store_true",
required=False,
help="Flag to indicate running on arm64 architecture.",
)
options = parser.parse_args()
try:
if json.loads(os.environ.get("IS_ARM64")):
options.is_arm64 = True
except json.JSONDecodeError:
LOGGER.warning("Invalid value given for IS_ARM64.")
try:
asyncio.run(amain(options))
except KeyboardInterrupt:
Expand Down

0 comments on commit 6d14ae9

Please sign in to comment.