forked from tinysearch/tinysearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
71 lines (56 loc) · 1.92 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Docker tinysearch with deps
# - binaryen
# - wasm-pack
# - terser
ARG TINY_REPO=https://github.com/tinysearch/tinysearch
ARG TINY_BRANCH=master
ARG RUST_IMAGE=rust:alpine
FROM $RUST_IMAGE AS builder
ARG TINY_REPO
ARG TINY_BRANCH
WORKDIR /build
# Install dependencies
RUN apk add --update --no-cache --virtual \
.build-deps \
musl-dev \
openssl-dev \
gcc \
curl \
git \
npm \
gcc \
ca-certificates \
libc6-compat \
binaryen && \
ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld64.so.1 && \
npm install terser -g
# Verify the installation
RUN terser --version
# Install wasm-pack
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Verify the installation
RUN wasm-pack --version && which wasm-pack
# Clone the repo and build the binary
RUN git clone --branch "$TINY_BRANCH" "$TINY_REPO" tinysearch && \
cd tinysearch && \
cargo build --release --features=bin && \
cp target/release/tinysearch $CARGO_HOME/bin
FROM $RUST_IMAGE
WORKDIR /app
# Install runtime dependencies
RUN apk add --update --no-cache libc6-compat musl-dev binaryen openssl-dev && \
ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld64.so.1
# Copy the build binaries and tinysearch directory
COPY --from=builder /usr/local/bin/ /usr/local/bin/
COPY --from=builder /usr/local/cargo/bin/ /usr/local/bin/
# Copy tinysearch build directory to be used as the engine (see `--engine-version` option below)
# This is done because we want to use the same image for building and running tinysearch
# and not depend on crates.io for the engine
COPY --from=builder /build/tinysearch/ /engine
# Initialize crate cache
RUN echo '[{"title":"","body":"","url":""}]' > build.json && \
tinysearch --engine-version 'path= "/engine"' build.json && \
rm -r build.json wasm_output
ENTRYPOINT ["tinysearch"]
# Use the engine we built above and not the one from crates.io
CMD ["--engine-version", "path= \"/engine\""]