reztilop commited on
Commit
bfed346
·
verified ·
1 Parent(s): f9d23bb

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +175 -0
Dockerfile ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cross-compiling using Docker multi-platform builds/images and `xx`.
2
+ #
3
+ # https://docs.docker.com/build/building/multi-platform/
4
+ # https://github.com/tonistiigi/xx
5
+ FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx AS xx
6
+
7
+ # Utilizing Docker layer caching with `cargo-chef`.
8
+ #
9
+ # https://www.lpalmieri.com/posts/fast-rust-docker-builds/
10
+ FROM --platform=${BUILDPLATFORM:-linux/amd64} lukemathwalker/cargo-chef:latest-rust-1.82.0 AS chef
11
+
12
+
13
+ FROM chef AS planner
14
+ WORKDIR /qdrant
15
+ COPY . .
16
+ RUN cargo chef prepare --recipe-path recipe.json
17
+
18
+
19
+ FROM chef AS builder
20
+ WORKDIR /qdrant
21
+
22
+ COPY --from=xx / /
23
+
24
+ # Relative order of `ARG` and `RUN` commands in the Dockerfile matters.
25
+ #
26
+ # If you pass a different `ARG` to `docker build`, it would invalidate Docker layer cache
27
+ # for the next steps. (E.g., the following steps may depend on a new `ARG` value, so Docker would
28
+ # have to re-execute them instead of using a cached layer from a previous run.)
29
+ #
30
+ # Steps in this stage are ordered in a way that should maximize Docker layer cache utilization,
31
+ # so, please, don't reorder them without prior consideration. 🥲
32
+
33
+ RUN apt-get update \
34
+ && apt-get install -y clang lld cmake protobuf-compiler jq \
35
+ && rustup component add rustfmt
36
+
37
+ # `ARG`/`ENV` pair is a workaround for `docker build` backward-compatibility.
38
+ #
39
+ # https://github.com/docker/buildx/issues/510
40
+ ARG BUILDPLATFORM
41
+ ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}
42
+
43
+ ARG MOLD_VERSION=2.31.0
44
+
45
+ RUN case "$BUILDPLATFORM" in \
46
+ */amd64 ) PLATFORM=x86_64 ;; \
47
+ */arm64 | */arm64/* ) PLATFORM=aarch64 ;; \
48
+ * ) echo "Unexpected BUILDPLATFORM '$BUILDPLATFORM'" >&2; exit 1 ;; \
49
+ esac; \
50
+ \
51
+ mkdir -p /opt/mold; \
52
+ cd /opt/mold; \
53
+ \
54
+ TARBALL="mold-$MOLD_VERSION-$PLATFORM-linux.tar.gz"; \
55
+ curl -sSLO "https://github.com/rui314/mold/releases/download/v$MOLD_VERSION/$TARBALL"; \
56
+ tar -xf "$TARBALL" --strip-components 1; \
57
+ rm "$TARBALL"
58
+
59
+ # `ARG`/`ENV` pair is a workaround for `docker build` backward-compatibility.
60
+ #
61
+ # https://github.com/docker/buildx/issues/510
62
+ ARG TARGETPLATFORM
63
+ ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
64
+
65
+ RUN xx-apt-get install -y pkg-config gcc g++ libc6-dev libunwind-dev
66
+
67
+ # Select Cargo profile (e.g., `release`, `dev` or `ci`)
68
+ ARG PROFILE=release
69
+
70
+ # Enable crate features
71
+ ARG FEATURES
72
+
73
+ # Pass custom `RUSTFLAGS` (e.g., `--cfg tokio_unstable` to enable Tokio tracing/`tokio-console`)
74
+ ARG RUSTFLAGS
75
+
76
+ # Select linker (e.g., `mold`, `lld` or an empty string for the default linker)
77
+ ARG LINKER=mold
78
+
79
+ COPY --from=planner /qdrant/recipe.json recipe.json
80
+ # `PKG_CONFIG=...` is a workaround for `xx-cargo` bug for crates using `pkg-config`!
81
+ #
82
+ # https://github.com/tonistiigi/xx/issues/107
83
+ # https://github.com/tonistiigi/xx/pull/108
84
+ RUN PKG_CONFIG="/usr/bin/$(xx-info)-pkg-config" \
85
+ PATH="$PATH:/opt/mold/bin" \
86
+ RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
87
+ xx-cargo chef cook --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace --recipe-path recipe.json
88
+
89
+ COPY . .
90
+ # Include git commit into Qdrant binary during build
91
+ ARG GIT_COMMIT_ID
92
+ # `PKG_CONFIG=...` is a workaround for `xx-cargo` bug for crates using `pkg-config`!
93
+ #
94
+ # https://github.com/tonistiigi/xx/issues/107
95
+ # https://github.com/tonistiigi/xx/pull/108
96
+ RUN PKG_CONFIG="/usr/bin/$(xx-info)-pkg-config" \
97
+ PATH="$PATH:/opt/mold/bin" \
98
+ RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \
99
+ xx-cargo build --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace --bin qdrant \
100
+ && PROFILE_DIR=$(if [ "$PROFILE" = dev ]; then echo debug; else echo $PROFILE; fi) \
101
+ && mv target/$(xx-cargo --print-target-triple)/$PROFILE_DIR/qdrant /qdrant/qdrant
102
+
103
+ # Download and extract web UI
104
+ RUN mkdir /static && STATIC_DIR=/static ./tools/sync-web-ui.sh
105
+
106
+
107
+ FROM debian:12-slim AS qdrant
108
+
109
+ RUN apt-get update
110
+
111
+ # Install additional packages into the container.
112
+ # E.g., the debugger of choice: gdb/gdbserver/lldb.
113
+ ARG PACKAGES
114
+
115
+ RUN apt-get install -y --no-install-recommends ca-certificates tzdata libunwind8 $PACKAGES \
116
+ && rm -rf /var/lib/apt/lists/*
117
+
118
+ # Copy Qdrant source files into the container. Useful for debugging.
119
+ #
120
+ # To enable, set `SOURCES` to *any* non-empty string. E.g., 1/true/enable/whatever.
121
+ # (Note, that *any* non-empty string would work, so 0/false/disable would enable the option as well.)
122
+ ARG SOURCES
123
+
124
+ # Dockerfile does not support conditional `COPY` instructions (e.g., it's impossible to do something
125
+ # like `if [ -n "$SOURCES" ]; then COPY ...; fi`), so we *hack* conditional `COPY` by abusing
126
+ # parameter expansion and `COPY` wildcards support. 😎
127
+
128
+ ENV DIR=${SOURCES:+/qdrant/src}
129
+ COPY --from=builder ${DIR:-/null?} $DIR/
130
+
131
+ ENV DIR=${SOURCES:+/qdrant/lib}
132
+ COPY --from=builder ${DIR:-/null?} $DIR/
133
+
134
+ ENV DIR=${SOURCES:+/usr/local/cargo/registry/src}
135
+ COPY --from=builder ${DIR:-/null?} $DIR/
136
+
137
+ ENV DIR=${SOURCES:+/usr/local/cargo/git/checkouts}
138
+ COPY --from=builder ${DIR:-/null?} $DIR/
139
+
140
+ ENV DIR=
141
+
142
+ ARG APP=/qdrant
143
+
144
+ COPY --from=builder /qdrant/qdrant "$APP"/qdrant
145
+ COPY --from=builder /qdrant/config "$APP"/config
146
+ COPY --from=builder /qdrant/tools/entrypoint.sh "$APP"/entrypoint.sh
147
+ COPY --from=builder /static "$APP"/static
148
+
149
+ WORKDIR "$APP"
150
+
151
+ ARG USER_ID=0
152
+
153
+ RUN if [ "$USER_ID" != 0 ]; then \
154
+ groupadd --gid "$USER_ID" qdrant; \
155
+ useradd --uid "$USER_ID" --gid "$USER_ID" -m qdrant; \
156
+ mkdir -p "$APP"/storage "$APP"/snapshots; \
157
+ chown -R "$USER_ID:$USER_ID" "$APP"; \
158
+ fi
159
+
160
+ USER "$USER_ID:$USER_ID"
161
+
162
+ ENV TZ=Etc/UTC \
163
+ RUN_MODE=production
164
+
165
+ EXPOSE 7860
166
+ EXPOSE 7861
167
+
168
+ LABEL org.opencontainers.image.title="Qdrant"
169
+ LABEL org.opencontainers.image.description="Official Qdrant image"
170
+ LABEL org.opencontainers.image.url="https://qdrant.com/"
171
+ LABEL org.opencontainers.image.documentation="https://qdrant.com/docs"
172
+ LABEL org.opencontainers.image.source="https://github.com/qdrant/qdrant"
173
+ LABEL org.opencontainers.image.vendor="Qdrant"
174
+
175
+ CMD ["./entrypoint.sh"]