From 68f019439aeaa904e939a24ba92f6309eba905f2 Mon Sep 17 00:00:00 2001 From: Silvan Buechi Date: Tue, 1 Sep 2026 10:02:49 +0200 Subject: [PATCH 1/2] feat(enterprise): support ssh transport for enterprise download --- images/odoo/README.md | 3 +- images/odoo/bin/download-odoo-enterprise | 66 ++++++++++++++++++++---- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/images/odoo/README.md b/images/odoo/README.md index 521df892..b0e06acf 100644 --- a/images/odoo/README.md +++ b/images/odoo/README.md @@ -252,7 +252,7 @@ Run the `download-odoo-enterprise` script to download the [Odoo Enterprise modul docker compose exec odoo download-odoo-enterprise ``` -This script requires `GITHUB_USERNAME` and `GITHUB_PAT`. The image has a pre-defined `ODOO_ENTERPRISE_REF` and `ODOO_ENTERPRISE_PATH`. +This script downloads a tarball with `GITHUB_USERNAME` and `GITHUB_PAT`, or checks out a shallow git repo with `GIT_SSH_PRIVATE_KEY`. Set the transport with `ODOO_ENTERPRISE_TRANSPORT`, it defaults to `https` when a PAT is set and to `ssh` otherwise. The image has a pre-defined `ODOO_ENTERPRISE_REF` and `ODOO_ENTERPRISE_PATH`. ### Init database @@ -406,6 +406,7 @@ The image can clone git repositories. - `FORGEJO_PAT`: Forgejo access token for https git clone and archive download. - `ADDONS_GIT_REPOS`: Comma or line-break seperated list of git clone urls appended with `#` and branch name. - `ODOO_ENTERPRISE_REF`: Commit ref of Odoo Enterprise repo. Default is based on the image revision date. +- `ODOO_ENTERPRISE_TRANSPORT`: Transport for the Odoo Enterprise download: `https` or `ssh`. Default is `https` when a GitHub PAT is set, else `ssh`. You can use https and git urls for `ADDONS_GIT_REPOS`: diff --git a/images/odoo/bin/download-odoo-enterprise b/images/odoo/bin/download-odoo-enterprise index e5457195..f8d46216 100755 --- a/images/odoo/bin/download-odoo-enterprise +++ b/images/odoo/bin/download-odoo-enterprise @@ -1,14 +1,63 @@ #!/usr/bin/env bash set -e -if [[ -z "$GITHUB_PAT" ]] || [[ -z "$GITHUB_USERNAME" ]]; then - log-entrypoint 'Error: GitHub personal access token or username is not set.' - exit 1 -fi - odoo_enterprise_path="${ODOO_ENTERPRISE_PATH:="/var/lib/odoo/enterprise"}" ref_file="$odoo_enterprise_path/.last_ref" +odoo_enterprise_transport="${ODOO_ENTERPRISE_TRANSPORT:=}" +if [[ -z "$odoo_enterprise_transport" ]]; then + if [[ -n "$GITHUB_PAT" ]] && [[ -n "$GITHUB_USERNAME" ]]; then + odoo_enterprise_transport='https' + else + odoo_enterprise_transport='ssh' + fi +fi + +case "$odoo_enterprise_transport" in + https) + if [[ -z "$GITHUB_PAT" ]] || [[ -z "$GITHUB_USERNAME" ]]; then + log-entrypoint 'Error: GitHub personal access token or username is not set.' + exit 1 + fi + ;; + ssh) + ;; + *) + log-entrypoint "Error: unsupported ODOO_ENTERPRISE_TRANSPORT '$odoo_enterprise_transport' (expected 'https' or 'ssh')." + exit 1 + ;; +esac + +download_https() { + curl -fL -o "$odoo_enterprise_path/archive.tar.gz" \ + "https://${GITHUB_USERNAME}:${GITHUB_PAT}@github.com/odoo/enterprise/archive/$ODOO_ENTERPRISE_REF.tar.gz" + tar -xzf "$odoo_enterprise_path/archive.tar.gz" --strip-components=1 -C "$odoo_enterprise_path" + rm "$odoo_enterprise_path/archive.tar.gz" +} + +download_ssh() { + git_hostname='github.com' + git_url="git@${git_hostname}:odoo/enterprise.git" + + mkdir -p "$HOME/.ssh" + chmod 700 "$HOME/.ssh" + add-ssh-key + ssh-keyscan -t rsa,ed25519 "$git_hostname" > "$HOME/.ssh/known_hosts" 2>/dev/null + + if [[ ! -d "$odoo_enterprise_path/.git" ]]; then + find "$odoo_enterprise_path" -mindepth 1 -maxdepth 1 ! -name '.last_ref' -exec rm -rf {} + + + log-entrypoint "Init git repo ${git_url} in $odoo_enterprise_path." + git -C "$odoo_enterprise_path" init -q + git -C "$odoo_enterprise_path" remote add origin "$git_url" + fi + + git -C "$odoo_enterprise_path" fetch -q --depth 1 origin "$ODOO_ENTERPRISE_REF" + git -C "$odoo_enterprise_path" checkout -q -f FETCH_HEAD + + remove-ssh-key +} + mkdir -p "$odoo_enterprise_path" last_ref="" if [[ -f "$ref_file" ]]; then @@ -16,11 +65,8 @@ if [[ -f "$ref_file" ]]; then fi if [[ -z "$last_ref" ]] || [[ "$last_ref" != "$ODOO_ENTERPRISE_REF" ]]; then - log-entrypoint "Downloading Odoo Enterprise $ODOO_ENTERPRISE_REF to ${odoo_enterprise_path}..." - curl -L -o "$odoo_enterprise_path/archive.tar.gz" \ - "https://${GITHUB_USERNAME}:${GITHUB_PAT}@github.com/odoo/enterprise/archive/$ODOO_ENTERPRISE_REF.tar.gz" - tar -xzf "$odoo_enterprise_path/archive.tar.gz" --strip-components=1 -C "$odoo_enterprise_path" - rm "$odoo_enterprise_path/archive.tar.gz" + log-entrypoint "Downloading Odoo Enterprise $ODOO_ENTERPRISE_REF to ${odoo_enterprise_path} over ${odoo_enterprise_transport}..." + "download_$odoo_enterprise_transport" echo "$ODOO_ENTERPRISE_REF" > "$ref_file" else log-entrypoint "Odoo Enterprise $ODOO_ENTERPRISE_REF already downloaded. Skipping download." From 639542b21c7e1b4ef34b98aa2242bb8c2ce4111d Mon Sep 17 00:00:00 2001 From: Silvan Buechi Date: Tue, 1 Sep 2026 17:02:28 +0200 Subject: [PATCH 2/2] refactor(enterprise): select download method by url --- images/odoo/README.md | 4 +- images/odoo/bin/download-odoo-enterprise | 102 +++++++++++------------ 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/images/odoo/README.md b/images/odoo/README.md index b0e06acf..fbcc9d17 100644 --- a/images/odoo/README.md +++ b/images/odoo/README.md @@ -252,7 +252,7 @@ Run the `download-odoo-enterprise` script to download the [Odoo Enterprise modul docker compose exec odoo download-odoo-enterprise ``` -This script downloads a tarball with `GITHUB_USERNAME` and `GITHUB_PAT`, or checks out a shallow git repo with `GIT_SSH_PRIVATE_KEY`. Set the transport with `ODOO_ENTERPRISE_TRANSPORT`, it defaults to `https` when a PAT is set and to `ssh` otherwise. The image has a pre-defined `ODOO_ENTERPRISE_REF` and `ODOO_ENTERPRISE_PATH`. +This script downloads an archive with `GITHUB_USERNAME` and `GITHUB_PAT`. With a git url in `ODOO_ENTERPRISE_URL` it checks out a shallow git repo with `GIT_SSH_PRIVATE_KEY` instead. The image has a pre-defined `ODOO_ENTERPRISE_REF` and `ODOO_ENTERPRISE_PATH`. ### Init database @@ -406,7 +406,7 @@ The image can clone git repositories. - `FORGEJO_PAT`: Forgejo access token for https git clone and archive download. - `ADDONS_GIT_REPOS`: Comma or line-break seperated list of git clone urls appended with `#` and branch name. - `ODOO_ENTERPRISE_REF`: Commit ref of Odoo Enterprise repo. Default is based on the image revision date. -- `ODOO_ENTERPRISE_TRANSPORT`: Transport for the Odoo Enterprise download: `https` or `ssh`. Default is `https` when a GitHub PAT is set, else `ssh`. +- `ODOO_ENTERPRISE_URL`: Url of the Odoo Enterprise repo. Default is `https://github.com/odoo/enterprise`. Use a git url like `git@github.com:odoo/enterprise` to download with SSH. You can use https and git urls for `ADDONS_GIT_REPOS`: diff --git a/images/odoo/bin/download-odoo-enterprise b/images/odoo/bin/download-odoo-enterprise index f8d46216..551db512 100755 --- a/images/odoo/bin/download-odoo-enterprise +++ b/images/odoo/bin/download-odoo-enterprise @@ -2,61 +2,12 @@ set -e odoo_enterprise_path="${ODOO_ENTERPRISE_PATH:="/var/lib/odoo/enterprise"}" +odoo_enterprise_url="${ODOO_ENTERPRISE_URL:="https://github.com/odoo/enterprise"}" ref_file="$odoo_enterprise_path/.last_ref" -odoo_enterprise_transport="${ODOO_ENTERPRISE_TRANSPORT:=}" -if [[ -z "$odoo_enterprise_transport" ]]; then - if [[ -n "$GITHUB_PAT" ]] && [[ -n "$GITHUB_USERNAME" ]]; then - odoo_enterprise_transport='https' - else - odoo_enterprise_transport='ssh' - fi -fi - -case "$odoo_enterprise_transport" in - https) - if [[ -z "$GITHUB_PAT" ]] || [[ -z "$GITHUB_USERNAME" ]]; then - log-entrypoint 'Error: GitHub personal access token or username is not set.' - exit 1 - fi - ;; - ssh) - ;; - *) - log-entrypoint "Error: unsupported ODOO_ENTERPRISE_TRANSPORT '$odoo_enterprise_transport' (expected 'https' or 'ssh')." - exit 1 - ;; -esac - -download_https() { - curl -fL -o "$odoo_enterprise_path/archive.tar.gz" \ - "https://${GITHUB_USERNAME}:${GITHUB_PAT}@github.com/odoo/enterprise/archive/$ODOO_ENTERPRISE_REF.tar.gz" - tar -xzf "$odoo_enterprise_path/archive.tar.gz" --strip-components=1 -C "$odoo_enterprise_path" - rm "$odoo_enterprise_path/archive.tar.gz" -} - -download_ssh() { - git_hostname='github.com' - git_url="git@${git_hostname}:odoo/enterprise.git" - - mkdir -p "$HOME/.ssh" - chmod 700 "$HOME/.ssh" - add-ssh-key - ssh-keyscan -t rsa,ed25519 "$git_hostname" > "$HOME/.ssh/known_hosts" 2>/dev/null - - if [[ ! -d "$odoo_enterprise_path/.git" ]]; then - find "$odoo_enterprise_path" -mindepth 1 -maxdepth 1 ! -name '.last_ref' -exec rm -rf {} + - - log-entrypoint "Init git repo ${git_url} in $odoo_enterprise_path." - git -C "$odoo_enterprise_path" init -q - git -C "$odoo_enterprise_path" remote add origin "$git_url" - fi - - git -C "$odoo_enterprise_path" fetch -q --depth 1 origin "$ODOO_ENTERPRISE_REF" - git -C "$odoo_enterprise_path" checkout -q -f FETCH_HEAD - - remove-ssh-key -} +git_proto=$(parse-url "$odoo_enterprise_url" proto) +git_hostname=$(parse-url "$odoo_enterprise_url" hostname) +git_path=$(parse-url "$odoo_enterprise_url" path | sed 's/.git//g') mkdir -p "$odoo_enterprise_path" last_ref="" @@ -65,8 +16,49 @@ if [[ -f "$ref_file" ]]; then fi if [[ -z "$last_ref" ]] || [[ "$last_ref" != "$ODOO_ENTERPRISE_REF" ]]; then - log-entrypoint "Downloading Odoo Enterprise $ODOO_ENTERPRISE_REF to ${odoo_enterprise_path} over ${odoo_enterprise_transport}..." - "download_$odoo_enterprise_transport" + log-entrypoint "Downloading Odoo Enterprise $ODOO_ENTERPRISE_REF to ${odoo_enterprise_path}..." + + if [[ "$git_proto" = "https://" ]]; then + + if [[ -z "$GITHUB_PAT" ]] || [[ -z "$GITHUB_USERNAME" ]]; then + log-entrypoint 'Error: GitHub personal access token or username is not set.' + exit 1 + fi + + curl -fL -o "$odoo_enterprise_path/archive.tar.gz" \ + "${git_proto}${GITHUB_USERNAME}:${GITHUB_PAT}@${git_hostname}/${git_path}/archive/$ODOO_ENTERPRISE_REF.tar.gz" + tar -xzf "$odoo_enterprise_path/archive.tar.gz" --strip-components=1 -C "$odoo_enterprise_path" + rm "$odoo_enterprise_path/archive.tar.gz" + + elif [[ "$git_proto" = "ssh://" ]]; then + + mkdir -p "$HOME/.ssh" + chmod 700 "$HOME/.ssh" + add-ssh-key + ssh-keyscan -t rsa,ed25519 "$git_hostname" >> "$HOME/.ssh/known_hosts" 2>/dev/null + + if [[ ! -d "$odoo_enterprise_path/.git" ]]; then + + find "$odoo_enterprise_path" -mindepth 1 -maxdepth 1 ! -name '.last_ref' -exec rm -rf {} + + + log-entrypoint "Init ${odoo_enterprise_url} in $odoo_enterprise_path." + git -C "$odoo_enterprise_path" init -q + git -C "$odoo_enterprise_path" remote add origin "$odoo_enterprise_url" + fi + + log-entrypoint "Fetch $ODOO_ENTERPRISE_REF commit in $odoo_enterprise_path." + git -C "$odoo_enterprise_path" fetch --depth 1 origin "$ODOO_ENTERPRISE_REF" + + log-entrypoint "Checkout $ODOO_ENTERPRISE_REF commit in $odoo_enterprise_path." + git -C "$odoo_enterprise_path" checkout -q -f "$ODOO_ENTERPRISE_REF" + + remove-ssh-key + + else + log-entrypoint "Error: unsupported protocol '${git_proto}' in ODOO_ENTERPRISE_URL." + exit 1 + fi + echo "$ODOO_ENTERPRISE_REF" > "$ref_file" else log-entrypoint "Odoo Enterprise $ODOO_ENTERPRISE_REF already downloaded. Skipping download."