首页 > 解决方案 > Github Actions + docker-compose 给出“没有这样的文件或目录”

问题描述

我正在用 Rust 为 Github Actions 编写 CI。docker-compose由于某些原因,我想从 Rust 执行。在 中Command,我在 docker-compose.yml 所在的文件夹中指定了当前工作目录。这是一些代码:

let docker_compose_file = current_dir.parent().unwrap().to_owned();

if docker_compose_file.join("docker-compose.yml").exists() {
    println!(
        "Found docker-compose file, full path: {:#?}",
        docker_compose_file
    );

    // DEBUG CODE
    let ls_result = Command::new("ls")
        .arg(docker_compose_file.to_str().unwrap())
        .output()
        .unwrap()
        .stdout;

    let y = String::from_utf8(ls_result).unwrap();

    println!("LS'ing gives: {:#?}", y);
} else {
    panic!(
        "Wrong file, current working dir: {:#?}",
        docker_compose_file
    );
}

let result = Command::new("docker-compose")
    .current_dir(&docker_compose_file)
    .args(&["up", "-d"])
    .status()
    .unwrap();

我在 Github Actions 中看到以下日志记录:

找到 docker-compose 文件,完整路径:“/Users/runner/work/something/something/server” LS'ing 给出:“Cargo.lock\nCargo.toml\napi\nbatch_jobs\nci_setup\ncommon\ndatabase\ndeployment.md \ndocker-compose.yml\nrustfmt.toml\nserver\ntarget\n" 线程 'main' 在'调用Result::unwrap()一个Err 值:Os { 代码:2,种类:NotFound,消息:“没有这样的文件或目录”}' , ci_setup/src/main.rs:137:14 注意:使用 RUST_BACKTRACE=1环境变量运行以显示回溯

我很困惑。ls清楚地向我展示了 docker-compose.yml 文件存在。为什么我会收到 Rust 错误,说找不到文件或目录?

main.rs:137 指unwrap的是代码示例底部的方法调用。

标签: dockerrustdocker-composegithub-actions

解决方案


推荐阅读