Skip to content

Commit

Permalink
⬆️ Upgrade v1 APIs / Add Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx committed Jan 22, 2021
1 parent 67c26f2 commit 42195c4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ futures = { version = "0.3", default-features = false }
lazy_static = "1.4"
prometheus = { version = "0.9", features = ["process"] }
prost = "0.6"
prost-types = "0.6"
tokio = { version = "0.2", features = ["macros", "rt-threaded", "time"] }
tonic = "0.3.1"
warp = "0.2"
Expand All @@ -20,3 +21,7 @@ env_logger = "0.8.2"

[build-dependencies]
tonic-build = "0.3"

[[bin]]
name = "vald-agent-ngt-rs"
path = "src/main.rs"
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM rust:latest AS builder

RUN apt update \
&& apt install -y \
build-essential \
cmake \
clang \
g++ \
gcc \
git \
libclang-dev \
llvm-dev \
&& apt autoclean -y \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*

RUN rustup component add rustfmt

WORKDIR /app

COPY Makefile .
COPY build.rs .
COPY Cargo.toml .
COPY Cargo.lock .
COPY src src

RUN make build/release

FROM gcr.io/distroless/cc AS base

COPY --from=builder /app/target/release/vald-agent-ngt-rs /vald-agent-ngt-rs
COPY --from=builder /app/target/release/build/ngt-sys-*/out/lib/* /usr/local/lib/

ENV LD_LIBRARY_PATH=/usr/local/lib

ENTRYPOINT [ "/vald-agent-ngt-rs" ]
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,33 @@ target/release/vald-agent-ngt-rs: \

proto: \
proto/github.com/envoyproxy/protoc-gen-validate \
proto/github.com/googleapis/googleapis
proto/github.com/gogo/protobuf \
proto/github.com/gogo/googleapis \
proto/github.com/protocolbuffers/protobuf

proto/github.com/envoyproxy/protoc-gen-validate:
mkdir -p proto
git clone --depth 1 \
https://github.com/envoyproxy/protoc-gen-validate \
proto/github.com/envoyproxy/protoc-gen-validate

proto/github.com/googleapis/googleapis:
proto/github.com/gogo/protobuf:
mkdir -p proto
git clone --depth 1 \
https://github.com/googleapis/googleapis \
proto/github.com/googleapis/googleapis
https://github.com/gogo/protobuf \
proto/github.com/gogo/protobuf

proto/github.com/gogo/googleapis:
mkdir -p proto
git clone --depth 1 \
https://github.com/gogo/googleapis \
proto/github.com/gogo/googleapis

proto/github.com/protocolbuffers/protobuf:
mkdir -p proto
git clone --depth 1 \
https://github.com/protocolbuffers/protobuf \
proto/github.com/protocolbuffers/protobuf

apis/proto/v1: \
proto \
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.format(true)
.compile(
&[
"apis/proto/v1/errors/errors.proto",
"apis/proto/v1/payload/payload.proto",
"apis/proto/v1/vald/insert.proto",
"apis/proto/v1/vald/object.proto",
Expand All @@ -18,7 +17,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
&[
".",
"proto",
"proto/github.com/googleapis/googleapis",
"proto/github.com/gogo/googleapis",
"proto/github.com/protocolbuffers/protobuf",
"apis/proto",
],
)?;
Expand Down
30 changes: 11 additions & 19 deletions src/vald.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ pub mod core {
}
}

pub mod errors {
pub mod payload {
pub mod v1 {
tonic::include_proto!("errors.v1");
tonic::include_proto!("payload.v1");
}
}

pub mod payload {
pub mod v1 {
tonic::include_proto!("payload.v1");
pub mod google {
pub mod rpc {
tonic::include_proto!("google.rpc");
}
}

Expand Down Expand Up @@ -155,14 +155,10 @@ impl Insert for ValdImpl {
payload: Some(payload::v1::object::stream_location::Payload::Location(loc)),
},
Err(st) => payload::v1::object::StreamLocation{
payload: Some(payload::v1::object::stream_location::Payload::Error(errors::v1::errors::Rpc{
r#type: "".to_string(),
msg: "".to_string(),
payload: Some(payload::v1::object::stream_location::Payload::Status(google::rpc::Status{
code: 0,
message: st.to_string(),
details: Vec::new(),
error: st.to_string(),
instance: "".to_string(),
status: 0,
roots: Vec::new(),
})),
},
};
Expand Down Expand Up @@ -218,14 +214,10 @@ impl Search for ValdImpl {
payload: Some(payload::v1::search::stream_response::Payload::Response(res)),
},
Err(st) => payload::v1::search::StreamResponse{
payload: Some(payload::v1::search::stream_response::Payload::Error(errors::v1::errors::Rpc{
r#type: "".to_string(),
msg: "".to_string(),
payload: Some(payload::v1::search::stream_response::Payload::Status(google::rpc::Status{
code: 0,
message: st.to_string(),
details: Vec::new(),
error: st.to_string(),
instance: "".to_string(),
status: 0,
roots: Vec::new(),
})),
},
};
Expand Down

0 comments on commit 42195c4

Please sign in to comment.