Permalink
Browse files

Add Makefile for static muslrust Docker build

  • Loading branch information...
uklotzde committed Oct 24, 2018
1 parent 82ad875 commit 9258c238531871199760d0d3acbe800a41a5b612
Showing with 63 additions and 1 deletion.
  1. +34 −0 Makefile.x86_64-unknown-linux-musl
  2. +29 −1 README.md
@@ -0,0 +1,34 @@
BUILD_PROJECT=openfairdb

BUILD_TARGET_BIN=openfairdb
BUILD_TARGET_ARCH=x86_64-unknown-linux-musl

BUILD_IMAGE=clux/muslrust:$(file < rust-toolchain)

BUILD_ROOT=/tmp/muslrust
BUILD_CARGO_CACHE=$(BUILD_ROOT)/cargo-cache
BUILD_PROJECT_ROOT=$(BUILD_ROOT)/$(BUILD_PROJECT)

.PHONY: default
default: build

# Pull the build image from DockerHub (initially or update)
pre-build:
docker pull docker.io/$(BUILD_IMAGE)

build:
mkdir -p "$(BUILD_CARGO_CACHE)"
mkdir -p "$(BUILD_PROJECT_ROOT)"
rsync -av --chown `id -gn`:`id -un` --progress . "$(BUILD_PROJECT_ROOT)" --exclude target --exclude .git
docker run --rm \
-it $(BUILD_IMAGE) \
rustc --version
docker run --rm \
-v "$(BUILD_CARGO_CACHE)":/root/.cargo:Z \
-v "$(BUILD_PROJECT_ROOT)":/volume:Z \
-w /volume \
-it $(BUILD_IMAGE) \
cargo build --bin=$(BUILD_TARGET_BIN) --release
strip "$(BUILD_PROJECT_ROOT)/target/$(BUILD_TARGET_ARCH)/release/$(BUILD_TARGET_BIN)"
mkdir -p bin/$(BUILD_TARGET_ARCH)
cp "$(BUILD_PROJECT_ROOT)/target/$(BUILD_TARGET_ARCH)/release/$(BUILD_TARGET_BIN)" bin/$(BUILD_TARGET_ARCH)
@@ -69,7 +69,7 @@ For the following requests one must be logged in:
`bbox-subscriptions` are subscriptions to a certain map area (bounding box,`bbox`): whenever a new entry is created or an entry is changed within that area, an email notification is sent to the user.

### Entry Export
**Example**: Export all entries in Germany:
**Example**: Export all entries in Germany:
http://api.ofdb.io/v0/export/entries.csv?bbox=47.497972542230855,0.7996758709088782,54.63407558981465,18.307256321725717

If you want to find out the coordinates for other map areas, open "network" in the "developer tools" in your browser and look at the search request under at the value of `bbox`.
@@ -230,6 +230,34 @@ On NixOS you can build the project with:
nix-build -E '(import <nixpkgs>{}).callPackage ./default.nix {}'
```

### Docker Build

The bundled Makefile can be used to build a static executable without installing any dependencies locally.

Depending on the permissions of your local Docker installation you may need to use `sudo` for the invocation of `make`.

#### Pull Build Image

The build requires the [muslrust](https://hub.docker.com/r/clux/muslrust/tags/) Docker image with the corresponding Rust toolchain:

```sh
make -f Makefile.x86_64-unknown-linux-musl pre-build
```

This command has to be executed at least once and can be repeated for updating the `muslrust` build image.

#### Execute Build

Use the following command from the project directory to start the build:

```sh
make -f Makefile.x86_64-unknown-linux-musl
```

The source folder is copied into `/tmp` and mounted as a volume into the Docker container. The Cargo cache is also stored in `/tmp` and reused on subsequent invocations.

The resulting executable is copied into the folder `bin/x86_64-unknown-linux-musl` after the build has completed successfully.

## Logging

RUST_LOG=debug ./target/debug/openfairdb

0 comments on commit 9258c23

Please sign in to comment.