#copy

replicate

Copies the currently running program into a temporary location

2 releases

Uses new Rust 2021

0.1.1 Nov 12, 2022
0.1.0 Nov 11, 2022

#794 in Development tools

44 downloads per month

MIT license

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]:

  1. The copy has a short lifetime and your temporary file cleaner is sane (doesn’t delete recently accessed files).
  2. You trust every user on your system (i.e. you are the only user).
  3. You have disabled your system’s temporary file cleaner or verified that your system doesn’t have a temporary file cleaner.

Dependencies

~0.8–1.3MB
~26K SLoC