Skip to content

The open alternative to Salesforce, designed for AI.

fix(docker): resolve release tags from the twenty/v* namespace and fail on bad downloads (#25524)

Marief471ffcbcce7
diff --git a/packages/twenty-docker/scripts/1-click.sh b/packages/twenty-docker/scripts/1-click.sh
index 7e9c535f428..4af31a902e1 100644
--- a/packages/twenty-docker/scripts/1-click.sh
+++ b/packages/twenty-docker/scripts/1-click.sh
@@ -1,22 +1,31 @@
-pull_version=${VERSION:-$(curl -s https://api.github.com/repos/twentyhq/twenty/tags | grep '"name":' | head -n 1 | cut -d '"' -f 4)}
+release_tag_pattern='^v[0-9]+\.[0-9]+\.[0-9]+$'
+if [[ -n "$VERSION" && ! "$VERSION" =~ $release_tag_pattern ]]; then
+ echo "Error: VERSION must be a full release tag such as v2.38.1, omit it to install the latest release."
+ exit 1
+fi
+
+pull_version=${VERSION:-$(curl -fsS --retry 3 --retry-delay 2 "https://hub.docker.com/v2/repositories/twentycrm/twenty/tags?page_size=100" | grep -o '"name":"[^"]*"' | cut -d'"' -f4 | grep -E "$release_tag_pattern" | sort -V | tail -n1)}
if [[ -z "$pull_version" ]]; then
- echo "Error: Unable to fetch the latest version tag. Please check your network connection or the GitHub API response."
+ echo "Error: Unable to fetch the latest version tag. Please check your network connection or the Docker Hub API response."
exit 1
fi
-pull_branch=${BRANCH:-$pull_version}
+pull_branch=${BRANCH:-twenty/$pull_version}
-version_num=${pull_version#v}
-target_version="0.32.4"
+install_url="https://raw.githubusercontent.com/twentyhq/twenty/$pull_branch/packages/twenty-docker/scripts/install.sh"
-# We moved the install script to a different location in v0.32.4
-if [[ -n "$BRANCH" ]] || [[ "$(printf '%s\n' "$target_version" "$version_num" | sort -V | head -n1)" != "$version_num" ]]; then
- curl -sL "https://raw.githubusercontent.com/twentyhq/twenty/$pull_branch/packages/twenty-docker/scripts/install.sh" -o twenty_install.sh
-else
- curl -sL "https://raw.githubusercontent.com/twentyhq/twenty/$pull_branch/install.sh" -o twenty_install.sh
+if ! curl -fsSL --retry 3 --retry-delay 2 -o twenty_install.sh.tmp "$install_url"; then
+ rm -f twenty_install.sh.tmp
+ echo "Error: Failed to download the install script from $install_url"
+ echo "If this is a 404, the twenty/<version> ref does not exist: releases that predate the twenty/ tag namespace (v2.9.0 and older) are not supported."
+ echo "Anything else is usually GitHub rate limiting your network, in which case retrying in a minute will work."
+ exit 1
fi
+mv twenty_install.sh.tmp twenty_install.sh
chmod +x twenty_install.sh
-VERSION="$VERSION" BRANCH="$BRANCH" ./twenty_install.sh
+VERSION="$pull_version" BRANCH="$pull_branch" ./twenty_install.sh
+install_status=$?
rm twenty_install.sh
+exit $install_status
diff --git a/packages/twenty-docker/scripts/install.sh b/packages/twenty-docker/scripts/install.sh
index 58c376981bd..69f05529eac 100755
--- a/packages/twenty-docker/scripts/install.sh
+++ b/packages/twenty-docker/scripts/install.sh
@@ -43,9 +43,34 @@ function on_exit {
}
trap on_exit EXIT
+# Download a file, failing loudly instead of writing an HTTP error page to disk.
+# curl retries 429/5xx on its own; raw.githubusercontent.com throttles by IP.
+function download {
+ local url=$1
+ local dest=$2
+ if ! curl -fsSL --retry 3 --retry-delay 2 -o "$dest.tmp" "$url"; then
+ rm -f "$dest.tmp"
+ echo -e "\t❌ Failed to download $url"
+ echo -e "\t\tIf this is a 404, the twenty/<version> ref does not exist: releases that predate the twenty/ tag namespace (v2.9.0 and older) are not supported."
+ echo -e "\t\tAnything else is usually GitHub rate limiting your network, in which case retrying in a minute will work."
+ exit 1
+ fi
+ mv "$dest.tmp" "$dest"
+}
+
# Use environment variables VERSION and BRANCH, with defaults if not set
-version=${VERSION:-$(curl -s "https://hub.docker.com/v2/repositories/twentycrm/twenty/tags" | grep -o '"name":"[^"]*"' | grep -v 'latest' | cut -d'"' -f4 | sort -V | tail -n1)}
-branch=${BRANCH:-$(curl -s https://api.github.com/repos/twentyhq/twenty/tags | grep '"name":' | head -n 1 | cut -d '"' -f 4)}
+release_tag_pattern='^v[0-9]+\.[0-9]+\.[0-9]+$'
+if [[ -n "$VERSION" && ! "$VERSION" =~ $release_tag_pattern ]]; then
+ echo -e "\t❌ VERSION must be a full release tag such as v2.38.1, omit it to install the latest release."
+ exit 1
+fi
+version=${VERSION:-$(curl -fsS --retry 3 --retry-delay 2 "https://hub.docker.com/v2/repositories/twentycrm/twenty/tags?page_size=100" | grep -o '"name":"[^"]*"' | cut -d'"' -f4 | grep -E "$release_tag_pattern" | sort -V | tail -n1)}
+if [ -z "$version" ]; then
+ echo -e "\t❌ Unable to resolve the latest release from Docker Hub. Check your network, or set VERSION explicitly."
+ exit 1
+fi
+# Deriving the branch from the image tag keeps docker-compose.yml and the image in lockstep.
+branch=${BRANCH:-twenty/$version}
echo "🚀 Using docker version $version and Github branch $branch"
@@ -74,11 +99,11 @@ mkdir -p "$dir_name" && cd "$dir_name" || { echo "❌ Failed to create/access di
# Copy twenty/packages/twenty-docker/docker-compose.yml in it
echo -e "\t• Copying docker-compose.yml"
-curl -sLo docker-compose.yml https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/docker-compose.yml
+download "https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/docker-compose.yml" docker-compose.yml
# Copy twenty/packages/twenty-docker/.env.example to .env
echo -e "\t• Setting up .env file"
-curl -sLo .env https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/.env.example
+download "https://raw.githubusercontent.com/twentyhq/twenty/$branch/packages/twenty-docker/.env.example" .env
# Replace TAG=latest by TAG=<latest_release or version input>
if [[ $(uname) == "Darwin" ]]; then
diff --git a/packages/twenty-docs/developers/self-host/capabilities/docker-compose.mdx b/packages/twenty-docs/developers/self-host/capabilities/docker-compose.mdx
index 650a2c9b632..a4c56e01b55 100644
--- a/packages/twenty-docs/developers/self-host/capabilities/docker-compose.mdx
+++ b/packages/twenty-docs/developers/self-host/capabilities/docker-compose.mdx
@@ -28,12 +28,18 @@ Install the latest stable version of Twenty with a single command:
bash <(curl -sL https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/scripts/install.sh)
```
-To install a specific version or branch:
+To install a specific version:
```bash
-VERSION=vx.y.z BRANCH=branch-name bash <(curl -sL https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/scripts/install.sh)
+VERSION=v2.38.1 bash <(curl -sL https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/scripts/install.sh)
```
-- Replace x.y.z with the desired version number.
-- Replace branch-name with the name of the branch you want to install.
+- `VERSION` must be a full release tag published on [Docker Hub](https://hub.docker.com/r/twentycrm/twenty/tags), such as `v2.38.1`. Aliases such as `v2` or `latest` are not accepted.
+- The matching `docker-compose.yml` is fetched from the `twenty/<version>` git tag, so releases that predate these tags (v2.9.0 and older) can't be installed with the script.
+
+To fetch the configuration files from a branch instead, for example to test unreleased changes:
+```bash
+BRANCH=branch-name bash <(curl -sL https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/scripts/install.sh)
+```
+- Replace branch-name with the branch to fetch `docker-compose.yml` and `.env.example` from. The image still defaults to the latest release unless `VERSION` is also set.
## Option 2: Manual steps
Follow these steps for a manual setup.