Skip to content

Commit

Permalink
Run docker commands with sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
judahpaul16 committed May 18, 2024
1 parent ddd5c1b commit 539eb1d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
72 changes: 37 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ This guide will explain how to build your own. It's pretty straight forward. You
```bash
curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setup.sh | \
bash -s -- --no-build
docker ps -aq -f name=gpt-home | xargs -r docker rm -f
docker pull judahpaul/gpt-home
docker run --restart unless-stopped -d --name gpt-home \
sudo docker ps -aq -f name=gpt-home | xargs -r docker rm -f
sudo docker pull judahpaul/gpt-home
sudo docker run --restart unless-stopped -d --name gpt-home \
--privileged \
--net=host \
--tmpfs /run \
Expand Down Expand Up @@ -370,25 +370,25 @@ Alternatively, you can put this at the end of your `~/.bashrc` file. (recommende
export OPENAI_API_KEY="your_openai_api_key_here"
# Optional: Add these aliases to your .bashrc file for easier management
alias gpt-start="docker exec -it gpt-home supervisorctl start app"
alias gpt-restart="docker exec -it gpt-home supervisorctl restart app"
alias gpt-stop="docker exec -it gpt-home supervisorctl stop app"
alias gpt-status="docker exec -it gpt-home supervisorctl status app"
alias gpt-log="docker exec -it gpt-home tail -n 100 -f /app/src/events.log"
alias wi-start="docker exec -it gpt-home supervisorctl start web-interface"
alias wi-restart="docker exec -it gpt-home supervisorctl restart web-interface && sudo systemctl restart nginx"
alias wi-stop="docker exec -it gpt-home supervisorctl stop web-interface"
alias wi-status="docker exec -it gpt-home supervisorctl status web-interface"
alias wi-build="docker exec -it gpt-home bash -c 'cd /app/src/frontend && npm run build'"
alias gpt-start="sudo docker exec -it gpt-home supervisorctl start app"
alias gpt-restart="sudo docker exec -it gpt-home supervisorctl restart app"
alias gpt-stop="sudo docker exec -it gpt-home supervisorctl stop app"
alias gpt-status="sudo docker exec -it gpt-home supervisorctl status app"
alias gpt-log="sudo docker exec -it gpt-home tail -n 100 -f /app/src/events.log"
alias wi-start="sudo docker exec -it gpt-home supervisorctl start web-interface"
alias wi-restart="sudo docker exec -it gpt-home supervisorctl restart web-interface && sudo systemctl restart nginx"
alias wi-stop="sudo docker exec -it gpt-home supervisorctl stop web-interface"
alias wi-status="sudo docker exec -it gpt-home supervisorctl status web-interface"
alias wi-build="sudo docker exec -it gpt-home bash -c 'cd /app/src/frontend && npm run build'"
alias wi-log="tail -n 100 -f /var/log/nginx/access.log"
alias wi-error="tail -n 100 -f /var/log/nginx/error.log"
alias spotifyd-start="docker exec -it gpt-home supervisorctl start spotifyd"
alias spotifyd-restart="docker exec -it gpt-home supervisorctl restart spotifyd"
alias spotifyd-stop="docker exec -it gpt-home supervisorctl stop spotifyd"
alias spotifyd-status="docker exec -it gpt-home supervisorctl status spotifyd"
alias spotifyd-log="docker exec -it gpt-home tail -n 100 -f /var/log/spotifyd.log"
alias spotifyd-start="sudo docker exec -it gpt-home supervisorctl start spotifyd"
alias spotifyd-restart="sudo docker exec -it gpt-home supervisorctl restart spotifyd"
alias spotifyd-stop="sudo docker exec -it gpt-home supervisorctl stop spotifyd"
alias spotifyd-status="sudo docker exec -it gpt-home supervisorctl status spotifyd"
alias spotifyd-log="sudo docker exec -it gpt-home tail -n 100 -f /var/log/spotifyd.log"
```
Run `source ~/.bashrc` to apply the changes to your current terminal session.

Expand All @@ -397,9 +397,9 @@ The setup script will take quite a while to run ***(900.0s+ to build and setup d
```bash
curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setup.sh | \
bash -s -- --no-build
docker ps -aq -f name=gpt-home | xargs -r docker rm -f
docker pull judahpaul/gpt-home
docker run --restart unless-stopped -d --name gpt-home \
sudo docker ps -aq -f name=gpt-home | xargs -r docker rm -f
sudo docker pull judahpaul/gpt-home
sudo docker run --restart unless-stopped -d --name gpt-home \
--privileged \
--net=host \
--tmpfs /run \
Expand Down Expand Up @@ -446,7 +446,7 @@ curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setu
You can also run the container interactively if you need to debug or test changes to the codebase with the `-it` (interactive terminal), `--entrypoint /bin/bash`, and `--rm` (remove on process exit) flags. This will drop you into a shell session inside the container. Alternatively, if the conatiner is already running:
```bash
docker exec -it gpt-home bash
sudo docker exec -it gpt-home bash
```
This will start the container and drop you into a shell session inside the container.
Expand Down Expand Up @@ -518,6 +518,8 @@ install containerd
install docker
install docker-buildx-plugin
install alsa-utils
sudo systemctl enable docker
sudo systemctl start docker
# Create ALSA config (asound.conf, adjust as needed)
sudo cat > /etc/asound.conf <<EOF
Expand Down Expand Up @@ -591,29 +593,29 @@ if [[ "$1" != "--no-build" ]]; then
git clone https://github.com/judahpaul16/gpt-home ~/gpt-home
cd ~/gpt-home
echo "Checking if the container 'gpt-home' is already running..."
if [ $(docker ps -q -f name=gpt-home) ]; then
if [ $(sudo docker ps -q -f name=gpt-home) ]; then
echo "Stopping running container 'gpt-home'..."
docker stop gpt-home
sudo docker stop gpt-home
fi
echo "Checking for existing container 'gpt-home'..."
if [ $(docker ps -aq -f status=exited -f name=gpt-home) ]; then
if [ $(sudo docker ps -aq -f status=exited -f name=gpt-home) ]; then
echo "Removing existing container 'gpt-home'..."
docker rm -f gpt-home
sudo docker rm -f gpt-home
fi
echo "Pruning Docker system..."
docker system prune -f
sudo docker system prune -f
# Check if the buildx builder exists, if not create and use it
if ! docker buildx ls | grep -q mybuilder; then
docker buildx create --name mybuilder --use
docker buildx inspect --bootstrap
if ! sudo docker buildx ls | grep -q mybuilder; then
sudo docker buildx create --name mybuilder --use
sudo docker buildx inspect --bootstrap
fi
# Building Docker image 'gpt-home' for ARMhf architecture
echo "Building Docker image 'gpt-home' for ARMhf..."
timeout 3600 docker buildx build --platform linux/arm64 -t gpt-home . --load
sudo timeout 3600 docker buildx build --platform linux/arm64 -t gpt-home . --load
if [ $? -ne 0 ]; then
echo "Docker build failed. Exiting..."
Expand All @@ -623,7 +625,7 @@ if [[ "$1" != "--no-build" ]]; then
echo "Container 'gpt-home' is now ready to run."
echo "Running container 'gpt-home' from image 'gpt-home'..."
docker run --restart unless-stopped -d --name gpt-home \
sudo docker run --restart unless-stopped -d --name gpt-home \
--privileged \
--net=host \
--tmpfs /run \
Expand All @@ -641,12 +643,12 @@ if [[ "$1" != "--no-build" ]]; then
fi
# Show status of the container
docker ps -a | grep gpt-home
sudo docker ps -a | grep gpt-home
sleep 10
# Show status of all programs managed by Supervisor
docker exec -i gpt-home supervisorctl status
sudo docker exec -i gpt-home supervisorctl status
```
</p>
Expand Down
24 changes: 12 additions & 12 deletions contrib/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,29 @@ if [[ "$1" != "--no-build" ]]; then
git clone https://github.com/judahpaul16/gpt-home ~/gpt-home
cd ~/gpt-home
echo "Checking if the container 'gpt-home' is already running..."
if [ $(docker ps -q -f name=gpt-home) ]; then
if [ $(sudo docker ps -q -f name=gpt-home) ]; then
echo "Stopping running container 'gpt-home'..."
docker stop gpt-home
sudo docker stop gpt-home
fi

echo "Checking for existing container 'gpt-home'..."
if [ $(docker ps -aq -f status=exited -f name=gpt-home) ]; then
if [ $(sudo docker ps -aq -f status=exited -f name=gpt-home) ]; then
echo "Removing existing container 'gpt-home'..."
docker rm -f gpt-home
sudo docker rm -f gpt-home
fi

echo "Pruning Docker system..."
docker system prune -f
sudo docker system prune -f

# Check if the buildx builder exists, if not create and use it
if ! docker buildx ls | grep -q mybuilder; then
docker buildx create --name mybuilder --use
docker buildx inspect --bootstrap
if ! sudo docker buildx ls | grep -q mybuilder; then
sudo docker buildx create --name mybuilder --use
sudo docker buildx inspect --bootstrap
fi

# Building Docker image 'gpt-home' for ARMhf architecture
echo "Building Docker image 'gpt-home' for ARMhf..."
timeout 3600 docker buildx build --platform linux/arm64 -t gpt-home . --load
sudo timeout 3600 docker buildx build --platform linux/arm64 -t gpt-home . --load

if [ $? -ne 0 ]; then
echo "Docker build failed. Exiting..."
Expand All @@ -164,7 +164,7 @@ if [[ "$1" != "--no-build" ]]; then
echo "Container 'gpt-home' is now ready to run."

echo "Running container 'gpt-home' from image 'gpt-home'..."
docker run --restart unless-stopped -d --name gpt-home \
sudo docker run --restart unless-stopped -d --name gpt-home \
--privileged \
--net=host \
--tmpfs /run \
Expand All @@ -182,9 +182,9 @@ if [[ "$1" != "--no-build" ]]; then
fi

# Show status of the container
docker ps -a | grep gpt-home
sudo docker ps -a | grep gpt-home

sleep 10

# Show status of all programs managed by Supervisor
docker exec -i gpt-home supervisorctl status
sudo docker exec -i gpt-home supervisorctl status

0 comments on commit 539eb1d

Please sign in to comment.