Skip to content

Commit

Permalink
adding dev container setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
yairgott committed Jan 25, 2025
1 parent 7164c65 commit e1bc348
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
19 changes: 14 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,28 @@ ENV PATH="/usr/local/bin:$PATH"
# 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;

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/vscode/.bashrc
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}

# 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++
Expand Down
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
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
4 changes: 2 additions & 2 deletions ci/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -e
export MOUNTED_DIR=$(pwd)
echo "export MOUNTED_DIR=$MOUNTED_DIR" >> /home/vscode/.bashrc
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/vscode/.bashrc
echo "$(pwd)/ci/refresh_comp_db.sh &> /dev/null &" >> /home/$USER/.bashrc
fi
bazel build //...
bazel run @hedron_compile_commands//:refresh_all

0 comments on commit e1bc348

Please sign in to comment.