add xtask to push docker image

This commit is contained in:
Max Känner 2024-09-02 20:00:05 +02:00
parent 0b02efc752
commit 60bd5acd35
2 changed files with 20 additions and 2 deletions

View File

@ -1,8 +1,8 @@
FROM rust:1.80 FROM rust:1.80
COPY . /usr/app COPY battlesnake/ /usr/app
WORKDIR /usr/app WORKDIR /usr/app
RUN cargo install --path battlesnake RUN cargo install --path .
CMD ["battlesnake"] CMD ["battlesnake"]

View File

@ -21,6 +21,7 @@ fn try_main() -> Result<(), DynError> {
match task.as_deref() { match task.as_deref() {
Some("local") => local()?, Some("local") => local()?,
Some("local2") => local2()?, Some("local2") => local2()?,
Some("docker") => docker()?,
_ => print_help(), _ => print_help(),
} }
Ok(()) Ok(())
@ -32,6 +33,8 @@ fn print_help() {
local runs the snake on a local game local runs the snake on a local game
local2 runs the snake twice 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<Child, DynError> {
} }
} }
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 { fn project_root() -> PathBuf {
Path::new(&env!("CARGO_MANIFEST_DIR")) Path::new(&env!("CARGO_MANIFEST_DIR"))
.ancestors() .ancestors()