refactored enterprise + third party addons clonning process

This commit is contained in:
yhaelopez
2023-12-24 12:22:16 -07:00
parent 6fd07e113a
commit 77edc03b91
5 changed files with 71 additions and 98 deletions

View File

@@ -65,16 +65,6 @@ RUN apt-get update && apt-get install -y \
# Remove apt lists
&& rm -rf /var/lib/apt/lists/*
#-----------------------#
# Odoo Enterprise #
#-----------------------#
# Create Enterprise addons directory
RUN mkdir -p ${ENTERPRISE_ADDONS} && chown odoo:odoo -R ${ENTERPRISE_ADDONS}
# Clone Enterprise addons if user and token are present
COPY --chown=odoo:odoo ./odoo/clone-enterprise.sh /
RUN /clone-enterprise.sh
#---------------------#
# PIP Dependecies #
#---------------------#
@@ -84,15 +74,15 @@ COPY --chown=odoo:odoo ./odoo/requirements.txt /tmp/requirements.txt
RUN python3 -m pip install -r /tmp/requirements.txt && \
rm /tmp/requirements.txt
#--------------------------#
# Third Party Addons #
#--------------------------#
#--------------------------------------------#
# Odoo Enterprise + Third Party Addons #
#--------------------------------------------#
# Create third-party-addons directory and clone them
RUN mkdir -p ${THIRD_PARTY_ADDONS}
COPY --chown=odoo:odoo ./odoo/fix-manifest.py /
COPY --chown=odoo:odoo ./odoo/clone-addons.sh /
COPY --chown=odoo:odoo ./odoo/third-party-addons.txt /
RUN /clone-addons.sh && chown odoo:odoo -R ${THIRD_PARTY_ADDONS}
# RUN /clone-addons.sh && chown odoo:odoo -R ${THIRD_PARTY_ADDONS}
RUN /clone-addons.sh
#-----------------------#
# Odoo Conf #

View File

@@ -2,50 +2,78 @@
set -e
# Function to construct the clone command
construct_clone_command() {
local repo_type=$1
local repo_url=$2
case $repo_type in
private) echo "git clone https://${GITHUB_USER}:${GITHUB_ACCESS_TOKEN}@${repo_url#https://}" ;;
enterprise) echo "git clone https://${ENTERPRISE_USER}:${ENTERPRISE_ACCESS_TOKEN}@${repo_url#https://} ${ENTERPRISE_ADDONS}" ;;
public) echo "git clone $repo_url" ;;
esac
}
# Function to clone and copy modules based on conditions
clone_and_copy_modules() {
local repo_type=$1
local repo_url=$2
local clone_cmd=$(construct_clone_command $repo_type $repo_url)
local repo_name=$(basename -s .git "$repo_url")
shift 2
local modules_conditions=("$@")
# Extract repo name from the URL
repo_name=$(basename -s .git "$repo_url")
# Determine the clone command based on repo type
local clone_cmd
if [[ $repo_type == "private" ]]; then
clone_cmd="git clone https://${GITHUB_USER}:${GITHUB_ACCESS_TOKEN}@${repo_url#https://}"
# Clone and copy logic for enterprise repository
if [[ $repo_type == "enterprise" ]]; then
if [[ ! -d "${ENTERPRISE_ADDONS}" ]] && [ -n "$GITHUB_USER" ] && [ -n "$GITHUB_ACCESS_TOKEN" ]; then
$clone_cmd --depth 1 --branch ${ODOO_TAG} --single-branch --no-tags
fi
else
clone_cmd="git clone $repo_url"
# Determine if any module has a true condition
local should_clone=false
if [[ ${#modules_conditions[@]} -eq 1 ]]; then
[[ ${modules_conditions[0]} == true ]] && should_clone=true
else
for (( i=1; i<${#modules_conditions[@]}; i+=2 )); do
if [[ ${modules_conditions[i]} == true ]]; then
should_clone=true
break
fi
done
fi
# Iterate over modules and conditions
# Clone the repo if should_clone is true and it's not already cloned
if [[ $should_clone == true && ! -d "$repo_name" ]]; then
$clone_cmd --depth 1 --branch ${ODOO_TAG} --single-branch --no-tags
fi
# Copy the modules if the condition is true
if [[ $should_clone == true ]]; then
for (( i=0; i<${#modules_conditions[@]}; i+=2 )); do
local module=${modules_conditions[i]}
local condition=${modules_conditions[i+1]}
# Check if the condition is true and clone and copy if needed
if [[ $condition == true ]]; then
# Clone the repository if not already cloned
if [ ! -d "$repo_name" ]; then
echo "Cloning $clone_cmd --depth 1 --branch ${ODOO_TAG} --single-branch --no-tags"
$clone_cmd --depth 1 --branch ${ODOO_TAG} --single-branch --no-tags
fi
# Copy the module
echo "Copying ${module} from ${repo_name} into ${THIRD_PARTY_ADDONS}"
cp -r /${repo_name}/${module} ${THIRD_PARTY_ADDONS}/${module}
fi
done
fi
fi
}
# Function to manually expand environment variables in a string
expand_env_vars() {
while IFS=' ' read -r -a words; do
for word in "${words[@]}"; do
if [[ $word == \$* ]]; then
varname=${word:2:-1} # Extract the variable name
if [[ $word == \$\{* ]]; then
# Remove the leading '${' and the trailing '}' from the word
varname=${word:2:-1}
# Check if the variable is set and not empty
if [ -n "${!varname+x}" ]; then
echo -n "${!varname} " # Substitute with its value
else
echo -n "false " # Default to false if not set
fi
else
echo -n "$word "
fi
@@ -56,15 +84,6 @@ expand_env_vars() {
# Read the configuration file and process each line
while IFS= read -r line; do
# Skip empty lines and lines starting with '#'
if [[ -z "$line" || "$line" == \#* ]]; then
continue
fi
# Manually replace environment variables in the line with their values
processed_line=$(expand_env_vars "$line")
# Split the processed line into an array
IFS=' ' read -r -a repo_info <<< "$processed_line"
# Call the function with the repository type, URL, and modules with conditions
clone_and_copy_modules "${repo_info[@]}"
[[ -z "$line" || "$line" == \#* ]] && continue
clone_and_copy_modules $(expand_env_vars "$line")
done < "third-party-addons.txt"

View File

@@ -1,7 +0,0 @@
#!/bin/bash
set -e
if [ -n "$ENTERPRISE_USER" ] && [ -n "$ENTERPRISE_ACCESS_TOKEN" ]; then \
git clone https://${ENTERPRISE_USER}:${ENTERPRISE_ACCESS_TOKEN}@github.com/odoo/enterprise.git ${ENTERPRISE_ADDONS} --depth 1 --branch ${ODOO_TAG} --single-branch --no-tags
fi

View File

@@ -1,34 +0,0 @@
import sys
# Define the path to the manifest file
manifest_file_path = sys.argv[1]
# Read the file content
with open(manifest_file_path, 'r') as file:
lines = file.readlines()
# Find the start and end index of the manifest dictionary
start_index = next(i for i, line in enumerate(lines) if line.strip().startswith('{'))
end_index = next(i for i, line in enumerate(lines) if line.strip().endswith('}'))
# Construct and evaluate the manifest dictionary
manifest_dict = eval(''.join(lines[start_index:end_index + 1]))
# Modify the manifest dictionary
manifest_dict['installable'] = True
manifest_dict['auto_install'] = True
# Construct the modified manifest string
modified_manifest_lines = ['{\n']
for key, value in manifest_dict.items():
modified_manifest_lines.append(f" '{key}': {repr(value)},\n")
modified_manifest_lines.append('}\n')
# Replace the manifest dictionary string in the content
lines[start_index:end_index + 1] = modified_manifest_lines
# Write the modified content back to the file
with open(manifest_file_path, 'w') as file:
file.writelines(lines)
print(f"Modified {manifest_file_path}")

View File

@@ -1,12 +1,17 @@
# This file is read by clone-addons.sh
# Enterprise addons
enterprise https://github.com/odoo/enterprise true
# Odoocker repositories
public https://github.com/odoocker/odoocker-modules.git odoocker_base true
public https://github.com/odoocker/odoo-cloud-platform.git session_redis ${USE_REDIS} base_attachment_object_storage ${USE_S3} attachment_s3 ${USE_S3}
public https://github.com/odoocker/server-tools.git sentry ${USE_SENTRY}
# Add repositories with the following format:
# <public|private> <repo_url> <module1> <copy_module1_condition> <module2> <copy_module2_condition> ...
# <public|private> <repo_url> <true|false>
# or
# <public|private> <repo_url> <module1> <true|false> <module2> <true|false> ...
# Public repositories