Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use system rocksdb libs, if available #565

Merged
merged 7 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[target.thumbv7em-none-eabi]
linker = "utils/alpine-linker-script.sh"
#ar = "arm-none-eabi-ar"

[env]
ROCKSDB_LIB_DIR = "/usr/lib/"
SNAPPY_LIB_DIR = "/usr/lib/"
tedil marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,41 @@ The supported set slightly differs between import for GRCh37 and GRCh38.
- gnomAD v3.1 mtDNA [`gnomad.genomes.v3.1.sites.chrM.vcf.bgz`](https://gnomad.broadinstitute.org/downloads#v3-mitochondrial-dna)
- HelixMTdb `HelixMTdb_20200327.tsv`

## Building from scratch
To reduce compile times, we recommend using a pre-built version of `rocksdb`, either from the system package manager or e.g. via `conda`:

```bash
# Ubuntu
sudo apt-get install librocksdb-dev

# Conda
conda install -c conda-forge rocksdb
```

In either case, either add
```toml
[env]
ROCKSDB_LIB_DIR = "/usr/lib/" # in case of the system package manager, adjust the path accordingly for conda
SNAPPY_LIB_DIR = "/usr/lib/" # same as above
```
to `.cargo/config.toml` or set the environment variables `ROCKSDB_LIB_DIR` and `SNAPPY_LIB_DIR` to the appropriate paths:

```bash
export ROCKSDB_LIB_DIR=/usr/lib/
export SNAPPY_LIB_DIR=/usr/lib/
```

By default, the environment variables are defined in the `.cargo/config.toml` as described above, i.e. may need adjustments if not using the system package manager.

To build the project, run:
```bash
cargo build --release
```

To install the project locally, run:
```bash
cargo install --path .
```
## Internal Notes

```
Expand Down
49 changes: 19 additions & 30 deletions utils/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,51 @@
# mehari right now as both CLI and lib; we would have to use features to
# untable the two.

# Based on https://levelup.gitconnected.com/1940db638a6c
#
# We don't do cross compilation at the moment but build the dependencies first
# anyway to get the ability to increment.

# ---------------------------------------------------------------------------
# Builder
# ---------------------------------------------------------------------------

# Pinning Rust version for now because of this issue:
#
# - https://github.com/rust-lang/rust/issues/95926
FROM rust:1-bookworm AS builder
# Use ubuntu:noble as the base image
FROM ubuntu:noble AS builder

# Build dependencies first.
#
# Install dependencies for compilation of C code (e.g., rocksdb).
# Install Rust toolchain and dependencies for compilation of C code (e.g., rocksdb)
RUN apt-get update && \
apt-get install -y clang
# Add the needed Cargo components.
RUN rustup component add rustfmt
apt-get install -y unzip wget curl build-essential clang librocksdb-dev libsqlite3-dev && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
. $HOME/.cargo/env && \
rustup component add rustfmt

# Install build dependency `protoc`.
COPY utils/install-protoc.sh /tmp
RUN PREFIX=/usr/local bash /tmp/install-protoc.sh

#### Now for the two-step building.
####
#### Set initial workdir.
###WORKDIR /usr/src
#### Create blank project.
###RUN USER=root cargo new mehari
#### We want dependencies cached, so copy those first.
###COPY Cargo.toml Cargo.lock /usr/src/mehari/
# Set the working directory.
WORKDIR /usr/src/mehari
#### This is a dummy build to get the dependencies cached.
###RUN cargo build --release
#
# Now copy in the rest of the sources.

# Copy in the rest of the sources.
COPY build.rs Cargo.toml Cargo.lock /usr/src/mehari/
COPY src /usr/src/mehari/src/
COPY protos /usr/src/mehari/protos/
COPY utils/alpine-linker-script.sh /usr/src/mehari/utils/
RUN chmod a+rx /usr/src/mehari/utils/alpine-linker-script.sh
COPY .cargo /usr/src/mehari/.cargo/
## Touch main.rs to prevent cached release build.

# Touch main.rs to prevent cached release build.
RUN touch /usr/src/mehari/src/main.rs
# This is the actual application build.
RUN cargo build --release

# Build the application
RUN /root/.cargo/bin/cargo build --release

# ---------------------------------------------------------------------------
# Runtime
# ---------------------------------------------------------------------------

FROM debian:bookworm-slim AS runtime
FROM ubuntu:noble AS runtime

# Install dependencies (and cleanup afterwards)
# Install dependencies (and cleanup afterward)
RUN apt-get update && \
apt-get install -y libsqlite3-0 && \
apt-get clean autoclean && \
Expand All @@ -78,5 +66,6 @@ RUN chmod a+rx /entrypoint.sh

# Set the entrypoint.
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
# Set port to expose

# Expose the application port
EXPOSE 8080
Loading