is-docker-0.2.0/.cargo_vcs_info.json0000644000000001360000000000100127130ustar { "git": { "sha1": "c1e40d4be6ee669e0294cbe55778ad62d69ce16f" }, "path_in_vcs": "" }is-docker-0.2.0/.github/workflows/ci.yaml000064400000000000000000000007111046102023000163560ustar 00000000000000name: Tests on: push: pull_request: schedule: [cron: "40 1 * * *"] permissions: contents: read jobs: test: name: Test on Ubuntu runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust: [stable, beta] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master name: Install toolchain with: toolchain: ${{ matrix.rust }} - run: cargo testis-docker-0.2.0/.gitignore000064400000000000000000000005001046102023000134660ustar 00000000000000# Generated by Cargo # will have compiled files and executables /target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk is-docker-0.2.0/Cargo.lock0000644000000005740000000000100106740ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "is-docker" version = "0.2.0" dependencies = [ "once_cell", ] [[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" is-docker-0.2.0/Cargo.toml0000644000000014770000000000100107220ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] name = "is-docker" version = "0.2.0" authors = ["Sean Larkin "] description = "Checks if the process is running inside a Docker container." readme = "README.md" categories = ["command-line-utilities"] license = "MIT" repository = "https://github.com/TheLarkInn/is-docker" [dependencies.once_cell] version = "1.17.0" is-docker-0.2.0/Cargo.toml.orig000064400000000000000000000006611046102023000143750ustar 00000000000000[package] name = "is-docker" description = "Checks if the process is running inside a Docker container." version = "0.2.0" authors = ["Sean Larkin "] repository = "https://github.com/TheLarkInn/is-docker" license = "MIT" categories = ["command-line-utilities"] [dependencies] once_cell = "1.17.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html is-docker-0.2.0/LICENSE000064400000000000000000000020541046102023000125110ustar 00000000000000MIT License Copyright (c) 2023 Sean Larkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-docker-0.2.0/README.md000064400000000000000000000005321046102023000127620ustar 00000000000000# is-docker Checks if the process is running inside a Docker container. Rust implementation of `sindresorhus/is-docker` ## Usage `$> cargo add is-docker` _main.rs_ ```rust use is_docker::is_docker fn main() { if is_docker() { // Do some docker related stuff 🎇 } else { // Do some different things! <3 } } ``` is-docker-0.2.0/examples/main.rs000064400000000000000000000003051046102023000146110ustar 00000000000000extern crate is_docker; fn main() { if is_docker::is_docker() { println!("Currently in a Docker Container!") } else { println!("Currently NOT in Docker Container!") } }is-docker-0.2.0/src/lib.rs000064400000000000000000000010241046102023000134030ustar 00000000000000extern crate once_cell; use std::fs; use once_cell::sync::OnceCell; fn has_docker_env_file() -> bool { fs::metadata("/.dockerenv").is_ok() } fn has_docker_in_cgroup() -> bool { match fs::read_to_string("/proc/self/cgroup") { Ok(file_contents) => file_contents.contains("docker"), Err(_error) => false, } } pub fn is_docker() -> bool { static CACHED_RESULT: OnceCell = OnceCell::new(); *CACHED_RESULT.get_or_init(|| { has_docker_env_file() || has_docker_in_cgroup() }) }