Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Integration of Opencraft into Continuum #13

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions application/opencraft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Building the Application
Notice that Opencraft is hosted in a private repository.
In order to be able to build Opencraft using Ansible, you need to have a ssh-key added to your key manager that has access to the repository.

To do that, execute
```
eval $(ssh-agent)
ssh-add path/to/private/key/with/access
```

## Publisher
For the publisher, simply execute the `docker.sh` script to build it.

To be able to build the _linux/arm64_ architecture, you will need to install Docker Desktop.
Once installed and running, you can check with `docker buildx ls` if a driver is selected that supports the architecture.
This is indicated by the `*` behind the name.
If this is not the case and you see `desktop-linux` in the list, execute
```
docker buildx create --use desktop-linux
```
This will create a new driver based on Docker Desktop and select it as the default.
This change does not persist across reboots.

## Subscriber
For the subscriber, execute
```
ansible-playbook build_server.yml -v
```
which will then run Ansible locally to build and push the server/subscriber.
26 changes: 26 additions & 0 deletions application/opencraft/launch_benchmark_kubeedge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- hosts: cloudcontroller
become: true
tasks:
- name: Create job file
template:
src: template_server.yml.j2
dest: /home/{{ username }}/job-template.yaml

- name: Create job directory
file:
path: /home/{{ username }}/jobs
state: directory

- name: Create job multiple times
shell: |
for i in `seq 0 {{ replicas }}`
do
cat "/home/{{ username }}/job-template.yaml" | sed "s/\%ITEM/$i/" \
> "/home/{{ username }}/jobs/job-$i.yaml"
done

- name: Launch jobs
command: >
kubectl create --kubeconfig="/home/{{ username }}/.kube/config"
-f "/home/{{ username }}/jobs"
26 changes: 26 additions & 0 deletions application/opencraft/launch_benchmark_kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- hosts: cloudcontroller
become: true
tasks:
- name: Create job file
template:
src: template_server.yml.j2
dest: /home/{{ username }}/job-template.yaml

- name: Create job directory
file:
path: /home/{{ username }}/jobs
state: directory

- name: Create job multiple times
shell: |
for i in `seq 0 {{ replicas }}`
do
cat "/home/{{ username }}/job-template.yaml" | sed "s/\%ITEM/$i/" \
> "/home/{{ username }}/jobs/job-$i.yaml"
done

- name: Launch jobs
command: >
kubectl create --kubeconfig="/home/{{ username }}/.kube/config"
-f "/home/{{ username }}/jobs"
15 changes: 15 additions & 0 deletions application/opencraft/publisher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14.21.1-alpine

ENV HOST=127.0.0.1
ENV PORT=25565
ENV USERNAME=Steve
ENV BOX_WIDTH=500
ENV NUMBER_STEPS=10000

# get dependencies
COPY src/package.json package.json
RUN npm install --loglevel verbose

COPY src/worker_bot.js worker_bot.js

CMD node worker_bot.js
2 changes: 2 additions & 0 deletions application/opencraft/publisher/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker buildx build --platform linux/amd64,linux/arm64 -t lwagner1/opencraft_benchmark:opencraft_bot --push .
7 changes: 7 additions & 0 deletions application/opencraft/publisher/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"mineflayer": "4.6.0",
"mineflayer-pathfinder": "2.4.2",
"vec3": "0.1.7"
}
}
77 changes: 77 additions & 0 deletions application/opencraft/publisher/src/worker_bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

const mineflayer = require('mineflayer');
const pathfinder = require('mineflayer-pathfinder').pathfinder
const Movements = require('mineflayer-pathfinder').Movements
const { GoalNear, GoalXZ } = require('mineflayer-pathfinder').goals
const v = require("vec3");

const host = process.env.HOST
const port = parseInt(process.env.PORT)
const username = process.env.USERNAME
const box_width = parseInt(process.env.BOX_WIDTH)
const number_steps = parseInt(process.env.NUMBER_STEPS)

const upper_limit_random_position = 1000
let initial_random_x = getRandomInt(upper_limit_random_position)
let initial_random_z = getRandomInt(upper_limit_random_position)
const box_center = v(5, -60, 2);

function getRandomInt(max) {
return Math.floor(Math.random() * max);
}

function nextGoal(bot) {
let x = box_center.x + getRandomInt(box_width) - (box_width / 2);
let z = box_center.z + getRandomInt(box_width) - (box_width / 2);
console.log(`${username} should go to ${x} and ${z}`)
//console.log(`bot ${bot.username} should walk from ${bot.entity.position} to ${v(x, bot.entity.position.y, z)}`)
return new GoalXZ(x, z);
}

function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

console.log(`Creating bot with name ${username} connecting to ${host}:${port}`)
let worker_bot = mineflayer.createBot({
host: host, // opencraft server ip
username: username, // opencraft username
port: port, // only set if you need a port that isn't 25565
});
worker_bot.on('kicked', console.log)
worker_bot.on('error', console.log)
worker_bot.loadPlugin(pathfinder)



worker_bot.once("spawn", async () => {
box_center.x = worker_bot.entity.position.x
box_center.z = worker_bot.entity.position.z
let defaultMove = new Movements(worker_bot)
defaultMove.allowSprinting = false
defaultMove.canDig = false
worker_bot.pathfinder.setMovements(defaultMove)
// worker_bot.pathfinder.thinkTimeout = 60000 // max 60 seconds to find path from start to finish
let step = 0
while (step < number_steps) {
console.log(step)
let goal = nextGoal(worker_bot);
try {
await worker_bot.pathfinder.goto(goal)
} catch (e) {
// if the bot cannot find a path, carry on and let it try to move somewhere else
if (e.name != "NoPath" && e.name != "Timeout") {
console.log(`${username} died :-(`)
throw e
}
}
step += 1
}
worker_bot.chat(`${username} is done!`)
worker_bot.quit(`${username} is done!`)

process.exit(0)
});
// parentPort.postMessage({});
48 changes: 48 additions & 0 deletions application/opencraft/subscriber/build_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
- hosts: localhost
connection: local
tasks:
- name: Checkout Opencraft
git:
repo: '[email protected]:atlarge-research/opencraft-dev.git'
version: 'dev'
dest: '/tmp/opencraft'

- name: Copy configuration file to server directory
copy:
src: './opencraft.yml'
dest: '/tmp/opencraft/opencraft.yml'
remote_src: true

- name: Copy start file to server directory
copy:
src: './start.sh'
dest: '/tmp/opencraft/start.sh'
remote_src: true

- name: Change image to Alpine # Amazon Linux 2 does not have tools installed to kill processes
lineinfile:
path: '/tmp/opencraft/Dockerfile'
search_string: 'FROM amazoncorretto:8'
line: 'FROM amazoncorretto:8-alpine'

- name: Add configuration file to dockerfile
blockinfile:
path: '/tmp/opencraft/Dockerfile'
insertbefore: 'CMD ["java", "-jar", "opencraft.jar"]'
block: |
COPY --from=builder /usr/src/opencraft/start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
COPY ./opencraft.yml /config/opencraft.yml

- name: Output server values # Amazon Linux 2 does not have tools installed to kill processes
lineinfile:
path: '/tmp/opencraft/Dockerfile'
search_string: 'CMD ["java", "-jar", "opencraft.jar"]'
line: 'CMD ["start.sh"]'


- name: Build and push image
shell:
cmd: 'docker buildx build --platform linux/amd64 -t lwagner1/opencraft_benchmark:opencraft_server --push .'
chdir: '/tmp/opencraft'
149 changes: 149 additions & 0 deletions application/opencraft/subscriber/opencraft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# opencraft.yml is the main configuration file for a Opencraft server
# It contains everything from server.properties and bukkit.yml in a
# normal CraftBukkit installation.

opencraft:
collector: false
logging:
events: true
overload-breaker: false
kludge:
cache-chunks: false
messaging:
type: dyconit
policy: chunk
merge: false
broker:
type: read-write
async: true
threads: 8
capacity: 2147483647
channel: unsafe
host: localhost
port: 0
username: ''
password: ''
virtualHost: ''
chunk-population:
policy: default
filterBCM: 'true'
function: ''
provider: azure
endpoint: ''
storage:
provider: default
sastoken: ''
endpoint: ''
container: ''
cacheregionpolicy: distance
distance: 0
player-operation:
provider: default
endpoint: ''
time-simulation:
provider: default
endpoint: ''
weather-simulation:
provider: default
endpoint: ''
server:
ip: ''
port: 25565
name: Opencraft Server
log-file: logs/log-%D.txt
online-mode: false
max-players: 999
whitelisted: false
motd: An Opencraft server
shutdown-message: Server shutting down.
allow-client-mods: true
dns: []
log-level: INFO
autosave: true
snooper-enabled: false
prevent-proxy-connections: true
console:
use-jline: false
prompt: '> '
date-format: HH:mm:ss
log-date-format: yyyy/MM/dd HH:mm:ss
log-level: INFO
game:
gamemode: CREATIVE
gamemode-force: true
difficulty: NORMAL
hardcore: false
pvp: true
max-build-height: 256
announce-achievements: true
allow-flight: false
command-blocks: false
resource-pack: ''
resource-pack-hash: ''
creatures:
enable:
monsters: false
animals: false
npcs: false
limit:
monsters: 70
animals: 15
water: 5
ambient: 15
ticks:
monsters: 1
animal: 400
folders:
plugins: plugins
update: update
worlds: worlds
libraries: lib
files:
permissions: permissions.yml
commands: commands.yml
help: help.yml
advanced:
connection-throttle: 4000
idle-timeout: 0
warn-on-overload: true
exact-login-location: false
plugin-profiling: false
deprecated-verbose: 'false'
compression-threshold: 256
proxy-support: false
player-sample-count: 12
graphics-compute:
enable: false
use-any-device: false
region-file:
cache-size: 256
compression: true
profile-lookup-timeout: 5
suggest-player-name-when-null-tab-completions: true
extras:
query-enabled: false
query-port: 25614
query-plugins: true
rcon-enabled: false
rcon-password: opencraft
rcon-port: 25575
rcon-colors: true
world:
name: world
seed: ''
level-type: FLAT
spawn-radius: 16
view-distance: 8
gen-structures: true
allow-nether: true
allow-end: true
keep-spawn-loaded: true
populate-anchored-chunks: true
classic-style-water: false
disable-generation: false
libraries:
checksum-validation: true
repository-url: https://repo1.maven.org/maven2/
download-attempts: 2
compatibility-bundle: CRAFTBUKKIT
list: []
4 changes: 4 additions & 0 deletions application/opencraft/subscriber/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

java -jar opencraft.jar
cat /opencraft-events.log
Loading