From fdaf62b430c3ec8fc5b95c1510e81af0d3dbe61e Mon Sep 17 00:00:00 2001 From: thuan2172001 Date: Sat, 9 Mar 2024 16:19:30 +0700 Subject: [PATCH] fix: install proto before build --- .github/workflows/ci.yaml | 23 +++++++++++++++++----- .github/workflows/rust-clippy.yml | 13 +++++++++++++ Cargo.lock | 5 +++++ Dockerfile | 3 +++ src/grpc/src/grpc_server/gpt_answer.rs | 27 +++++++++++++++++--------- 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 32057fa..72e2e92 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,9 +9,22 @@ on: - main jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install protoc and grpcio-tools + run: | + sudo apt-get update + sudo apt-get install -y protobuf-compiler + cargo install grpcio-compiler + cargo-check: name: Cargo check runs-on: ubuntu-latest + needs: setup steps: - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 @@ -26,6 +39,7 @@ jobs: fmt-check: name: Rust fmt runs-on: ubuntu-latest + needs: setup steps: - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 @@ -42,6 +56,7 @@ jobs: test-and-coverage: name: Test and Coverage runs-on: ubuntu-latest + needs: setup steps: - name: Checkout code uses: actions/checkout@v4 @@ -53,8 +68,7 @@ jobs: cargo install cargo-tarpaulin - name: Run tests with coverage - run: | - cargo tarpaulin --all-features --verbose + run: cargo tarpaulin --all-features --verbose release-github-artifact: name: Release Packaging @@ -117,9 +131,8 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - + - name: Build and push docker image - run: | + run: | docker build . --tag ${{ env.DOCKER_HUB_REPOSITORY }}:latest docker push ${{ env.DOCKER_HUB_REPOSITORY }}:latest - diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml index 03c2dc3..63f39e8 100644 --- a/.github/workflows/rust-clippy.yml +++ b/.github/workflows/rust-clippy.yml @@ -19,9 +19,22 @@ on: - cron: '27 4 * * 6' jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install protoc and grpcio-tools + run: | + sudo apt-get update + sudo apt-get install -y protobuf-compiler + cargo install grpcio-compiler + rust-clippy-analyze: name: Run rust-clippy analyzing runs-on: ubuntu-latest + needs: setup permissions: contents: read security-events: write diff --git a/Cargo.lock b/Cargo.lock index 62e1fb2..5db657a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,7 @@ version = 3 name = "adapter" version = "0.0.1" dependencies = [ + "anyhow", "async-trait", "deadpool-diesel", "diesel", @@ -330,6 +331,7 @@ name = "cli" version = "0.0.1" dependencies = [ "adapter", + "anyhow", "clap", "common", "deadpool-diesel", @@ -344,6 +346,7 @@ dependencies = [ "serde", "serde_json", "testcontainers-modules", + "thiserror", "tokio", "tracing", "warp", @@ -1780,8 +1783,10 @@ dependencies = [ name = "rust_core" version = "0.0.1" dependencies = [ + "anyhow", "async-trait", "serde", + "thiserror", ] [[package]] diff --git a/Dockerfile b/Dockerfile index aa0966e..58033a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,9 @@ FROM chef AS planner COPY . . RUN cargo chef prepare --recipe-path recipe.json +RUN apt-get update && \ + apt-get install -y protobuf-compiler + FROM chef AS builder COPY --from=planner /app/recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json diff --git a/src/grpc/src/grpc_server/gpt_answer.rs b/src/grpc/src/grpc_server/gpt_answer.rs index f487b1c..873d0cf 100644 --- a/src/grpc/src/grpc_server/gpt_answer.rs +++ b/src/grpc/src/grpc_server/gpt_answer.rs @@ -25,16 +25,25 @@ impl GptAnswerService for GptAnswerServer { } pub async fn init_gpt_answer_server() { - let addr: std::net::SocketAddr = "http://0.0.0.0:50051".parse().unwrap(); - println!("GPT Answer server config at {}", addr); + let result = "http://0.0.0.0:50051".parse().map_err(|err| { + println!("Error: {:?}", err); + }); - let gpt_answer_server = GptAnswerServer::default(); + if result.is_ok() { + let addr = result.unwrap(); - Server::builder() - .add_service(GptAnswerServiceServer::new(gpt_answer_server)) - .serve(addr) - .await - .unwrap(); + println!("GPT Answer server config at {}", addr); - println!("GPT Answer server started at {}", addr); + let gpt_answer_server = GptAnswerServer::default(); + + Server::builder() + .add_service(GptAnswerServiceServer::new(gpt_answer_server)) + .serve(addr) + .await + .unwrap(); + + println!("GPT Answer server started at {}", addr); + } else { + println!("GPT Answer server failed to start"); + } }