Skip to content

Commit

Permalink
Merge branch 'valkey-io:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
murphyjacob4 authored Jan 28, 2025
2 parents a379522 + 9ea9ff9 commit fe4a62a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 36 deletions.
43 changes: 15 additions & 28 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,35 @@ RUN wget -O /usr/local/bin/buildifier https://github.com/bazelbuild/buildtools/r

# Add bazel/buildifier to PATH
ENV PATH="/usr/local/bin:$PATH"
RUN echo '#!/bin/bash\n\
set +e\n\
LOCKFILE="/tmp/rebuild_comp_db.lock"\n\
if [ -e "$LOCKFILE" ] && kill -0 "$(cat "$LOCKFILE")" 2>/dev/null; then\n\
echo "Script is already running. Exiting."\n\
exit 1\n\
fi\n\
echo $$ > "$LOCKFILE"\n\
trap "rm -f $LOCKFILE" EXIT\n\
if [ ! -d "/workspaces/valkey-search" ]; then\n\
echo "Error: Directory /workspaces/valkey-search does not exist."\n\
exit 1\n\
fi\n\
cd /workspaces/valkey-search\n\
while sleep 1; do\n\
find src testing vmsdk/src vmsdk/testing -type f \\( -iname \\*.cc -o -iname \\*.h -o -iname BUILD \\) | entr -d bazel run @hedron_compile_commands//:refresh_all &> /dev/null\n\
done' > /usr/local/bin/refresh_comp_db.sh && chmod +x /usr/local/bin/refresh_comp_db.sh

# Set working directory
WORKDIR /workspace

# Add non-root user for development
RUN useradd -m vscode && echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
ARG USERNAME=ubuntu
ENV USERNAME=${USERNAME}
ARG USER_UID=1000
ENV USER_UID=${USER_UID}
ARG USER_GID=1000
ENV USER_GID=${USER_GID}

USER vscode
RUN groupadd -g $USER_GID $USERNAME || true; \
useradd -ms /bin/bash -u $USER_UID -g $USER_GID $USERNAME || true; \
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers || true;

# Add an alias for 'vi' to point to 'vim' if 'vi' doesn't exist
RUN echo 'if ! command -v vi &> /dev/null; then alias vi="vim"; fi' >> /home/vscode/.bashrc
USER $USERNAME

# Add an alias for 'vi' to point to 'vim' if 'vi' doesn't exist
RUN echo 'if ! command -v vi &> /dev/null; then alias vi="vim"; fi' >> /home/$USERNAME/.bashrc

ARG ENABLE_COMP_DB_REFRESH=true
ENV ENABLE_COMP_DB_REFRESH=${ENABLE_COMP_DB_REFRESH}

RUN if [ "$ENABLE_COMP_DB_REFRESH" = "true" ]; then \
echo 'refresh_comp_db.sh &> /dev/null &' >> /home/vscode/.bashrc; \
fi

# Ensure the history file exists and configure permissions
RUN touch /home/vscode/.bash_history && chmod 600 /home/vscode/.bash_history
RUN touch /home/$USERNAME/.bash_history && \
chmod 600 /home/$USERNAME/.bash_history

ENV CC=clang
ENV CXX=clang++


# Default shell
SHELL ["/bin/bash", "-c"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "ValkeySearch Development Environment",
"build": {
"dockerfile": "Dockerfile",
"context": "."
"context": ".",
"args": {
"USERNAME": "ubuntu",
"USER_UID": "1000",
"USER_GID": "1000"
}
},
"customizations": {
"vscode": {
Expand All @@ -24,6 +29,6 @@
]
}
},
"remoteUser": "vscode",
"postCreateCommand": "./ci/entrypoint.sh && /bin/bash"
"remoteUser": "ubuntu",
"postCreateCommand": "export USER=ubuntu && ./ci/entrypoint.sh && /bin/bash"
}
35 changes: 35 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Get the current user's ID, group ID, and username
user_id=$(id -u)
group_id=$(id -g)
user_name=$(whoami)

# Define source and destination file paths
source_file=".devcontainer/devcontainer_base.json"
destination_file=".devcontainer/devcontainer.json"

# Check if the source file exists
if [[ ! -f $source_file ]]; then
echo "Source file $source_file does not exist. Exiting."
exit 1
fi

# Create the destination file with the updated content
sed -e "s/\"USER_UID\": \"1000\"/\"USER_UID\": \"$user_id\"/g" \
-e "s/\"USER_GID\": \"1000\"/\"USER_GID\": \"$group_id\"/g" \
-e "s/\"remoteUser\": \"ubuntu\"/\"remoteUser\": \"$user_name\"/g" \
-e "s/\"USERNAME\": \"ubuntu\"/\"USERNAME\": \"$user_name\"/g" \
-e "s/USER=ubuntu/USER=$user_name/g" \
"$source_file" > "$destination_file"

# Verify the operation and provide feedback
if [[ $? -eq 0 ]]; then
echo "File successfully created at $destination_file with updated user information:"
echo " USER_UID: $user_id"
echo " USER_GID: $group_id"
echo " remoteUser: $user_name"
else
echo "Failed to create the file $destination_file."
exit 2
fi
4 changes: 2 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: docker build -t presubmit-image -f .devcontainer/Dockerfile .

- name: Run Tests
run: docker run --rm -v "$(pwd):/workspace" --user "$(id -u):$(id -g)" presubmit-image bazel test --jobs=4 testing/...
run: docker run --rm -v "$(pwd):/workspace" --user "ubuntu:ubuntu" presubmit-image bazel test --jobs=4 testing/...

- name: Run vmsdk Tests
run: docker run --rm -v "$(pwd):/workspace" --user "$(id -u):$(id -g)" presubmit-image bazel test --jobs=4 vmsdk/testing/...
run: docker run --rm -v "$(pwd):/workspace" --user "ubuntu:ubuntu" presubmit-image bazel test --jobs=4 vmsdk/testing/...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ MODULE.bazel.lock
resolved_deps.py
*.swp
compile_commands.json
.devcontainer/devcontainer.json
11 changes: 9 additions & 2 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ For development purposes, it is recommended to use <b>VSCode</b>, which is alrea
- Note: Building the code may take some time, and it is important to use a host with decent CPU capacity. If you prefer, you can use a remote host. In that case, also install the following extensions:
- `Remote - SSH` by Microsoft
- `Remote Explorer` by Microsoft
2. <b>Open the Repository in VSCode:</b>

2. <b>Run the dev container setup script</b>
- Issue the following command from the cloned repo root directory:
```bash
.devcontainer/setup.sh
```

3. <b>Open the Repository in VSCode:</b>
- On your local machine, open the root directory of the cloned valkey-search repository in VSCode.
- If the repository is located on a remote host:
1. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS) to open the Command Palette.
2. Type Remote-SSH: Connect to Host and select it.
3. Choose the appropriate host and provide any necessary authentication details.

Once connected, VSCode will open the repository in the context of the remote host.


Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bazel_dep(name = "rules_cc", version = "0.0.16")
bazel_dep(name = "abseil-cpp", version = "20240722.0.bcr.1", repo_name = "com_google_absl")
bazel_dep(name = "protobuf", version = "29.2", repo_name = "com_google_protobuf")
bazel_dep(name = "boringssl", version = "0.20241024.0")
bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "grpc", version = "1.63.1.bcr.1", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_code_re2") # rename to com_google_re2
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True, repo_name = "com_google_googletest")
Expand Down
5 changes: 5 additions & 0 deletions ci/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
set -e
export MOUNTED_DIR=$(pwd)
echo "export MOUNTED_DIR=$MOUNTED_DIR" >> /home/$USER/.bashrc
if [ "$ENABLE_COMP_DB_REFRESH" = "true" ]; then
echo "$(pwd)/ci/refresh_comp_db.sh &> /dev/null &" >> /home/$USER/.bashrc
fi
bazel build //...
bazel run @hedron_compile_commands//:refresh_all
17 changes: 17 additions & 0 deletions ci/refresh_comp_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set +e
LOCKFILE="/tmp/rebuild_comp_db.lock"
if [ -e "$LOCKFILE" ] && kill -0 "$(cat "$LOCKFILE")" 2>/dev/null; then
echo "Script is already running. Exiting."
exit 1
fi
echo $$ > "$LOCKFILE"
trap "rm -f $LOCKFILE" EXIT
if [ ! -d $MOUNTED_DIR ]; then
echo "Error: Directory $MOUNTED_DIR does not exist."
exit 1
fi
cd $MOUNTED_DIR
while sleep 1; do
find src testing vmsdk/src vmsdk/testing -type f \( -iname \*.cc -o -iname \*.h -o -iname BUILD \) | entr -d bazel run @hedron_compile_commands//:refresh_all &> /dev/null
done

0 comments on commit fe4a62a

Please sign in to comment.