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

fix: add network in linux installation script #1566

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 54 additions & 13 deletions keploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ installKeploy (){
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin

set_alias 'sudo -E env PATH="$PATH" keploybin'

check_docker_status_for_linux
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
}

check_sudo(){
Expand All @@ -36,6 +43,13 @@ installKeploy (){
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin

set_alias 'sudo -E env PATH="$PATH" keploybin'

check_docker_status_for_linux
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
}

append_to_rc() {
Expand Down Expand Up @@ -96,21 +110,59 @@ installKeploy (){
fi
}

check_docker_status_for_linux() {
check_sudo
sudoCheck=$?
network_alias=""
if [ "$sudoCheck" -eq 0 ] && [ $OS_NAME = "Linux" ]; then
# Add sudo to docker
network_alias="sudo"
fi
if ! $network_alias which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker and reinstall keploy if you are willing to use applications with docker"
Copy link
Member

Choose a reason for hiding this comment

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

The logs for mac and linux shouldn't be so different in my opinion. and I think "willing" doesn't fit well in a log message. I think just change both to "Docker not found on device. Please install docker and reinstall keploy". Same thing for starting docker.

Copy link
Member Author

Choose a reason for hiding this comment

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

we shouldn't force user to use docker on linux if he has no application with docker

return 0
fi
if ! $network_alias docker info &> /dev/null; then
echo "Please start Docker and reinstall keploy if you are willing to use applications with docker"
return 0
fi
return 1
}


install_docker() {
check_docker_status_for_Darwin() {
check_sudo
sudoCheck=$?
network_alias=""
if [ "$sudoCheck" -eq 0 ] && [ $OS_NAME = "Linux" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

os name should be darwin here.

Copy link
Member Author

Choose a reason for hiding this comment

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

added

# Add sudo to docker
network_alias="sudo"
fi
if ! $network_alias which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker to use Keploy"
return 0
fi
# Check if docker is running
if ! $network_alias docker info &> /dev/null; then
echo "Keploy only supports intercepting and replaying docker containers on macOS, and requires Docker to be installed and running. Please start Docker and try again."
return 0
fi
return 1
}

add_network() {
if ! $network_alias docker network ls | grep -q 'keploy-network'; then
$network_alias docker network create keploy-network
fi
}

install_docker() {
Copy link
Member

Choose a reason for hiding this comment

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

why haven't you called add_network in this function? In macos, we still install keploy via docker, so it will be needed in that case. In the future when we add a binary for macos, we can remove the install_docker completely

Copy link
Member Author

Choose a reason for hiding this comment

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

Added add_network in darwin

if [ "$OS_NAME" = "Darwin" ]; then
check_docker_status_for_Darwin
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
if ! docker volume inspect debugfs &>/dev/null; then
docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs
fi
Expand All @@ -126,19 +178,8 @@ installKeploy (){
if [ "$IS_CI" = false ]; then
OS_NAME="$(uname -s)"
if [ "$OS_NAME" = "Darwin" ]; then
if ! which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker to use Keploy"
return
fi

# Check if docker is running
if ! docker info &> /dev/null; then
echo "Keploy only supports intercepting and replaying docker containers on macOS, and requires Docker to be installed and running. Please start Docker and try again."
return
fi
install_docker
return

elif [ "$OS_NAME" = "Linux" ]; then
if ! sudo mountpoint -q /sys/kernel/debug; then
sudo mount -t debugfs debugfs /sys/kernel/debug
Expand Down