feat: add one liner install command (#4613)
* feat: add one liner * fix: interactive issue & add support for both linux & mac * feat: move quick start documentation * feat: catch errors * feat: check if directory exists * feat: default to yes for prompt * feat: open in browser * fix: format * feat: do not expose STORAGE_LOCAL_PATH env but handle the case where it would be set * fix: db reset command wasn't working out of the box * Update install.sh Co-authored-by: Darek Desu <4459421+darekdesu@users.noreply.github.com> * feat: harden the whole UX with one-liner * fix: small logical order adjustment * Update packages/twenty-docs/docs/start/self-hosting/docker-compose.mdx --------- Co-authored-by: Darek Desu <4459421+darekdesu@users.noreply.github.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
149
install.sh
Executable file
149
install.sh
Executable file
@ -0,0 +1,149 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔧 Checking dependencies..."
|
||||
if ! command -v docker &>/dev/null; then
|
||||
echo -e "\t❌ Docker is not installed or not in PATH. Please install Docker first.\n\t\tSee https://docs.docker.com/get-docker/"
|
||||
exit 1
|
||||
fi
|
||||
# Check if docker compose plugin is installed
|
||||
if ! docker compose version &>/dev/null; then
|
||||
echo -e "\t❌ Docker Compose is not installed or not in PATH (n.b. docker-compose is deprecated)\n\t\tUpdate docker or install docker-compose-plugin\n\t\tOn Linux: sudo apt-get install docker-compose-plugin\n\t\tSee https://docs.docker.com/compose/install/"
|
||||
exit 1
|
||||
fi
|
||||
# Check if docker is started
|
||||
if ! docker info &>/dev/null; then
|
||||
echo -e "\t❌ Docker is not running.\n\t\tPlease start Docker Desktop, Docker or check documentation at https://docs.docker.com/config/daemon/start/"
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v curl &>/dev/null; then
|
||||
echo -e "\t❌ Curl is not installed or not in PATH.\n\t\tOn macOS: brew install curl\n\t\tOn Linux: sudo apt install curl"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Catch errors
|
||||
set -e
|
||||
function on_exit {
|
||||
# $? is the exit status of the last command executed
|
||||
local exit_status=$?
|
||||
if [ $exit_status -ne 0 ]; then
|
||||
echo "❌ Something went wrong, exiting: $exit_status"
|
||||
fi
|
||||
}
|
||||
trap on_exit EXIT
|
||||
|
||||
# Use environment variables VERSION and BRANCH, with defaults if not set
|
||||
version=${VERSION:-$(curl -s https://api.github.com/repos/twentyhq/twenty/releases/latest | grep '"tag_name":' | cut -d '"' -f 4)}
|
||||
branch=${BRANCH:-main}
|
||||
|
||||
echo "🚀 Using version $version and branch $branch"
|
||||
|
||||
dir_name="twenty"
|
||||
function ask_directory {
|
||||
read -p "📁 Enter the directory name to setup the project (default: $dir_name): " answer
|
||||
if [ -n "$answer" ]; then
|
||||
dir_name=$answer
|
||||
fi
|
||||
}
|
||||
|
||||
ask_directory
|
||||
|
||||
while [ -d "$dir_name" ]; do
|
||||
read -p "🚫 Directory '$dir_name' already exists. Do you want to overwrite it? (y/N) " answer
|
||||
if [ "$answer" = "y" ]; then
|
||||
break
|
||||
else
|
||||
ask_directory
|
||||
fi
|
||||
done
|
||||
|
||||
# Create a directory named twenty
|
||||
echo "📁 Creating directory '$dir_name'"
|
||||
mkdir -p "$dir_name" && cd "$dir_name" || { echo "❌ Failed to create/access directory '$dir_name'"; exit 1; }
|
||||
|
||||
# Copy the twenty/packages/twenty-docker/prod/docker-compose.yml file in it
|
||||
echo "\t• Copying docker-compose.yml"
|
||||
curl -sLo docker-compose.yml https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/prod/docker-compose.yml
|
||||
|
||||
# Copy twenty/packages/twenty-docker/prod/.env.example to .env
|
||||
echo "\t• Setting up .env file"
|
||||
curl -sLo .env https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/prod/.env.example
|
||||
|
||||
# Replace TAG=latest by TAG=<latest_release or version input>
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
# Running on macOS
|
||||
sed -i '' "s/TAG=latest/TAG=$version/g" .env
|
||||
else
|
||||
# Assuming Linux
|
||||
sed -i'' "s/TAG=latest/TAG=$version/g" .env
|
||||
fi
|
||||
|
||||
# Generate random strings for secrets
|
||||
echo "ACCESS_TOKEN_SECRET=$(openssl rand -base64 32)" >>.env
|
||||
echo "LOGIN_TOKEN_SECRET=$(openssl rand -base64 32)" >>.env
|
||||
echo "REFRESH_TOKEN_SECRET=$(openssl rand -base64 32)" >>.env
|
||||
echo "FILE_TOKEN_SECRET=$(openssl rand -base64 32)" >>.env
|
||||
|
||||
echo "\t• .env configuration completed"
|
||||
|
||||
port=3000
|
||||
# Check if command nc is available
|
||||
if command -v nc &> /dev/null; then
|
||||
# Check if port 3000 is already in use, propose to change it
|
||||
while nc -zv localhost $port &>/dev/null; do
|
||||
read -p "🚫 Port $port is already in use. Do you want to use another port? (Y/n) " answer
|
||||
if [ "$answer" = "n" ]; then
|
||||
continue
|
||||
fi
|
||||
read -p "Enter a new port number: " new_port
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
sed -i '' "s/$port:$port/$new_port:$port/g" docker-compose.yml
|
||||
else
|
||||
sed -i'' "s/$port:$port/$new_port:$port/g" docker-compose.yml
|
||||
fi
|
||||
port=$new_port
|
||||
done
|
||||
fi
|
||||
|
||||
# Ask user if he wants to start the project
|
||||
read -p "🚀 Do you want to start the project now? (Y/n) " answer
|
||||
if [ "$answer" = "n" ]; then
|
||||
echo "✅ Project setup completed. Run 'docker-compose up -d' to start."
|
||||
exit 0
|
||||
else
|
||||
echo "🐳 Starting Docker containers..."
|
||||
docker compose up -d
|
||||
# Check if port is listening
|
||||
echo -n "Waiting for server to start..."
|
||||
while [ ! $(docker inspect --format='{{.State.Health.Status}}' twenty-server-1) = "healthy" ]; do
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
echo ""
|
||||
echo "✅ Server is up and running"
|
||||
fi
|
||||
|
||||
function ask_open_browser {
|
||||
read -p "🌐 Do you want to open the project in your browser? (Y/n) " answer
|
||||
if [ "$answer" = "n" ]; then
|
||||
echo "✅ Setup completed. Access your project at http://localhost:$port"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Ask user if he wants to open the project
|
||||
# Running on macOS
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
ask_open_browser
|
||||
|
||||
open "http://localhost:$port"
|
||||
# Assuming Linux
|
||||
else
|
||||
# xdg-open is not installed, we could be running in a non gui environment
|
||||
if command -v xdg-open >/dev/null 2>&1; then
|
||||
ask_open_browser
|
||||
|
||||
xdg-open "http://localhost:$port"
|
||||
else
|
||||
echo "✅ Setup completed. Your project is available at http://localhost:$port"
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user