From b62fb34e1c5e28821f68bf83780e96cc0c5c5715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20-=20Le=20Filament?= <theo@le-filament.com> Date: Thu, 26 Sep 2024 16:10:25 +0200 Subject: [PATCH] feat(build): script to retrieve addons and save commit hashes (backported from 16.0) --- 17.0.Dockerfile | 211 +++++++++++++++++++++++++--------------------- get_addons | 218 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 332 insertions(+), 97 deletions(-) create mode 100644 get_addons diff --git a/17.0.Dockerfile b/17.0.Dockerfile index 8bfc478..203df8a 100644 --- a/17.0.Dockerfile +++ b/17.0.Dockerfile @@ -1,16 +1,25 @@ FROM python:3.12-slim-bookworm AS builder RUN set -x; \ - apt-get update &&\ - apt-get install -y --no-install-recommends build-essential curl git libldap2-dev libpq-dev libsasl2-dev &&\ - pip install wheel &&\ - pip wheel --wheel-dir=/svc/wheels -r https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt &&\ - # astor required by base_view_inheritance_extension - # openupgradelib required for OCA module migration from one version to another - # phonenumbers required by phone_validation - # 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 - 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 + apt-get update \ + && apt-get install --yes --no-install-recommends \ + build-essential \ + 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 + # openupgradelib required for OCA module migration from one version to another + # phonenumbers required by phone_validation + # python-stdnum>=1.18 required by l10n_fr_siret and l10n_fr_siret_lookup + # zxcvbn required by password_security + 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 @@ -19,107 +28,115 @@ ENV LANG=C.UTF-8 \ PGDATABASE=odoo RUN set -x; \ - apt-get update &&\ - apt-get install -y --no-install-recommends \ - curl \ - git \ - gnupg \ - openssh-client \ - postgresql-client \ - wkhtmltopdf \ - xmlsec1 &&\ - apt-get -y autoremove &&\ - rm -rf /var/lib/apt/lists/* + apt-get update \ + && apt-get install --yes --no-install-recommends \ + curl \ + git \ + gnupg \ + openssh-client \ + postgresql-client \ + wkhtmltopdf \ + xmlsec1 \ + && apt-get -y autoremove \ + && rm -rf /var/lib/apt/lists/* 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 &&\ - pip3 install -U --no-index --find-links=/svc/wheels astor openupgradelib phonenumbers python-stdnum>=1.18 PyYAML zxcvbn +RUN pip3 install --no-index --find-links=/svc/wheels --requirement https://raw.githubusercontent.com/oca/OCB/17.0/requirements.txt \ + && 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 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 +ARG SAVE_COMMITS_FILENAME='ocb' RUN set -x; \ - useradd --create-home --home-dir /opt/odoo --no-log-init odoo &&\ - /bin/bash -c "mkdir -p /opt/odoo/{etc,odoo,additional_addons,private_addons,data,private}" &&\ - curl -L https://github.com/OCA/OCB/tarball/17.0 | tar -xzC /opt/odoo/odoo --strip-components 1 &&\ - find /opt/odoo/odoo/addons/*/i18n/ /opt/odoo/odoo/odoo/addons/base/i18n/ -type f -not -name 'fr.po' -delete &&\ - chown -R odoo:odoo /opt/odoo + repo='https://github.com/OCA/OCB' \ + branch='17.0' \ + && useradd --create-home --home-dir /opt/odoo --no-log-init odoo \ + && /bin/bash -c "mkdir -p /opt/odoo/{etc,odoo,additional_addons,private_addons,data,private}" \ + && 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 +ARG SAVE_COMMITS_FILENAME='default_addons' RUN set -x; \ - mkdir -p /tmp/oca-repos/ &&\ - 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 &&\ - mv /tmp/oca-repos/account-financial-tools/account_lock_date_update \ - /tmp/oca-repos/account-financial-tools/account_move_name_sequence \ - /tmp/oca-repos/account-financial-tools/account_usability \ - /opt/odoo/additional_addons/ &&\ -## https://github.com/OCA/account-invoicing/pull/1713 -# curl -L https://github.com/OCA/account-invoicing/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="account-invoicing" --strip-components 1 &&\ -# mv /tmp/oca-repos/account-invoicing/sale_timesheet_invoice_description \ -# /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/account-reconcile/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="account-reconcile" --strip-components 1 &&\ - mv /tmp/oca-repos/account-reconcile/account_statement_base \ - /tmp/oca-repos/account-reconcile/account_reconcile_model_oca \ - /tmp/oca-repos/account-reconcile/account_reconcile_oca \ - /opt/odoo/additional_addons/ &&\ - 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 &&\ - mv /tmp/oca-repos/bank-statement-import/account_statement_import_base \ - /tmp/oca-repos/bank-statement-import/account_statement_import_file \ - /tmp/oca-repos/bank-statement-import/account_statement_import_file_reconcile_oca \ -# /tmp/oca-repos/bank-statement-import/account_statement_import_ofx \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/crm/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="crm" --strip-components 1 &&\ - mv /tmp/oca-repos/crm/crm_stage_probability /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/l10n-france/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="l10n-france" --strip-components 1 &&\ - mv /tmp/oca-repos/l10n-france/l10n_fr_siret \ -# /tmp/oca-repos/l10n-france/l10n_fr_siret_lookup \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/partner-contact/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="partner-contact" --strip-components 1 &&\ -# mv /tmp/oca-repos/partner-contact/partner_disable_gravatar \ - mv /tmp/oca-repos/partner-contact/partner_firstname \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/project/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="project" --strip-components 1 &&\ - mv /tmp/oca-repos/project/project_task_default_stage \ -# /tmp/oca-repos/project/project_template \ - /opt/odoo/additional_addons/ &&\ -# curl -L https://github.com/OCA/server-auth/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-auth" --strip-components 1 &&\ -# mv /tmp/oca-repos/server-auth/password_security \ -# /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/server-brand/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-brand" --strip-components 1 &&\ - mv /tmp/oca-repos/server-brand/disable_odoo_online \ -# /tmp/oca-repos/server-brand/portal_odoo_debranding \ - /tmp/oca-repos/server-brand/remove_odoo_enterprise \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/server-tools/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-tools" --strip-components 1 &&\ - mv /tmp/oca-repos/server-tools/base_view_inheritance_extension \ - /tmp/oca-repos/server-tools/module_change_auto_install \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/server-ux/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="server-ux" --strip-components 1 &&\ - mv /tmp/oca-repos/server-ux/server_action_mass_edit \ - /opt/odoo/additional_addons/ &&\ - curl -L https://github.com/OCA/social/tarball/17.0 | tar -xzC /tmp/oca-repos/ --one-top-level="social" --strip-components 1 &&\ - mv /tmp/oca-repos/social/mail_debrand \ - /tmp/oca-repos/social/mail_tracking \ - /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 + get_addons 'https://github.com/OCA/account-financial-tools' '17.0' 'additional_addons' \ + account_lock_date_update \ + account_move_name_sequence \ + account_usability \ + # https://github.com/OCA/account-invoicing/pull/1713 + # && get_addons 'https://github.com/OCA/account-invoicing' '17.0' 'additional_addons' \ + # sale_timesheet_invoice_description \ + && get_addons 'https://github.com/OCA/account-reconcile' '17.0' 'additional_addons' \ + account_statement_base \ + account_reconcile_model_oca \ + account_reconcile_oca \ + && get_addons 'https://github.com/OCA/bank-statement-import' '17.0' 'additional_addons' \ + account_statement_import_base \ + account_statement_import_file \ + account_statement_import_file_reconcile_oca \ + # account_statement_import_ofx \ + && get_addons 'https://github.com/OCA/crm' '17.0' 'additional_addons' \ + crm_stage_probability \ + && get_addons 'https://github.com/OCA/l10n-france' '17.0' 'additional_addons' \ + l10n_fr_siret \ + # l10n_fr_siret_lookup \ + && get_addons 'https://github.com/OCA/partner-contact' '17.0' 'additional_addons' \ + # partner_disable_gravatar \ + partner_firstname \ + && get_addons 'https://github.com/OCA/project' '17.0' 'additional_addons' \ + project_task_default_stage \ + # project_template \ + # && get_addons 'https://github.com/OCA/server-auth' '17.0' 'additional_addons' \ + # password_security \ + && get_addons 'https://github.com/OCA/server-brand' '17.0' 'additional_addons' \ + disable_odoo_online \ + # portal_odoo_debranding \ + remove_odoo_enterprise \ + && get_addons 'https://github.com/OCA/server-tools' '17.0' 'additional_addons' \ + base_view_inheritance_extension \ + module_change_auto_install \ + && get_addons 'https://github.com/OCA/server-ux' '17.0' 'additional_addons' \ + server_action_mass_edit \ + && get_addons 'https://github.com/OCA/social' '17.0' 'additional_addons' \ + mail_debrand \ + mail_tracking \ + && get_addons 'https://github.com/OCA/web' '17.0' 'additional_addons' \ + web_environment_ribbon \ + web_refresher \ + web_responsive \ + web_no_bubble \ + web_theme_classic \ + && find /opt/odoo/additional_addons/*/i18n/ -type f -not -name 'fr.po' -delete \ + # Install Le Filament default addons. + # && get_addons 'https://sources.le-filament.com/lefilament/remove_login_links.git' '17.0' 'private_addons/remove_login_links' \ + # && get_addons 'https://sources.le-filament.com/lefilament/lefilament_release_agent.git' '17.0' 'private_addons/lefilament_release_agent' \ + && echo "info: default addon commits:" \ + && cat $SAVE_COMMITS_DIR/$SAVE_COMMITS_FILENAME # Copy entrypoint script and Odoo configuration file COPY ./entrypoint.sh / 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 VOLUME ["/opt/odoo/data/"] diff --git a/get_addons b/get_addons new file mode 100644 index 0000000..5363c3d --- /dev/null +++ b/get_addons @@ -0,0 +1,218 @@ +#!/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}" -- GitLab