Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
coord-e committed May 5, 2020
2 parents 29b5bf3 + 7d21c23 commit b0e0251
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: push
on: [push, pull_request]

name: Test and Lint

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [1.1.0] - 2020-05-05

- Fixed the order of `-ldl` option in resolver compilation. (#[1](https://github.com/coord-e/magicpak/pulls/1))

## [1.0.3] - 2020-04-14

- Fixed `--test` behavior when the resulting bundle contains `/bin/`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "magicpak"
version = "1.0.3"
version = "1.1.0"
authors = ["coord.e <me@coord-e.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ That's it! The resulting image shall only contain what your executable requires
- **Flexible**. We expose a full control of resulting bundle with a family of options like `--include` and `--exclude`. You can deal with dependencies that cannot be detected automatically.
- **Stable**. We don't parse undocumented and sometimes inaccurate ldd(1) outputs. Instead, we use dlopen(3) and dlinfo(3) in glibc to query shared library locations to ld.so(8).

`magicpak` is especially useful when you find it difficult to produce a statically linked executable. Also, `magicpak` is powerful when building from source is bothering or the source code is not public, because `magicpak` only requires the executable to build a minimal docker image.

## Usage

You can start with `magicpak path/to/executable path/to/output`. This simply analyzes runtime dependencies of your executable statically and put everything your executable needs in runtime to the specified output directory. Once they've bundled, we can simply copy them to the `scratch` image in the second stage as follows.
Expand Down Expand Up @@ -82,36 +84,36 @@ We provide some base images that contain `magicpak` and its optional dependencie

| name | description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [magicpak/debian ![magicpak/debian](https://img.shields.io/docker/image-size/magicpak/debian?sort=date)](https://hub.docker.com/r/magicpak/debian) | [library/debian](http://hub.docker.com/_/debian) with `magicpak` |
| [magicpak/cc ![magicpak/cc](https://img.shields.io/docker/image-size/magicpak/cc?sort=date)](https://hub.docker.com/r/magicpak/cc) | [library/debian](http://hub.docker.com/_/debian) with `build-essential`, `clang`, and `magicpak` |
| [magicpak/haskell ![magicpak/haskell](https://img.shields.io/docker/image-size/magicpak/haskell?sort=date)](https://hub.docker.com/r/magicpak/haskell) | [library/haskell](http://hub.docker.com/_/haskell) with `magicpak` |
| [magicpak/rust ![magicpak/rust](https://img.shields.io/docker/image-size/magicpak/rust?sort=date)](https://hub.docker.com/r/magicpak/rust) | [library/rust](http://hub.docker.com/_/rust) with `magicpak` |
| [magicpak/debian ![magicpak/debian](https://img.shields.io/docker/pulls/magicpak/debian)](https://hub.docker.com/r/magicpak/debian) | [library/debian](http://hub.docker.com/_/debian) with `magicpak` |
| [magicpak/cc ![magicpak/cc](https://img.shields.io/docker/pulls/magicpak/cc)](https://hub.docker.com/r/magicpak/cc) | [library/debian](http://hub.docker.com/_/debian) with `build-essential`, `clang`, and `magicpak` |
| [magicpak/haskell ![magicpak/haskell](https://img.shields.io/docker/pulls/magicpak/haskell)](https://hub.docker.com/r/magicpak/haskell) | [library/haskell](http://hub.docker.com/_/haskell) with `magicpak` |
| [magicpak/rust ![magicpak/rust](https://img.shields.io/docker/pulls/magicpak/rust)](https://hub.docker.com/r/magicpak/rust) | [library/rust](http://hub.docker.com/_/rust) with `magicpak` |

### Example

The following is a dockerfile using `magicpak` for a docker image of [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html), a formatter for C-like languages. ([example/clang-format](/example/clang-format))
The following is a dockerfile using `magicpak` for a docker image of [`brittany`](https://github.com/lspitzner/brittany), a formatter for Haskell. The resulting image size is just 15.6MB. ([example/brittany](/example/brittany))

```dockerfile
FROM magicpak/debian

RUN apt-get -y update
RUN apt-get -y --no-install-recommends install clang-format

RUN magicpak $(which clang-format) /bundle -v \
--compress \
--upx-arg --best \
--upx-arg --brute \
--test \
--test-stdin "int main( ){ }" \
--test-stdout "int main() {}" \
FROM magicpak/haskell:8

RUN cabal new-update
RUN cabal new-install brittany

RUN magicpak $(which brittany) /bundle -v \
--dynamic \
--dynamic-stdin "a = 1" \
--compress \
--upx-arg -9 \
--upx-arg --brute \
--test \
--test-stdin "a= 1" \
--test-stdout "a = 1" \
--install-to /bin/

FROM scratch
COPY --from=0 /bundle /.

WORKDIR /workdir

CMD ["/bin/clang-format"]
CMD ["/bin/brittany"]
```

## Disclaimer
Expand Down
8 changes: 4 additions & 4 deletions dockerfile/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"args": {
"BUSYBOX_VERSION": "1.31.0-defconfig-multiarch-musl",
"UPX_VERSION": "3.96",
"MAGICPAK_VERSION": "1.0.3",
"MAGICPAK_VERSION": "1.1.0",
"DEBIAN_PACKAGES": ""
}
},
Expand All @@ -17,7 +17,7 @@
"args": {
"BUSYBOX_VERSION": "1.31.0-defconfig-multiarch-musl",
"UPX_VERSION": "3.96",
"MAGICPAK_VERSION": "1.0.3",
"MAGICPAK_VERSION": "1.1.0",
"DEBIAN_PACKAGES": ""
}
},
Expand All @@ -28,7 +28,7 @@
"args": {
"BUSYBOX_VERSION": "1.31.0-defconfig-multiarch-musl",
"UPX_VERSION": "3.96",
"MAGICPAK_VERSION": "1.0.3",
"MAGICPAK_VERSION": "1.1.0",
"DEBIAN_PACKAGES": "build-essential clang"
}
},
Expand All @@ -39,7 +39,7 @@
"args": {
"BUSYBOX_VERSION": "1.31.0-defconfig-multiarch-musl",
"UPX_VERSION": "3.96",
"MAGICPAK_VERSION": "1.0.3",
"MAGICPAK_VERSION": "1.1.0",
"DEBIAN_PACKAGES": ""
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/domain/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Executable {
// NOTE: We expect `fs::remove_file` to remove the file immediately, though the
// documentation says 'there is no guarantee that the file is immediately deleted'.
fs::remove_file(&result_path)?;
debug_assert!(!result_path.exists());
assert!(!result_path.exists());
let output = Command::new(upx_path.as_ref())
.args(upx_opts)
.arg("--no-progress")
Expand All @@ -188,7 +188,7 @@ fn default_interpreter<P>(exe: P) -> Result<Option<PathBuf>>
where
P: AsRef<Path>,
{
// from ldd(1); TODO: deal with hardcoded paths
// from the source code of ldd(1); TODO: deal with hardcoded paths
let rtld_list = &[
"/usr/lib/ld-linux.so.2",
"/usr/lib64/ld-linux-x86-64.so.2",
Expand Down
4 changes: 2 additions & 2 deletions src/domain/executable/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ where
let source_path = source.into_temp_path();

let output = Command::new(cc_path.as_ref())
.arg("-xc")
.arg(&source_path)
.arg(format!("-Wl,-dynamic-linker,{}", interp.as_ref().display()))
.arg("-ldl")
.arg("-o")
.arg(program_path.as_ref())
.arg("-xc")
.arg(&source_path)
.output_with_log()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
Expand Down
10 changes: 5 additions & 5 deletions src/domain/executable/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ where
S: AsRef<OsStr>,
T: AsRef<OsStr>,
{
match *s {
[b'O', b'R', b'I', b'G', b'I', b'N'] => origin.as_ref().to_owned(),
[b'L', b'I', b'B'] => match is_64bit(&platform) {
match s {
b"ORIGIN" => origin.as_ref().to_owned(),
b"LIB" => match is_64bit(&platform) {
Some(true) => OsStr::new("lib64").to_owned(),
Some(false) => OsStr::new("lib").to_owned(),
None => {
Expand All @@ -200,7 +200,7 @@ where
OsStr::new("lib").to_owned()
}
},
[b'P', b'L', b'A', b'T', b'F', b'O', b'R', b'M'] => platform.as_ref().to_owned(),
b"PLATFORM" => platform.as_ref().to_owned(),
_ => {
warn!(
"search_paths: unknown token string ${}",
Expand All @@ -225,7 +225,7 @@ where
#[cfg(target_env = "gnu")]
const AT_PLATFORM: libc::c_ulong = libc::AT_PLATFORM;
#[cfg(not(target_env = "gnu"))]
const AT_PLATFORM: libc::c_ulong = 15;
const AT_PLATFORM: libc::c_ulong = 15; // TODO: ad-hoc constant

fn auxv_platform() -> Result<OsString> {
let cstr = unsafe {
Expand Down

0 comments on commit b0e0251

Please sign in to comment.