diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 17:58:24 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:35:20 -0600 |
| commit | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (patch) | |
| tree | 782542be4e438d264a88b4e19efa8fcedfdc5a0e | |
| parent | bcafdf918489485aca2b405109187e66f2e645d5 (diff) | |
feat: implement cargo vendor and optimize Docker builds
| -rw-r--r-- | .cargo/config.toml | 9 | ||||
| -rw-r--r-- | .gitattributes | 3 | ||||
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Dockerfile | 2 | ||||
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | src/authorization/server.rs | 3 |
6 files changed, 34 insertions, 6 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..496c0f18 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,9 @@ +[source.crates-io] +replace-with = "vendored-sources" + +[source."git+https://github.com/xlgmokha/please.git"] +git = "https://github.com/xlgmokha/please.git" +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "vendor"
\ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..62df66ae --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +vendor/** -diff -merge linguist-vendored gitlab-generated +.cargo/** -diff -merge linguist-vendored gitlab-generated +Cargo.lock -diff -merge linguist-vendored gitlab-generated @@ -1 +1,5 @@ target + +# Explicitly include vendor directory +!vendor/ +!.cargo/ @@ -3,7 +3,7 @@ FROM rust:alpine AS builder RUN apk add --no-cache musl-dev WORKDIR /app COPY . ./ -RUN cargo build --release --target x86_64-unknown-linux-musl +RUN cargo build --release --target x86_64-unknown-linux-musl --offline RUN strip /app/target/x86_64-unknown-linux-musl/release/authzd FROM gcr.io/distroless/static-debian12:nonroot @@ -2,15 +2,15 @@ PROJECT_NAME := $(shell basename $(shell pwd)) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') IMAGE_TAG := $(PROJECT_NAME):$(GIT_BRANCH) -.PHONY: build check test run clean fmt lint doc +.PHONY: build check test run clean fmt lint doc vendor .PHONY: build-image run-image health-check list-services test-grpc setup: @rustup component add clippy rustfmt # Cargo targets -build: - @cargo build +build: vendor + @cargo build --offline check: @cargo check @@ -19,7 +19,7 @@ test: @cargo test run: - @cargo run + @cargo run --offline clean: @cargo clean @@ -33,8 +33,14 @@ lint: doc: @cargo doc --open +vendor: + @cargo vendor + # Docker targets -build-image: +build-image: vendor + @docker build --tag $(IMAGE_TAG) . + +build-image-clean: @docker build --no-cache --tag $(IMAGE_TAG) . run-image: build-image @@ -43,3 +49,6 @@ run-image: build-image # gRPC testing targets health-check: @grpcurl -plaintext localhost:50051 grpc.health.v1.Health/Check + +list-services: + @grpcurl -plaintext localhost:50051 list diff --git a/src/authorization/server.rs b/src/authorization/server.rs index ded609da..2229163a 100644 --- a/src/authorization/server.rs +++ b/src/authorization/server.rs @@ -18,6 +18,9 @@ impl Server { let reflection_service = tonic_reflection::server::Builder::configure() .register_encoded_file_descriptor_set(tonic_health::pb::FILE_DESCRIPTOR_SET) + .register_encoded_file_descriptor_set(include_bytes!( + "../../vendor/envoy-types/src/generated/types.bin" + )) .build_v1()?; Ok(Self::new_with(|mut builder| { |
