diff --git a/Dockerfile b/Dockerfile index d39956a..bb0c7af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM rust:1.80 -COPY . /usr/app +COPY battlesnake/ /usr/app WORKDIR /usr/app -RUN cargo install --path battlesnake +RUN cargo install --path . CMD ["battlesnake"] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6c5a8b3..d2f6f10 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,6 +21,7 @@ fn try_main() -> Result<(), DynError> { match task.as_deref() { Some("local") => local()?, Some("local2") => local2()?, + Some("docker") => docker()?, _ => print_help(), } Ok(()) @@ -32,6 +33,8 @@ fn print_help() { local runs the snake on a local game local2 runs the snake twice on a local game + +docker package docker image and upload to docker.mkaenner.de/snake " ) } @@ -120,6 +123,21 @@ fn run_snake(port: u16) -> Result { } } +fn docker() -> Result<(), DynError> { + if !Command::new("docker") + .current_dir(project_root()) + .args(["build", ".", "-t", "docker.mkaenner.de/snake"]) + .status()? + .success() + { + Err("Build of docker image failed")?; + } + Command::new("docker") + .args(["push", "docker.mkaenner.de/snake"]) + .status()?; + Ok(()) +} + fn project_root() -> PathBuf { Path::new(&env!("CARGO_MANIFEST_DIR")) .ancestors()