2 releases
0.1.1 | Nov 12, 2022 |
---|---|
0.1.0 | Nov 11, 2022 |
#1226 in Development tools
7KB
63 lines
replicate
replicate is a library that:
- copies the currently running program to a temporary file
- (Unix-only) makes that file executable
- returns a path object to the temporary file, that cleans up the temporary file when dropped.
It's intended to be used by musl-compiled programs which can run inside Docker containers; by creating a copy and then volume-mounting that program within the Docker container.
Examples
use replicate::Replicate;
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let copy = Replicate::new()?;
println!("My copy's path is {}", copy.display());
Ok(())
}
Additional examples are in the examples directory.
lib.rs
:
Copies the currently running program into a temporary location
This crate copies the currently running executable into a temporary location and returns the path to that executable. This allows you to (for example):
- Compile a program statically using something like musl
- Create a copy of that program while it's running
- Run Docker from your original program, mounting the copy as a Docker volume mount
- Run the copied program from within the Dockerized environment.
Because this library uses NamedTempFile
via Builder
to generate a temporary location,
the following security restrictions apply to Replicate
:
- The copy has a short lifetime and your temporary file cleaner is sane (doesn’t delete recently accessed files).
- You trust every user on your system (i.e. you are the only user).
- You have disabled your system’s temporary file cleaner or verified that your system doesn’t have a temporary file cleaner.
Dependencies
~4–12MB
~167K SLoC