etcd Bundled in a Crate
This crate provides access to an etcd binary for the purpose of unit testing.
The core of this library is the etcd_bin_path function, which gets a path to an etcd binary which is compatible with
this operating system and architecture.
etcd_bin_path.unwrap;
This is meant to be used as the program for an [std::process::Command].
To quickly spin up an etcd server for testing purposes, do something like this:
// If you want to run multiple etcd servers at a time, you should vary
// the directory and ports.
let data_dir = "/tmp/etcd-data-dir";
let client_port = 2379u16;
let peer_port = 2380u16;
let etcd_path = etcd_bin_path
.expect;
let mut command = new;
command
.arg
.arg
.arg
.arg
.arg
.arg
.arg
.arg;
let mut process = command.spawn.expect;
// Do things with a client library
println!;
// Error handling which makes sense to you, probably in a `Drop` impl
process.kill.expect;
process.wait.expect;
Platform Specific
To minimize library size, the actual binaries are packaged inside of platform-specific libraries.
For example, the etcd-bin-vendored-linux-amd64 crate contains the binary for running
on Linux AMD64.
By default, the platform-specific crate is enabled for the detected target.
In other words, the etcd-bin-vendored-darwin-arm64 package is a required dependency
when you are running on MacOS with ARM64 silicon.
target_os |
target_arch |
Crate |
|---|---|---|
linux |
x86_64 |
etcd-bin-vendored-linux-amd64 |
linux |
aarch64 |
etcd-bin-vendored-linux-arm64 |
linux |
powerpc64 |
etcd-bin-vendored-linux-ppc64le |
linux |
s390x |
etcd-bin-vendored-linux-s390x |
macos |
x86_64 |
etcd-bin-vendored-darwin-amd64 |
macos |
aarch64 |
etcd-bin-vendored-darwin-arm64 |
windows |
x86_64 |
etcd-bin-vendored-windows-amd64 |
Note: Naming
There is a bit of incongruity between
target_osandtarget_archnames and their respective crate names; e.g.: thetarget_os = "macos"andtarget_arch = "aarch64"maps to theetcd-bin-vendored-darwin-arm64crate. This is because the Rust conventions fortarget_osandtarget_archare different from theGOOSandGOARCHplatform conventions, whichetcduses directly. My thinking is that someone looking to pull a specific binary will be more familiar with Go conventions, so the crates keep the Go suffixes.
Versioning
The versions of this library match the etcd version.
So, pulling this library at version 3.6.5 means you get the binaries for etcd release 3.6.5.
Caveats
Not Suitable for Distribution
This crate is not useful for distributing etcd to your application.
It merely pulls the etcd binary from its own Cargo manifest.
If you try to use this function outside of a Cargo test on the system it was built on, it will not work.
The advantage of this is that it makes it impossible to use this in production.
That is an advantage because you should not be running a critical service like etcd from a binary you pulled from some
random crate.
This is for unit/integration testing only.
Security
This crate gives you a binary blob ultimately downloaded from etcd releases on GitHub.
Before running anything changing library versions, you should verify that the binary downloaded by this library matches
what you find on the release.
Note that this library gives the executable inside the archive (etcd/etcd.exe), not the whole archive, so the SHA
sums listed on GitHub will not match; you have to download the archive, unpack it, and do this yourself.
If an etcd release gets yanked for security reasons, I will also yank it from Crates.
If I have not done this, open an issue with a "security" tag.