-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_dev_env.sh
More file actions
136 lines (111 loc) · 3.69 KB
/
setup_dev_env.sh
File metadata and controls
136 lines (111 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
setup_venv(){
echo "Setting up virtual environment"
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
source .venv/bin/activate
}
ensure_mac_brew(){
if ! command -v brew > /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew update
}
install_docker_mac() {
echo "Detected macOS. Installing Docker..."
# Check if Homebrew is installed
ensure_mac_brew
brew install --cask docker
open /Applications/Docker.app && echo "Docker installed successfully"
}
install_python_mac(){
ensure_mac_brew
brew install python@3.10
}
install_docker_apt() {
echo "Detected apt(ubuntu, debian). Installing Docker..."
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker && echo "Docker installed successfully"
}
install_python_apt(){
sudo apt update
sudo apt install -y python3.10
}
install_docker_dnf() {
echo "Detected dnf (feedora, redhat). Installing Docker..."
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker. && echo "Docker installed successfully"
}
install_python_dnf(){
sudo dnf install -y python3.10
}
install_docker_pacman() {
echo "Detected pacman (arch). Installing Docker..."
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm docker
sudo systemctl start docker
sudo systemctl enable docker && echo "Docker installed successfully"
}
install_python_pacman(){
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm python3.10
}
# Function to install Docker based on the OS and package manager
ensure_docker() {
[ "$(uname)" == "Darwin" ] && install_docker_mac
command -v apt >/dev/null 2>&1 && install_docker_apt
command -v dnf >/dev/null 2>&1 && install_docker_dnf
command -v pacman >/dev/null 2>&1 && install_docker_pacman
}
ensure_python(){
[ "$(uname)" == "Darwin" ] && install_python_mac
command -v apt >/dev/null 2>&1 && install_python_apt
command -v dnf >/dev/null 2>&1 && install_python_dnf
command -v pacman >/dev/null 2>&1 && install_python_pacman
}
# Check if Docker is installed and running
if [ -x "$(command -v docker)" ]; then
echo "Docker is already installed."
# Check if Docker daemon is running
if ! sudo docker info > /dev/null 2>&1; then
echo "Docker is installed but not running. Starting Docker..."
sudo systemctl start docker || open /Applications/Docker.app
fi
else
echo "Docker is not installed. Attempting to install Docker..."
ensure_docker
fi
if ! docker buildx version > /dev/null 2>&1; then
echo "Docker buildx is not installed. Please install Docker buildx plugin."
exit 1
fi
# check if builder instance exists
#
#
create_mybuilder(){
echo "Creating a new builder instance..."
sudo docker buildx create --name mybuilder --use
}
use_mybuilder(){
echo "Using existing builder instance..."
sudo docker buildx use mybuilder
}
activate_mybuilder(){
echo "Activating existing builder instance..."
sudo docker buildx inspect --bootstrap
}
# check if builder instance exists
command -v sudo dodcker buildx inspect mybuilder > /dev/null 2>&1 || create_mybuilder
# check if builder instance is active
command -v sudo docker buildx inspect mybuilder | grep -q "Status:.*inactive" > /dev/null 2>&1 && activate_mybuilder || use_mybuilder
# check if python3.10 is installed
command -v python3.10 > /dev/null 2>&1 || ensure_python
# setup local venv and install dependencies
setup_venv