Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #2705 to release/v1.7 for add example-client docker image #2709

Conversation

vdaas-ci
Copy link
Collaborator

@vdaas-ci vdaas-ci commented Oct 21, 2024

Description

SSIA

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.2
  • Rust Version: v1.81.0
  • Docker Version: v27.3.1
  • Kubernetes Version: v1.31.1
  • Helm Version: v3.16.2
  • NGT Version: v2.2.4
  • Faiss Version: v1.9.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow for automating Docker image builds for the example client.
    • Added support for building and packaging an example client target.
    • New Docker image build targets for the example client have been implemented.
  • Improvements

    • Enhanced the Makefile with new variables and functions to streamline the build process for the example client.
    • Updated distance calculation method in configuration for improved feature vector processing.

These changes improve the efficiency and automation of the build and deployment processes for the example client application.

* 🐳 add example-client docker image

Signed-off-by: vankichi <[email protected]>

* 🐛 fix build error

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

---------

Signed-off-by: vankichi <[email protected]>
Copy link

cloudflare-workers-and-pages bot commented Oct 21, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: e7311df
Status: ✅  Deploy successful!
Preview URL: https://8b8a991a.vald.pages.dev
Branch Preview URL: https://backport-release-v1-7-featur-cewm.vald.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

📝 Walkthrough

Walkthrough

This pull request introduces several changes aimed at enhancing the build and deployment processes for a client application. A new GitHub Actions workflow file, dockers-example-client-image.yaml, is created to automate the Docker image build process. Modifications are made to various Makefiles to add support for the example client, including new variables, targets, and functions. Additionally, a multi-stage Dockerfile is introduced for building the client application, and a configuration update is made to the values.yaml file to change the distance metric used in calculations.

Changes

File Change Summary
.github/workflows/dockers-example-client-image.yaml New workflow file created to automate Docker image building for the example client.
Makefile New variable EXAMPLE_CLIENT_IMAGE added, and AGENT_NGT_IMAGE moved to a higher position.
Makefile.d/build.mk Added target example/client/client, updated zip artifact inclusion, and created a new artifact rule.
Makefile.d/docker.mk Added .PHONY targets for docker/name/example-client and docker/build/example-client.
Makefile.d/functions.mk New function go-example-build added for building Go projects.
dockers/example/client/Dockerfile Introduced a multi-stage build process for the client application, setting up the build environment.
example/helm/values.yaml Updated distance_type parameter from cos to l2 in the agent.ngt section.

Possibly related PRs

  • add example-client docker image #2705: This PR introduces a new GitHub Actions workflow for building a Docker image for an example client, which is directly related to the main PR that also adds a workflow for building a Docker image.

Suggested labels

type/feature, size/XXXL, area/makefile, actions/backport/release/v1.7

Suggested reviewers

  • vankichi
  • kmrmt
  • hlts2

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

FROM ghcr.io/vdaas/vald/vald-buildbase:nightly AS builder
LABEL maintainer="vdaas.org vald team <[email protected]>"
# skipcq: DOK-DL3002
USER root:root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [hadolint] <DL3002> reported by reviewdog 🐶
Last USER should not be root

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
#skipcq: DOK-W1001, DOK-SC2046, DOK-SC2086, DOK-DL3008
RUN --mount=type=bind,target=.,rw \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [hadolint] <DL3008> reported by reviewdog 🐶
Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>

@vdaas-ci
Copy link
Collaborator Author

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
.github/workflows/dockers-example-client-image.yaml (1)

19-70: LGTM: Well-defined workflow triggers with a suggestion.

The workflow name is clear, and the trigger events are comprehensive, covering necessary scenarios for rebuilding the example client image. The use of path filters for pull requests is an excellent practice to avoid unnecessary builds.

Consider adding a brief comment explaining the purpose of including both pull_request and pull_request_target events, as this might not be immediately clear to all contributors.

Makefile.d/docker.mk (1)

389-399: LGTM: New targets for example-client added correctly

The new targets docker/name/example-client and docker/build/example-client are correctly implemented and consistent with the PR objective. They follow the pattern of other similar targets in the file.

One minor suggestion:

Consider adding a comment above the docker/build/example-client target to briefly explain why the ZLIB_VERSION and HDF5_VERSION build arguments are necessary for the example client. This would improve the maintainability of the Makefile.

 .PHONY: docker/build/example-client
-## build example client docker image
+## Build example client docker image
+## Note: ZLIB_VERSION and HDF5_VERSION are required for [brief explanation]
 docker/build/example-client:
 	@make DOCKERFILE="$(ROOTDIR)/dockers/example/client/Dockerfile" \
 		IMAGE=$(EXAMPLE_CLIENT_IMAGE) \
 		DOCKER_OPTS="--build-arg ZLIB_VERSION=$(ZLIB_VERSION) --build-arg HDF5_VERSION=$(HDF5_VERSION)" \
 		docker/build/image
dockers/example/client/Dockerfile (1)

18-18: Note: This Dockerfile is auto-generated; modify the generator for changes.

As mentioned in the comment, this Dockerfile is generated by hack/docker/gen/main.go. To make sustainable changes, please update the generator script instead of editing the Dockerfile directly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 26098a4 and e7311df.

⛔ Files ignored due to path filters (1)
  • hack/docker/gen/main.go is excluded by !**/gen/**
📒 Files selected for processing (7)
  • .github/workflows/dockers-example-client-image.yaml (1 hunks)
  • Makefile (2 hunks)
  • Makefile.d/build.mk (4 hunks)
  • Makefile.d/docker.mk (3 hunks)
  • Makefile.d/functions.mk (1 hunks)
  • dockers/example/client/Dockerfile (1 hunks)
  • example/helm/values.yaml (1 hunks)
🧰 Additional context used
🔇 Additional comments (15)
.github/workflows/dockers-example-client-image.yaml (2)

1-17: LGTM: Proper license and auto-generation notice.

The file includes the correct Apache 2.0 license header and a clear note about being auto-generated. This is good practice for maintaining consistency and clarity in the project.


1-76: Overall: Well-structured and efficient workflow configuration.

This new workflow file for building the example client Docker image is well-designed and follows GitHub Actions best practices. It leverages reusable workflows, uses appropriate trigger events with path filtering, and considers security aspects.

The file is consistent with the project's coding standards and effectively serves its purpose. Great job on implementing this workflow!

example/helm/values.yaml (1)

65-65: Verify the impact of changing distance_type from cos to l2

The distance metric for NGT has been changed from cosine (cos) to Euclidean (l2). This change aligns with the comment "We use L2-Norm for distance_type." However, this modification can significantly impact search results, performance, and how client applications interpret the results.

  1. Please confirm if this change is intentional and has been thoroughly tested with the example client and other components.
  2. Ensure that all documentation referencing the distance metric is updated to reflect this change.
  3. Consider adding a comment explaining the rationale behind this change, especially if it's part of a larger optimization or feature update.

To help verify the impact of this change across the codebase, you can run the following script:

This script will help identify areas of the codebase that might be affected by the distance type change, allowing for a more comprehensive review of its impact.

✅ Verification successful

Change to distance_type from cos to l2 has been verified successfully. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to distance_type in the codebase

# Search for distance_type in YAML files
echo "Searching for distance_type in YAML files:"
rg -A 5 'distance_type:' --type yaml

# Search for references to distance calculation in Go files
echo "Searching for distance calculation references in Go files:"
rg -A 5 'distance.*type' --type go

# Search for cosine distance references
echo "Searching for cosine distance references:"
rg -A 5 'cos(ine)?.*distance' --type go --type yaml

# Search for L2/Euclidean distance references
echo "Searching for L2/Euclidean distance references:"
rg -A 5 'l2|euclidean.*distance' --type go --type yaml

Length of output: 57838

Makefile.d/build.mk (4)

34-34: LGTM: Example client added to binary build target

The addition of example/client/client to the binary/build target is correct and maintains the existing structure and order.


107-109: Clarify HDF5 dependency for example client

The build rule for the example client includes HDF5-related flags and version information. Could you please clarify if the example client actually requires HDF5? If not, consider simplifying the build command to:

example/client/client:
	$(eval CGO_ENABLED = 1)
	$(call go-example-build,example/client,-linkmode 'external',$(LDFLAGS), cgo,,$@)

This would remove the potentially unnecessary HDF5 dependency.


127-127: LGTM: Example client added to zip artifacts

The addition of the example client to the binary/build/zip target and the corresponding zip artifact creation rule are correct and consistent with the existing structure.

Also applies to: 202-204


34-34: Summary of changes

The modifications to Makefile.d/build.mk successfully integrate the example client into the build and packaging process. The changes are consistent with existing patterns and achieve the PR objective. However, please address the query regarding the HDF5 dependency for the example client to ensure we're not introducing unnecessary complexity.

Also applies to: 107-109, 127-127, 202-204

Makefile.d/docker.mk (2)

60-60: LGTM: Consistent addition of example-client to docker/xpanes/build

The addition of docker/build/example-client to the docker/xpanes/build target is consistent with the changes made to the docker/build target and aligns with the PR objective. The new line is correctly placed to maintain the alphabetical order of the commands.


Line range hint 1-399: Overall: Changes for example-client are well-implemented

The modifications to Makefile.d/docker.mk successfully integrate the example-client into the Docker build process. The changes are consistent across different targets and follow the established patterns in the file. The only points of attention are:

  1. Verifying the intentional removal of helm-operator from the docker/build target.
  2. Considering adding a brief explanation for the ZLIB_VERSION and HDF5_VERSION build arguments in the docker/build/example-client target.

These changes effectively support the PR objective of adding an example-client Docker image to the project.

Makefile.d/functions.mk (1)

94-121: 🛠️ Refactor suggestion

Review the new go-example-build function for consistency and potential improvements.

The new go-example-build function is similar to the existing go-build function but with some key differences:

  1. It uses $(ROOTDIR)/$1 instead of $(ROOTDIR)/cmd/$1 for finding Go files.
  2. It changes the working directory before running the build command.
  3. Vald-specific build flags (e.g., AlgorithmInfo, BuildTime) are not included.
  4. The output binary path is set to $(ROOTDIR)/$6.
  5. It doesn't run the version check after building.

Consider the following suggestions:

  1. Add echo $(PBGOS) for consistency with go-build.
  2. Evaluate if the working directory change affects relative path resolution.
  3. Confirm if the removal of Vald-specific build flags is intentional for example clients.
  4. Consider adding a version check after building, if applicable.

Here's a suggested improvement to address point 1:

 define go-example-build
 	echo $(GO_SOURCES_INTERNAL)
-	echo $(PBGOS)
+	echo $(PBGOS)
 	echo $(shell find $(ROOTDIR)/$1 -type f -name '*.go' -not -name '*_test.go' -not -name 'doc.go')
 	cd $(ROOTDIR)/$1 && \
 	CFLAGS="$(CFLAGS)" \
 	...

To verify the impact of the working directory change, run:

This will help identify any relative imports that might be affected by the working directory change.

Makefile (3)

28-28: LGTM: Variable definition moved.

The AGENT_NGT_IMAGE variable definition has been relocated to a more appropriate position in the file. This change improves readability and organization without affecting functionality.


39-39: LGTM: New variable for example-client image added.

The EXAMPLE_CLIENT_IMAGE variable has been introduced, which aligns with the PR objective of adding an example-client docker image. The naming convention is consistent with other image variables in the file.


Line range hint 1-1000: Summary: Makefile changes support example-client image addition.

The modifications to this Makefile are minimal and focused, supporting the PR objective of adding an example-client docker image. The changes include:

  1. Relocating the AGENT_NGT_IMAGE variable definition for better organization.
  2. Adding a new EXAMPLE_CLIENT_IMAGE variable for the example-client image.

These changes are consistent with the existing structure and naming conventions in the Makefile. They provide the necessary groundwork for building and managing the new example-client docker image without introducing any apparent issues or inconsistencies.

dockers/example/client/Dockerfile (2)

21-21: ⚠️ Potential issue

Pin base images to specific versions or digests for reproducible builds.

Currently, the FROM statements use unpinned images (ghcr.io/vdaas/vald/vald-buildbase:nightly and gcr.io/distroless/static:nonroot) without specifying exact versions or digests. This can result in non-reproducible builds if the base images are updated. It's recommended to pin the base images to specific tags or digests to ensure consistency.

Run the following script to identify the use of unpinned base images in Dockerfiles:

#!/bin/bash
# Description: Find unpinned base images in Dockerfiles.

# List FROM statements without a tag or digest
rg '^FROM\s+\S+:(?!\S)' -g '*Dockerfile*'

Also applies to: 90-90


19-19: 🛠️ Refactor suggestion

Consider removing the unused ARG UPX_OPTIONS.

The ARG UPX_OPTIONS=-9 is declared but not utilized in this Dockerfile. Keeping unused build arguments can lead to confusion. It's good practice to remove them to simplify the Dockerfile.

Run the following script to check if UPX_OPTIONS is used elsewhere in the codebase:

✅ Verification successful

UPX_OPTIONS is unused in dockers/example/client/Dockerfile

The ARG UPX_OPTIONS=-9 is declared but not utilized within this Dockerfile. It can be safely removed to simplify the Dockerfile.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the usage of UPX_OPTIONS in Dockerfiles.

# Find all occurrences of UPX_OPTIONS in Dockerfiles
rg 'UPX_OPTIONS' -g '*Dockerfile*'

Length of output: 371


Script:

#!/bin/bash
# Description: Search for the usage of UPX_OPTIONS across the entire codebase.

rg 'UPX_OPTIONS'

Length of output: 1379


Script:

#!/bin/bash
# Description: Check for the usage of UPX_OPTIONS in dockers/example/client/Dockerfile beyond its declaration.

# Search for UPX_OPTIONS usage excluding its declaration
rg 'UPX_OPTIONS' dockers/example/client/Dockerfile | grep -v 'ARG UPX_OPTIONS'

Length of output: 78

Comment on lines +71 to +76
jobs:
build:
uses: ./.github/workflows/_docker-image.yaml
with:
target: example-client
secrets: inherit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issue Found: 'example-client' target not configured in _docker-image.yaml.

  • The example-client target specified in the main workflow is missing from .github/workflows/_docker-image.yaml.
🔗 Analysis chain

LGTM: Efficient job definition using reusable workflow.

The job definition is concise and leverages a reusable workflow, which is an excellent practice for maintaining consistency and reducing duplication across different workflows.

To ensure the referenced workflow file exists and is correctly configured, please run the following command:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence and basic structure of the _docker-image.yaml file

if [ -f .github/workflows/_docker-image.yaml ]; then
    echo "File _docker-image.yaml exists. Checking its content:"
    grep -E "name:|on:|jobs:" .github/workflows/_docker-image.yaml
else
    echo "Error: _docker-image.yaml file not found in .github/workflows/"
fi

Length of output: 962


Script:

#!/bin/bash
# Verify that 'example-client' target is correctly configured in _docker-image.yaml

if [ -f .github/workflows/_docker-image.yaml ]; then
    echo "Checking for 'example-client' target configuration in _docker-image.yaml:"
    rg "target:\s*example-client" .github/workflows/_docker-image.yaml
    if [ $? -eq 0 ]; then
        echo "'example-client' target is properly configured."
    else
        echo "Error: 'example-client' target not found in _docker-image.yaml."
    fi
else
    echo "Error: _docker-image.yaml file not found in .github/workflows/"
fi

Length of output: 442

Comment on lines +32 to +36
docker/build/example-client \
docker/build/gateway-filter \
docker/build/gateway-lb \
docker/build/gateway-mirror \
docker/build/helm-operator \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

helm-operator is still referenced in Makefile.d/docker.mk

The removal of docker/build/helm-operator was intended; however, it is still present in the following lines of Makefile.d/docker.mk:

  • Line 36
  • Line 291
  • Line 293
🔗 Analysis chain

Verify the removal of helm-operator from the docker/build target

The addition of docker/build/example-client is consistent with the PR objective. However, please confirm if the removal of docker/build/helm-operator from this target is intentional. If it's not, consider adding it back to maintain consistency with other build targets.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if helm-operator is built elsewhere
grep -n "docker/build/helm-operator" Makefile.d/*.mk

Length of output: 529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants