aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXander <xander@biltopia.org>2023-10-22 12:31:51 +0200
committerXander <xander@biltopia.org>2023-10-22 12:31:51 +0200
commit3ac0ecfec25617e5282f507de615c8ea5a29b69d (patch)
tree3c8539c026c5356947896cf751bfe576461f97ef
parentccee0f7ca6dc2b2542b84922d855f51204033b8a (diff)
downloadplanetwars.dev-3ac0ecfec25617e5282f507de615c8ea5a29b69d.tar.xz
planetwars.dev-3ac0ecfec25617e5282f507de615c8ea5a29b69d.zip
Add containerfile and fix all issues
-rw-r--r--Containerfile29
-rw-r--r--bot.toml7
-rw-r--r--planetwars-server/src/lib.rs4
-rw-r--r--planetwars-server/src/modules/client_api.rs2
-rw-r--r--planetwars-server/src/modules/matches.rs5
-rw-r--r--planetwars-server/src/routes/matches.rs4
-rw-r--r--simplebot/Containerfile4
-rw-r--r--web/pw-server/package.json52
8 files changed, 76 insertions, 31 deletions
diff --git a/Containerfile b/Containerfile
new file mode 100644
index 0000000..9284d9f
--- /dev/null
+++ b/Containerfile
@@ -0,0 +1,29 @@
+FROM rust:latest
+
+RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
+RUN chmod a+r /etc/apt/keyrings/docker.gpg
+RUN echo \
+ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
+ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
+ tee /etc/apt/sources.list.d/docker.list > /dev/null
+RUN apt-get update && apt-get install cmake npm docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
+
+WORKDIR /pw
+
+COPY . .
+
+RUN cargo build --release
+
+RUN cargo install wasm-pack
+
+RUN wasm-pack build web/planetwars-rs --target web
+
+WORKDIR /pw/web/pw-server
+
+RUN npm install --force && npm run build
+
+RUN sed "s/module.exports=y;//" /pw/web/pw-server/.svelte-kit/output/client/_app/chunks/PlayerLog-c14926a0.js -i
+
+WORKDIR /pw/planetwars-server
+
+ENTRYPOINT ["../target/release/planetwars-server", "npm --prefix /pw/web/pw-server run preview -- --host"]
diff --git a/bot.toml b/bot.toml
new file mode 100644
index 0000000..90f776d
--- /dev/null
+++ b/bot.toml
@@ -0,0 +1,7 @@
+# Comand to run when starting the bot.
+# Argv style also supported: ["python", "simplebot.py"]
+command = "python simplebot.py"
+
+# Directory in which to run the command.
+# It is recommended to use an absolute path here.
+working_directory = "/home/planetwars/planetwars.dev/simplebot"
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index 39dd57e..127ff05 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -167,7 +167,7 @@ pub fn get_config() -> Result<GlobalConfig, ConfigError> {
async fn run_registry(config: Arc<GlobalConfig>, db_pool: DbPool) {
// TODO: put in config
- let addr = SocketAddr::from(([127, 0, 0, 1], 9001));
+ let addr = SocketAddr::from(([0, 0, 0, 0], 9001));
axum::Server::bind(&addr)
.serve(
@@ -193,7 +193,7 @@ pub async fn run_app() {
tokio::spawn(run_client_api(global_config.clone(), db_pool.clone()));
// TODO: put in config
- let addr = SocketAddr::from(([127, 0, 0, 1], 9000));
+ let addr = SocketAddr::from(([0, 0, 0, 0], 9000));
let pw_api_service = create_pw_api(global_config, db_pool).into_make_service();
axum::Server::bind(&addr)
diff --git a/planetwars-server/src/modules/client_api.rs b/planetwars-server/src/modules/client_api.rs
index 9c0bbe7..ac4394f 100644
--- a/planetwars-server/src/modules/client_api.rs
+++ b/planetwars-server/src/modules/client_api.rs
@@ -377,7 +377,7 @@ pub async fn run_client_api(runner_config: Arc<GlobalConfig>, pool: ConnectionPo
runner_config,
};
- let addr = SocketAddr::from(([127, 0, 0, 1], 50051));
+ let addr = SocketAddr::from(([0, 0, 0, 0], 50051));
Server::builder()
.add_service(pb::client_api_service_server::ClientApiServiceServer::new(
server,
diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs
index 489a9fa..f5f9f2a 100644
--- a/planetwars-server/src/modules/matches.rs
+++ b/planetwars-server/src/modules/matches.rs
@@ -141,8 +141,9 @@ pub fn bot_version_to_botspec(
}
fn python_docker_bot_spec(config: &GlobalConfig, code_bundle_path: &str) -> Box<dyn BotSpec> {
- let code_bundle_rel_path = PathBuf::from(&config.bots_directory).join(code_bundle_path);
- let code_bundle_abs_path = std::fs::canonicalize(&code_bundle_rel_path).unwrap();
+ let code_bundle_abs_path = PathBuf::from("/home/planetwars/data/bots").join(code_bundle_path);
+ //let code_bundle_abs_path = std::fs::canonicalize(&code_bundle_rel_path).unwrap();
+ println!("{}",code_bundle_abs_path.display());
let code_bundle_path_str = code_bundle_abs_path.as_os_str().to_str().unwrap();
// TODO: it would be good to simplify this configuration
diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs
index 1ae8c27..0b8e5b7 100644
--- a/planetwars-server/src/routes/matches.rs
+++ b/planetwars-server/src/routes/matches.rs
@@ -108,6 +108,10 @@ pub async fn list_recent_matches(
None => matches::list_public_matches(count, params.before, params.after, &mut conn),
};
+ match matches_result {
+ Ok(_) => println!("ok"),
+ Err(ref err) => println!("{}",err)
+ };
let mut matches = matches_result.expect("failed to get matches"); //.map_err(|_| StatusCode::BAD_REQUEST)?;
let mut has_next = false;
diff --git a/simplebot/Containerfile b/simplebot/Containerfile
new file mode 100644
index 0000000..b2b755f
--- /dev/null
+++ b/simplebot/Containerfile
@@ -0,0 +1,4 @@
+FROM python:alpine
+WORKDIR /app
+COPY simplebot.py simplebot.py
+CMD python simplebot.py
diff --git a/web/pw-server/package.json b/web/pw-server/package.json
index e8ade9f..63100d6 100644
--- a/web/pw-server/package.json
+++ b/web/pw-server/package.json
@@ -12,37 +12,37 @@
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"devDependencies": {
- "@originjs/vite-plugin-commonjs": "^1.0.1",
+ "@originjs/vite-plugin-commonjs": "1.0.1",
"@sveltejs/adapter-auto": "next",
- "@sveltejs/kit": "^1.0.0-next.286",
- "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
- "@typescript-eslint/eslint-plugin": "^4.31.1",
- "@typescript-eslint/parser": "^4.31.1",
- "eslint": "^7.32.0",
- "eslint-config-prettier": "^8.3.0",
- "eslint-plugin-svelte3": "^3.2.1",
- "luxon": "^2.3.0",
- "mdsvex": "^0.10.6",
- "prettier": "^2.4.1",
- "prettier-plugin-svelte": "^2.4.0",
- "sass": "^1.49.7",
- "svelte": "^3.52.0",
- "svelte-check": "^2.2.6",
- "svelte-preprocess": "^4.9.4",
- "tslib": "^2.3.1",
- "typescript": "^4.4.3",
- "vite-plugin-iso-import": "^0.1.3"
+ "@sveltejs/kit": "1.0.0-next.286",
+ "@sveltejs/vite-plugin-svelte": "1.0.0-next.49",
+ "@typescript-eslint/eslint-plugin": "4.31.1",
+ "@typescript-eslint/parser": "4.31.1",
+ "eslint": "7.32.0",
+ "eslint-config-prettier": "8.3.0",
+ "eslint-plugin-svelte3": "3.2.1",
+ "luxon": "2.3.0",
+ "mdsvex": "0.10.6",
+ "prettier": "2.4.1",
+ "prettier-plugin-svelte": "2.4.0",
+ "sass": "1.49.7",
+ "svelte": "3.52.0",
+ "svelte-check": "2.2.6",
+ "svelte-preprocess": "4.9.4",
+ "tslib": "2.3.1",
+ "typescript": "4.4.3",
+ "vite-plugin-iso-import": "0.1.3"
},
"dependencies": {
- "@fortawesome/free-solid-svg-icons": "^6.2.0",
- "@sveltejs/adapter-node": "^1.0.0-next.69",
- "@types/luxon": "^2.0.9",
- "ace-builds": "^1.4.14",
- "dayjs": "^1.10.7",
+ "@fortawesome/free-solid-svg-icons": "6.2.0",
+ "@sveltejs/adapter-node": "1.0.0-next.69",
+ "@types/luxon": "2.0.9",
+ "ace-builds": "1.4.14",
+ "dayjs": "1.10.7",
"planetwars-rs": "file:../planetwars-rs/pkg",
"pw-visualizer": "file:../pw-visualizer",
- "svelte-fa": "^3.0.3",
- "svelte-select": "^5.0.0-beta.31"
+ "svelte-fa": "3.0.3",
+ "svelte-select": "5.0.0-beta.31"
},
"type": "module"
}