Skip to content
Extraits de code Groupes Projets
Valider b62fb34e rédigé par Théo - Le Filament's avatar Théo - Le Filament
Parcourir les fichiers

feat(build): script to retrieve addons and save commit hashes (backported from 16.0)

parent d84f3da9
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
FROM python:3.12-slim-bookworm AS builder FROM python:3.12-slim-bookworm AS builder
RUN set -x; \ RUN set -x; \
apt-get update &&\ apt-get update \
apt-get install -y --no-install-recommends build-essential curl git libldap2-dev libpq-dev libsasl2-dev &&\ && apt-get install --yes --no-install-recommends \
pip install wheel &&\ build-essential \
pip wheel --wheel-dir=/svc/wheels -r https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt &&\ curl \
git \
libldap2-dev \
libpq-dev \
libsasl2-dev \
&& pip install wheel \
&& pip wheel --wheel-dir=/svc/wheels --requirement https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt \
# astor required by base_view_inheritance_extension # astor required by base_view_inheritance_extension
# openupgradelib required for OCA module migration from one version to another # openupgradelib required for OCA module migration from one version to another
# phonenumbers required by phone_validation # phonenumbers required by phone_validation
# python-stdnum>=1.18 required by l10n_fr_siret and l10n_fr_siret_lookup # python-stdnum>=1.18 required by l10n_fr_siret and l10n_fr_siret_lookup
# PyYAML required by custom scripts for adding modules (https://sources.le-filament.com/lefilament/ansible-roles/docker_odoo/-/tree/master/templates)
# zxcvbn required by password_security # zxcvbn required by password_security
pip wheel --wheel-dir=/svc/wheels astor git+https://github.com/OCA/openupgradelib.git@master phonenumbers==8.13.40 python-stdnum==1.20 PyYAML==6.0.1 zxcvbn==4.4.28 pip wheel --wheel-dir=/svc/wheels \
'astor' \
'git+https://github.com/OCA/openupgradelib.git@master' \
'phonenumbers==8.13.40' \
'zxcvbn==4.4.28'
FROM python:3.12-slim-bookworm AS final FROM python:3.12-slim-bookworm AS final
...@@ -19,107 +28,115 @@ ENV LANG=C.UTF-8 \ ...@@ -19,107 +28,115 @@ ENV LANG=C.UTF-8 \
PGDATABASE=odoo PGDATABASE=odoo
RUN set -x; \ RUN set -x; \
apt-get update &&\ apt-get update \
apt-get install -y --no-install-recommends \ && apt-get install --yes --no-install-recommends \
curl \ curl \
git \ git \
gnupg \ gnupg \
openssh-client \ openssh-client \
postgresql-client \ postgresql-client \
wkhtmltopdf \ wkhtmltopdf \
xmlsec1 &&\ xmlsec1 \
apt-get -y autoremove &&\ && apt-get -y autoremove \
rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --from=builder /svc /svc COPY --from=builder /svc /svc
RUN pip3 install --no-index --find-links=/svc/wheels -r https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt &&\ RUN pip3 install --no-index --find-links=/svc/wheels --requirement https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt \
pip3 install -U --no-index --find-links=/svc/wheels astor openupgradelib phonenumbers python-stdnum>=1.18 PyYAML zxcvbn && pip3 install --no-index --upgrade --find-links=/svc/wheels \
'astor' \
'openupgradelib' \
'phonenumbers' \
'zxcvbn'
ARG SAVE_COMMITS_DIR='/opt/odoo_commits/'
ENV SAVE_COMMITS_DIR=$SAVE_COMMITS_DIR
# Add Git Known Hosts # Add Git Known Hosts
COPY ./ssh_known_git_hosts /root/.ssh/known_hosts COPY ./ssh_known_git_hosts /root/.ssh/known_hosts
# Install Odoo and remove not French translations and .git directory to limit amount of data used by container # Install Odoo and remove not French translations and .git directory to limit amount of data used by container
ARG SAVE_COMMITS_FILENAME='ocb'
RUN set -x; \ RUN set -x; \
useradd --create-home --home-dir /opt/odoo --no-log-init odoo &&\ repo='https://github.com/OCA/OCB' \
/bin/bash -c "mkdir -p /opt/odoo/{etc,odoo,additional_addons,private_addons,data,private}" &&\ branch='17.0' \
curl -L https://github.com/OCA/OCB/tarball/17.0 | tar -xzC /opt/odoo/odoo --strip-components 1 &&\ && useradd --create-home --home-dir /opt/odoo --no-log-init odoo \
find /opt/odoo/odoo/addons/*/i18n/ /opt/odoo/odoo/odoo/addons/base/i18n/ -type f -not -name 'fr.po' -delete &&\ && /bin/bash -c "mkdir -p /opt/odoo/{etc,odoo,additional_addons,private_addons,data,private}" \
chown -R odoo:odoo /opt/odoo && mkdir /opt/odoo_commits \
&& git clone --single-branch --branch "${branch}" --depth 1 "${repo}" /tmp/repo \
&& commit="$(git -C /tmp/repo rev-parse HEAD)" \
&& mv /tmp/repo/* /opt/odoo/odoo/ \
&& echo "repo;ref;commit" > $SAVE_COMMITS_DIR/$SAVE_COMMITS_FILENAME \
&& echo "${repo};${branch};${commit}" >> $SAVE_COMMITS_DIR/$SAVE_COMMITS_FILENAME \
&& rm -r /tmp/repo \
# Only keep French translations.
&& find /opt/odoo/odoo/addons/*/i18n/ /opt/odoo/odoo/odoo/addons/base/i18n/ -type f -not -name 'fr.po' -delete \
&& echo "info: OCB commit:" \
&& cat $SAVE_COMMITS_DIR/$SAVE_COMMITS_FILENAME
# Add script to download Odoo addons.
COPY --chown=root:root --chmod=755 ./get_addons /usr/local/bin
# Install Odoo OCA default dependencies - Commented modules do not exist yet # Install Odoo OCA default dependencies - Commented modules do not exist yet
ARG SAVE_COMMITS_FILENAME='default_addons'
RUN set -x; \ RUN set -x; \
mkdir -p /tmp/oca-repos/ &&\ get_addons 'https://github.com/OCA/account-financial-tools' '17.0' 'additional_addons' \
curl -L https://github.com/OCA/account-financial-tools/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="account-financial-tools" --strip-components 1 &&\ account_lock_date_update \
mv /tmp/oca-repos/account-financial-tools/account_lock_date_update \ account_move_name_sequence \
/tmp/oca-repos/account-financial-tools/account_move_name_sequence \ account_usability \
/tmp/oca-repos/account-financial-tools/account_usability \ # https://github.com/OCA/account-invoicing/pull/1713
/opt/odoo/additional_addons/ &&\ # && get_addons 'https://github.com/OCA/account-invoicing' '17.0' 'additional_addons' \
## https://github.com/OCA/account-invoicing/pull/1713 # sale_timesheet_invoice_description \
# curl -L https://github.com/OCA/account-invoicing/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="account-invoicing" --strip-components 1 &&\ && get_addons 'https://github.com/OCA/account-reconcile' '17.0' 'additional_addons' \
# mv /tmp/oca-repos/account-invoicing/sale_timesheet_invoice_description \ account_statement_base \
# /opt/odoo/additional_addons/ &&\ account_reconcile_model_oca \
curl -L https://github.com/OCA/account-reconcile/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="account-reconcile" --strip-components 1 &&\ account_reconcile_oca \
mv /tmp/oca-repos/account-reconcile/account_statement_base \ && get_addons 'https://github.com/OCA/bank-statement-import' '17.0' 'additional_addons' \
/tmp/oca-repos/account-reconcile/account_reconcile_model_oca \ account_statement_import_base \
/tmp/oca-repos/account-reconcile/account_reconcile_oca \ account_statement_import_file \
/opt/odoo/additional_addons/ &&\ account_statement_import_file_reconcile_oca \
curl -L https://github.com/OCA/bank-statement-import/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="bank-statement-import" --strip-components 1 &&\ # account_statement_import_ofx \
mv /tmp/oca-repos/bank-statement-import/account_statement_import_base \ && get_addons 'https://github.com/OCA/crm' '17.0' 'additional_addons' \
/tmp/oca-repos/bank-statement-import/account_statement_import_file \ crm_stage_probability \
/tmp/oca-repos/bank-statement-import/account_statement_import_file_reconcile_oca \ && get_addons 'https://github.com/OCA/l10n-france' '17.0' 'additional_addons' \
# /tmp/oca-repos/bank-statement-import/account_statement_import_ofx \ l10n_fr_siret \
/opt/odoo/additional_addons/ &&\ # l10n_fr_siret_lookup \
curl -L https://github.com/OCA/crm/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="crm" --strip-components 1 &&\ && get_addons 'https://github.com/OCA/partner-contact' '17.0' 'additional_addons' \
mv /tmp/oca-repos/crm/crm_stage_probability /opt/odoo/additional_addons/ &&\ # partner_disable_gravatar \
curl -L https://github.com/OCA/l10n-france/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="l10n-france" --strip-components 1 &&\ partner_firstname \
mv /tmp/oca-repos/l10n-france/l10n_fr_siret \ && get_addons 'https://github.com/OCA/project' '17.0' 'additional_addons' \
# /tmp/oca-repos/l10n-france/l10n_fr_siret_lookup \ project_task_default_stage \
/opt/odoo/additional_addons/ &&\ # project_template \
curl -L https://github.com/OCA/partner-contact/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="partner-contact" --strip-components 1 &&\ # && get_addons 'https://github.com/OCA/server-auth' '17.0' 'additional_addons' \
# mv /tmp/oca-repos/partner-contact/partner_disable_gravatar \ # password_security \
mv /tmp/oca-repos/partner-contact/partner_firstname \ && get_addons 'https://github.com/OCA/server-brand' '17.0' 'additional_addons' \
/opt/odoo/additional_addons/ &&\ disable_odoo_online \
curl -L https://github.com/OCA/project/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="project" --strip-components 1 &&\ # portal_odoo_debranding \
mv /tmp/oca-repos/project/project_task_default_stage \ remove_odoo_enterprise \
# /tmp/oca-repos/project/project_template \ && get_addons 'https://github.com/OCA/server-tools' '17.0' 'additional_addons' \
/opt/odoo/additional_addons/ &&\ base_view_inheritance_extension \
# curl -L https://github.com/OCA/server-auth/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-auth" --strip-components 1 &&\ module_change_auto_install \
# mv /tmp/oca-repos/server-auth/password_security \ && get_addons 'https://github.com/OCA/server-ux' '17.0' 'additional_addons' \
# /opt/odoo/additional_addons/ &&\ server_action_mass_edit \
curl -L https://github.com/OCA/server-brand/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-brand" --strip-components 1 &&\ && get_addons 'https://github.com/OCA/social' '17.0' 'additional_addons' \
mv /tmp/oca-repos/server-brand/disable_odoo_online \ mail_debrand \
# /tmp/oca-repos/server-brand/portal_odoo_debranding \ mail_tracking \
/tmp/oca-repos/server-brand/remove_odoo_enterprise \ && get_addons 'https://github.com/OCA/web' '17.0' 'additional_addons' \
/opt/odoo/additional_addons/ &&\ web_environment_ribbon \
curl -L https://github.com/OCA/server-tools/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-tools" --strip-components 1 &&\ web_refresher \
mv /tmp/oca-repos/server-tools/base_view_inheritance_extension \ web_responsive \
/tmp/oca-repos/server-tools/module_change_auto_install \ web_no_bubble \
/opt/odoo/additional_addons/ &&\ web_theme_classic \
curl -L https://github.com/OCA/server-ux/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-ux" --strip-components 1 &&\ && find /opt/odoo/additional_addons/*/i18n/ -type f -not -name 'fr.po' -delete \
mv /tmp/oca-repos/server-ux/server_action_mass_edit \ # Install Le Filament default addons.
/opt/odoo/additional_addons/ &&\ # && get_addons 'https://sources.le-filament.com/lefilament/remove_login_links.git' '17.0' 'private_addons/remove_login_links' \
curl -L https://github.com/OCA/social/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="social" --strip-components 1 &&\ # && get_addons 'https://sources.le-filament.com/lefilament/lefilament_release_agent.git' '17.0' 'private_addons/lefilament_release_agent' \
mv /tmp/oca-repos/social/mail_debrand \ && echo "info: default addon commits:" \
/tmp/oca-repos/social/mail_tracking \ && cat $SAVE_COMMITS_DIR/$SAVE_COMMITS_FILENAME
/opt/odoo/additional_addons/ &&\
curl -L https://github.com/OCA/web/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="web" --strip-components 1 &&\
mv /tmp/oca-repos/web/web_environment_ribbon \
/tmp/oca-repos/web/web_refresher \
/tmp/oca-repos/web/web_responsive \
/tmp/oca-repos/web/web_no_bubble \
/tmp/oca-repos/web/web_theme_classic \
/opt/odoo/additional_addons/ &&\
rm -rf /tmp/oca-repos/ &&\
find /opt/odoo/additional_addons/*/i18n/ -type f -not -name 'fr.po' -delete
# # Install Le Filament default dependency
# git clone -b 17.0 --depth 1 https://sources.le-filament.com/lefilament/remove_login_links.git /opt/odoo/private_addons/remove_login_links &&\
# git clone -b 17.0 --depth 1 https://sources.le-filament.com/lefilament/lefilament_release_agent.git /opt/odoo/private_addons/lefilament_release_agent &&\
# chown -R odoo:odoo /opt/odoo
# Copy entrypoint script and Odoo configuration file # Copy entrypoint script and Odoo configuration file
COPY ./entrypoint.sh / COPY ./entrypoint.sh /
COPY ./odoo.conf /opt/odoo/etc/odoo.conf COPY ./odoo.conf /opt/odoo/etc/odoo.conf
RUN chown odoo:odoo /opt/odoo/etc/odoo.conf RUN chown --recursive odoo:odoo /opt/odoo
# Mount /opt/odoo/data to allow restoring filestore # Mount /opt/odoo/data to allow restoring filestore
VOLUME ["/opt/odoo/data/"] VOLUME ["/opt/odoo/data/"]
......
#!/bin/sh
ODOO_ROOT_DIR=${ODOO_ROOT_DIR:-'/opt/odoo'}
SAVE_COMMITS_DIR=${SAVE_COMMITS_DIR:-'/opt/odoo_commits'}
SAVE_COMMITS_FILENAME=${SAVE_COMMITS_FILENAME:-'custom_addons'}
TMP_REPO_PATH=${TEMP_REPO_PATH:-'/tmp/repo'}
CSV_FILE="${SAVE_COMMITS_DIR}/${SAVE_COMMITS_FILENAME}"
CSV_HEADERS='repo;ref;commit;module;dst'
# logging section: begin
STYLE_FGBLACK='\033[30m'
STYLE_FGRED='\033[31m'
STYLE_FGGREEN='\033[32m'
STYLE_FGYELLOW='\033[33m'
STYLE_FGBLUE='\033[34m'
STYLE_FGMAGENTA='\033[35m'
STYLE_FGCYAN='\033[36m'
STYLE_FGLIGHTGRAY='\033[37m'
STYLE_BGBLACK='\033[40m'
STYLE_BGRED='\033[41m'
STYLE_BGGREEN='\033[42m'
STYLE_BGYELLOW='\033[43m'
STYLE_BGBLUE='\033[44m'
STYLE_BGMAGENTA='\033[45m'
STYLE_BGCYAN='\033[46m'
STYLE_BGLIGHTGRAY='\033[47m'
STYLE_DEFAULT='\033[39m'
STYLE_BOLD='\033[1m'
STYLE_NORMAL='\033[0m'
print_info() {
msg="$1"
echo "${STYLE_FGBLUE}info: ${msg}${STYLE_DEFAULT}"
}
print_success() {
msg="$1"
print_info "${msg} ${STYLE_FGGREEN}success${STYLE_DEFAULT}"
}
print_failed() {
msg="$1"
print_info "${msg} ${STYLE_FGRED}failed${STYLE_DEFAULT}"
}
print_err() {
msg="$1"
exit_code="${2:-0}"
echo "${STYLE_BOLD}${STYLE_FGRED}err: ${msg}${STYLE_DEFAULT}${STYLE_NORMAL}"
[ "$exit_code" != "0" ] && exit_script "$exit_code"
}
exit_script() {
exit_code="${1:-0}"
exit "$exit_code"
}
# logging section: end
save_commit() {
repo="$1"
ref="$2"
commit="$3"
module="$4"
dst="$5"
if [ -f "$CSV_FILE" ]; then
if [ "$(head --lines=1 $CSV_FILE)" != "$CSV_HEADERS" ]; then
sed -i "1s/^/${CSV_HEADERS}\n/" "$CSV_FILE"
if [ "$?" -ne 0 ]; then
return 1
fi
fi
else
echo "$CSV_HEADERS" > "$CSV_FILE"
fi
echo "${repo};${ref};${commit};${module};${dst}" >> "$CSV_FILE"
if [ "$?" -ne 0 ]; then
return 1
fi
return 0
}
repo="$1"
shift
ref="$1"
shift
dst="$1"
shift
modules="$@"
# Cloning repo.
log_action="repo '$repo': cloning [no tree + branch]..."
print_info "$log_action"
git clone --branch "${ref}" --filter=tree:0 "${repo}" "${TMP_REPO_PATH}"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
log_action="repo '$repo': cloning [no tree]..."
print_info "$log_action"
git clone --filter=tree:0 "${repo}" "${TMP_REPO_PATH}"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
log_action="repo '$repo': cloning [branch]..."
print_info "$log_action"
git clone --single-branch --branch "${ref}" --depth 1 "${repo}" "${TMP_REPO_PATH}"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
log_action="repo '$repo': cloning [classic]..."
print_info "$log_action"
git clone "${repo}" "${TMP_REPO_PATH}"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to clone repo '$repo'" 1
fi
fi
fi
fi
## Get module code and save informations about it in a CSV file.
# Checkout to ref.
log_action="repo '${repo}': checkout to '${ref}'..."
print_info "$log_action"
git -C "${TMP_REPO_PATH}" checkout "${ref}"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to checkout to '${ref}' in repo '${repo}'" 2
fi
# Get commit number.
log_action="repo '${repo}': getting commit number..."
print_info "$log_action"
commit="$(git -C ${TMP_REPO_PATH} rev-parse HEAD)"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to get commit number in repo '${repo}'" 3
fi
# Get selected modules from repo.
if [ -n "$modules" ]; then
print_info "repo '${repo}': repo with multiple modules detected, modules selected: [$(echo $modules | sed 's/ /, /g')]"
# Install each module.
for module in $modules; do
module_dst="${ODOO_ROOT_DIR}/${dst}/${module}"
if [ -d "$module_dst" ]; then
print_info "module '${module}': destination '${module_dst}' already exist removing..."
rm -r "$module_dst"
fi
log_action="module '${module}': moving module code to directory '${module_dst}'..."
print_info "$log_action"
mv "${TMP_REPO_PATH}/${module}" "${ODOO_ROOT_DIR}/${dst}/"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to move module '${module}' from repo '${repo}' to directory '${module_dst}'" 5
fi
log_action="module '${module}': saving module informations..."
print_info "$log_action"
save_commit "$repo" "$ref" "$commit" "$module" "$dst"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to save informations of module '${module}' in file '${CSV_FILE}'" 6
fi
done
# Get repo as a module.
else
module_dst="${ODOO_ROOT_DIR}/${dst}"
module="$(basename $dst)"
print_info "repo '${repo}': repo as a single module detected: '${module}'"
if [ -d "$module_dst" ]; then
print_info "module '${module}': destination '${module_dst}' already exist removing..."
rm -r "$module_dst"
fi
log_action="module '${module}': creating destination directory '${module_dst}'..."
print_info "$log_action"
mkdir -p "$module_dst"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to create destination directory '${module_dst}' for '${module}' from repo '${repo}'" 4
fi
log_action="module '${module}': moving module code to directory '${module_dst}'..."
print_info "$log_action"
mv ${TMP_REPO_PATH}/* "$module_dst"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to move code of module '${module}' from repo '${repo}' to directory '${module_dst}'" 5
fi
log_action="module '${module}': saving module informations..."
print_info "$log_action"
save_commit "$repo" "$ref" "$commit" "$module" "$dst"
if [ "$?" -eq 0 ]; then
print_success "$log_action"
else
print_failed "$log_action"
print_err "unable to save informations of module '${module}' in file '${CSV_FILE}'" 6
fi
fi
rm -r "${TMP_REPO_PATH}"
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter