Commit 54614157 by Administrator

Merge branch 'dev_cooperatic' into 'lacagette_prod'

Correctif parametres bouton 'Oubli validation service' dans FAQ

See merge request !257
parents 07102692 fed8bf23
Pipeline #3350 failed with stage
in 1 minute 5 seconds
...@@ -159,3 +159,5 @@ LOSSES_LOC_ID = 33 ...@@ -159,3 +159,5 @@ LOSSES_LOC_ID = 33
LOSSES_PICKING_TYPE_ID = 10 LOSSES_PICKING_TYPE_ID = 10
AUTOCONSO_LOC_ID = 27 AUTOCONSO_LOC_ID = 27
AUTOCONSO_PICKING_TYPE_ID = 7 AUTOCONSO_PICKING_TYPE_ID = 7
SUBSCRIPTION_ASK_FOR_SEX = True
\ No newline at end of file
...@@ -5,7 +5,7 @@ ci_data_dir="/home/django/third-party/scripts/data" ...@@ -5,7 +5,7 @@ ci_data_dir="/home/django/third-party/scripts/data"
coop=$1 coop=$1
instance=$2 #(prod not supported for now) instance=$2
#move to the third argument #move to the third argument
shift shift
shift shift
...@@ -35,17 +35,26 @@ fi ...@@ -35,17 +35,26 @@ fi
now=$( date +%Y%m%d_%H%M%S ) now=$( date +%Y%m%d_%H%M%S )
source "${ci_dir}/update_code.sh" source "${ci_dir}/prepare_mail.sh"
source "${ci_dir}/update_instance.sh"
if [[ "${instance}" == "preprod" ]]; then
repo="third-party"
echo "Prepare mail" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
prepare_mail "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"|| exit 1
repo="Odoo"
echo "Prepare mail" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
prepare_mail "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
fi
repo="third-party" repo="third-party"
echo "START PROCESS" "${coop}" "${instance}" "${repo}" "${now}" echo "Update instance" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
update_code "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" || exit 1 update_instance "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
echo "DONE"
repo="Odoo" repo="Odoo"
echo "START PROCESS" "${coop}" "${instance}" "${repo}" "${now}" echo "Update instance" "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}"
update_code "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" || exit 1 update_instance "${coop}" "${instance}" "${repo}" "${now}" "${send_mails}" "${ci_dir}" "${ci_data_dir}" || exit 1
echo "DONE"
if [[ "${instance}" == "preprod" ]] && ${send_mails}; then if [[ "${instance}" == "preprod" ]] && ${send_mails}; then
python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${coop}" python3 "${ci_dir}/send_mail.py" "${ci_data_dir}/ci_diff_third-party_${now}.txt" "${ci_data_dir}/ci_diff_Odoo_${now}.txt" "${coop}"
......
...@@ -35,8 +35,14 @@ grant lacagette to odoo; ...@@ -35,8 +35,14 @@ grant lacagette to odoo;
alter database lacagette owner to odoo; alter database lacagette owner to odoo;
select pg_terminate_backend(pid) from pg_stat_activity where pid <> pg_backend_pid() and datname = 'lacagette'; select pg_terminate_backend(pid) from pg_stat_activity where pid <> pg_backend_pid() and datname = 'lacagette';
alter database lacagette rename to odoo; alter database lacagette rename to odoo;
GRANT CONNECT ON DATABASE odoo TO metabase;
GRANT USAGE ON SCHEMA public TO metabase;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metabase;
exit exit
nano /etc/postgresql/10/main/pg_hba.conf puis remplacer lacagette par odoo sur la ligne qui concerne metabase
exit exit
service postgresql restart
//CONFIGS //CONFIGS
sed -i -e 's/\/lacagette\//\/odoo\//g' /home/odoo/odoo-server.conf sed -i -e 's/\/lacagette\//\/odoo\//g' /home/odoo/odoo-server.conf
...@@ -61,3 +67,5 @@ delete from ir_attachment where mimetype in ('text/css','application/javascript' ...@@ -61,3 +67,5 @@ delete from ir_attachment where mimetype in ('text/css','application/javascript'
//puis deux restarts nécessaires... de odoo //puis deux restarts nécessaires... de odoo
restart django. restart django.
//METABASE : change database name in settings
\ No newline at end of file
prepare_mail() {
#Read arguments and set variables
coop=$1
instance=$2
repo=$3
now=$4
send_mails=$5
ci_dir=$6
ci_data_dir=$7
if [[ ${repo} == "third-party" ]]; then
user="django"
elif [[ ${repo} == "Odoo" ]]; then
user="odoo"
else
echo "Incorrect repo name : ${repo}"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : incorrect repo name"
fi
exit 1
fi
cd /home/${user}/${repo}
su ${user} -c "git fetch --all"
#Check branch
branch_found_str=$( su ${user} -c "git ls-remote origin ${coop}_prod" ) #seems that git ls-remote is not "failing" so we need to check output
if [ -z "${branch_found_str}" ]; then
#branch prod does not exist, cannot go on
echo "${coop} ${instance} ${repo}: branch ${coop}_prod does not exist"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : branch ${coop}_prod does not exist"
fi
exit 1
fi
###COMPARE BRANCHES AND DECIDE IF WE NEED TO CREATE A FILE CONTAINING NEW COMMITS###
#initialize file
if ! test -f "${ci_data_dir}/ci_diff_${repo}_last.txt"; then
touch "${ci_data_dir}/ci_diff_${repo}_last.txt"
fi
#new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --no-merges --oneline )" (old version)
#Let's break down the new big line below :
#origin/${coop}_prod...origin/dev_cooperatic : we look for difference between develop branch and prod branch
#--pretty=format:'%s' : get rid of commit id
#the big grep+sed group : discard lines not maching pattern "merge [0-9]\+-... into dev_cooperatic" and only keep the [0-9]\+-.... part with a link to redmine
new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --merges --oneline --pretty=format:'%s' | grep "into 'dev_cooperatic'" | sed "s/Merge branch '//g" | sed "s/' into 'dev_cooperatic'//g" | grep "^[0-9]\+" | sed -E 's/(^[0-9]+)/\<a href=\"https\:\/\/redmine.coopdev.fr\/issues\/\1\"\>\1\<\/a\>/g' )"
if [ -z "${new_commits}" ]; then
echo "${coop} ${instance} ${repo} : no difference between prod and dev_cooperatic"
#There are no difference between prod and dev_cooperatic therefore we don't want to send email for this repo.
#To inform the mailer that there is nothing new, we do not create ci_diff file at current time.
#The mailer will therefore use ci_diff_last to get the list of commits for the client.
#Not only there is nothing new, but also there is just no difference,
#therefore we need to erase the content the ci_diff_last file if not already empty (save time of first time it was erased)
if [[ -s "${ci_data_dir}/ci_diff_${repo}_last.txt" ]]; then
> "${ci_data_dir}/ci_diff_${repo}_last.txt"
fi
else
echo "${new_commits}" > "${ci_data_dir}/ci_diff_${repo}_${now}.txt"
#See if commit difference is the same than last time
if cmp "${ci_data_dir}/ci_diff_${repo}_last.txt" "${ci_data_dir}/ci_diff_${repo}_${now}.txt"; then
#As there are no new commits in prod, we don't want to send email for this repo.
#To indicate that, we delete just created ci_diff file at current time.
rm "${ci_data_dir}/ci_diff_${repo}_${now}.txt"
echo "${coop} ${instance} ${repo} : ci_diff_${repo} files are identical"
else
#We have created new ci_diff.
#Replace old ci_diff_last by new one
rm "${ci_data_dir}/ci_diff_${repo}_last.txt"
cp "${ci_data_dir}/ci_diff_${repo}_${now}.txt" "${ci_data_dir}/ci_diff_${repo}_last.txt"
fi
fi
}
\ No newline at end of file
...@@ -6,7 +6,7 @@ def is_coop_supported(coop): ...@@ -6,7 +6,7 @@ def is_coop_supported(coop):
def is_instance_supported(instance): def is_instance_supported(instance):
return instance == "preprod" or instance == "test" or instance == "dev" return instance == "preprod" or instance == "test" or instance == "dev" or instance == "prod"
def get_mail(coop): def get_mail(coop):
......
#This script prepares files to send an email and update code update_instance() {
update_code() { #Read arguments and set variables
coop=$1 coop=$1
instance=$2 instance=$2
repo=$3 repo=$3
now=$4 now=$4
send_mails=$5 send_mails=$5
ci_dir=$6
ci_dir="/home/django/third-party/scripts/src" ci_data_dir=$7
ci_data_dir="/home/django/third-party/scripts/data"
###EARLY CHECKS###
if [[ ${repo} == "third-party" ]]; then if [[ ${repo} == "third-party" ]]; then
user="django" user="django"
service="django" service="django"
...@@ -25,10 +20,15 @@ update_code() { ...@@ -25,10 +20,15 @@ update_code() {
fi fi
exit 1 exit 1
fi fi
if [[ "${instance}" == "prod" ]]; then
target="${coop}_prod"
else
target="dev_cooperatic"
fi
#Move to repository directory, fetch all and make sure coop_prod branch exists
cd /home/${user}/${repo} cd /home/${user}/${repo}
su ${user} -c "git fetch --all" su ${user} -c "git fetch --all"
branch_found_str=$( su ${user} -c "git ls-remote origin ${coop}_prod" ) #seems that git ls-remote is not "failing" so we need to check output branch_found_str=$( su ${user} -c "git ls-remote origin ${coop}_prod" ) #seems that git ls-remote is not "failing" so we need to check output
if [ -z "${branch_found_str}" ]; then if [ -z "${branch_found_str}" ]; then
#branch prod does not exist, cannot go on #branch prod does not exist, cannot go on
...@@ -39,45 +39,7 @@ update_code() { ...@@ -39,45 +39,7 @@ update_code() {
exit 1 exit 1
fi fi
#Make sure config file exists if repo is third-party
###COMPARE BRANCHES AND DECIDE IF WE NEED TO CREATE A FILE CONTAINING NEW COMMITS###
#new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --no-merges --oneline )" (old version)
#Let's break down the new big line below :
#origin/${coop}_prod...origin/dev_cooperatic : we look for difference between develop branch and prod branch
#--pretty=format:'%s' : get rid of commit id
#the big grep+sed group : discard lines not maching pattern "merge [0-9]\+-... into dev_cooperatic" and only keep the [0-9]\+-.... part with a link to redmine
new_commits="$( git log origin/${coop}_prod...origin/dev_cooperatic --merges --oneline --pretty=format:'%s' | grep "into 'dev_cooperatic'" | sed "s/Merge branch '//g" | sed "s/' into 'dev_cooperatic'//g" | grep "^[0-9]\+" | sed -E 's/(^[0-9]+)/\<a href=\"https\:\/\/redmine.coopdev.fr\/issues\/\1\"\>\1\<\/a\>/g' )"
if [ -z "${new_commits}" ]; then
echo "${coop} ${instance} ${repo} : no new commits"
#As there are no new commits in prod, we don't want to send email for this repo.
#To indicate that, we do not create any ci_diff file at current time.
else
if ! test -f "${ci_data_dir}/ci_diff_${repo}_last.txt"; then
touch "${ci_data_dir}/ci_diff_${repo}_last.txt"
fi
echo "${new_commits}" > "${ci_data_dir}/ci_diff_${repo}_${now}.txt"
#See if commit difference is the same than last time
if cmp "${ci_data_dir}/ci_diff_${repo}_last.txt" "${ci_data_dir}/ci_diff_${repo}_${now}.txt"; then
#As there are no new commits in prod, we don't want to send email for this repo.
#To indicate that, we delete just created ci_diff file at current time.
rm "${ci_data_dir}/ci_diff_${repo}_${now}.txt"
echo "${coop} ${instance} ${repo} : ci_diff_${repo} files are identical"
else
#We have created new ci_diff.
#Replace old ci_diff_last by new one
rm "${ci_data_dir}/ci_diff_${repo}_last.txt"
cp "${ci_data_dir}/ci_diff_${repo}_${now}.txt" "${ci_data_dir}/ci_diff_${repo}_last.txt"
fi
fi
###UPDATE CODE (DO IT ANYWAY AS IT IS ONLY USED ON PREPROD FOR NOW)###
#If repo is third-party, make sure config file exists as we need it later
if [[ ${repo} == "third-party" ]]; then if [[ ${repo} == "third-party" ]]; then
if ! test -f "coops_configurations/config_${coop}.py"; then if ! test -f "coops_configurations/config_${coop}.py"; then
echo "${coop} ${instance} ${repo}: coops_configurations/config_${coop}.py does not exists" echo "${coop} ${instance} ${repo}: coops_configurations/config_${coop}.py does not exists"
...@@ -88,101 +50,127 @@ update_code() { ...@@ -88,101 +50,127 @@ update_code() {
fi fi
fi fi
/etc/init.d/${service} stop #TODO : on prod, make sure some changes are required before stopping / restarting service #Save filepaths of files that are going to be updated if repo is odoo
#Stash mess, then checkout proper branch and pull
#Stash + checkout + pull seems a good way to get rid of mess without deleting it
su ${user} -c "git stash"
#maybe some user changed branch so we need to get back on dev_cooperatic
if ! su ${user} -c "git checkout dev_cooperatic"; then
#handling cases when git checkout branch fails
#We can not continue but we have stopped service already, let's restart it before exiting
/etc/init.d/${service} start
echo "${coop} ${instance} ${repo}: could not git checkout dev_cooperatic"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not checkout dev_cooperatic"
fi
exit 1
fi
if [[ ${repo} == "Odoo" ]]; then if [[ ${repo} == "Odoo" ]]; then
echo "git diff --name-only dev_cooperatic..origin/dev_cooperatic" echo "git diff --name-only origin/${target}.."
updated_filepaths="$( git diff --name-only dev_cooperatic..origin/dev_cooperatic )" updated_filepaths="$( git diff --name-only origin/${target}.. )"
echo "${updated_filepaths}" echo "${updated_filepaths}"
fi fi
if ! su ${user} -c "git pull"; then #Update code if needed
#handling cases when git pull branch fails new_commits="$( git log origin/${target}... )"
#We can not continue but we have stopped service already, let's restart it before exiting if [ -z "${new_commits}" ]; then
/etc/init.d/${service} start echo "${coop} ${instance} ${repo} : already up to date"
echo "${coop} ${instance} ${repo}: could not git pull" else
if ${send_mails}; then #Stop instance
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not git pull" /etc/init.d/${service} stop
#One could argue that git stash is risky on prod,
#but it's way easier to go that way to get rid of template file changes generated on django service restart
if ! su ${user} -c "git stash"; then
#We can not finish the update : restart the system
/etc/init.d/${service} start
echo "${coop} ${instance} ${repo}: could not git stash"
if ${send_mails}; then
python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not git stash"
fi
exit 1
fi fi
exit 1 #Make script robust to any branch change : switch to target !
fi if ! su ${user} -c "git checkout ${target}"; then
#We can not finish the update : restart the system
if [[ ${repo} == "third-party" ]]; then #TODO : detect if we have stashed something on previous step to revert it (git stash pop)
#Replace config file by proper one only if required /etc/init.d/${service} start
if ! cmp "outils/config.py" "coops_configurations/config_${coop}.py"; then echo "${coop} ${instance} ${repo}: could not git checkout ${target}"
#Config files are different, go for it if ${send_mails}; then
mv "outils/config.py" "${ci_data_dir}/ci_old_cfg_file_${now}.py" python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not git checkout ${target}"
cp "coops_configurations/config_${coop}.py" "outils/config.py" fi
else exit 1
echo "config files are identical"
fi fi
/etc/init.d/django start #Pull
else if ! su ${user} -c "git pull"; then
#oop on updated_filenames, for each filename, look for the directory of __openerp__.py file #We can not finish the update : restart the system
#if found, just store the parent directory #TODO : detect if we have stashed something on previous step to revert it (git stash pop)
SAVEIFS=$IFS #TODO : undo previous git checkout if necessary
IFS=$'\n' echo "${coop} ${instance} ${repo}: could not git pull"
if [[ ${updated_filepaths} == "" ]]; then if ${send_mails}; then
updated_filepaths_array=() python3 "${ci_dir}/send_error_mail.py" "${coop} ${instance} ${repo} : could not git pull"
else fi
read -rd '' -a updated_filepaths_array <<<"${updated_filepaths}" exit 1
fi fi
IFS='/' #Additionnal update actions
l=${#updated_filepaths_array[@]}
declare -A modules #modules to update #push tags to remember this prod update point (only on prod)
modules_str="" if [[ "${instance}" == "prod" ]]; then
#TODO : handle errors
su ${user} -c "git tag -a ${coop}_${now} -m autotag"
su ${user} -c "git push origin ${coop}_${now}"
fi
for (( i=0; i<l; i++ )); if [[ ${repo} == "third-party" ]]; then
do #Replace config file by proper one only if required
read -rd '' -a one_path_array <<<"${updated_filepaths_array[$i]}" if ! cmp "outils/config.py" "coops_configurations/config_${coop}.py"; then
j=0 #Config files are different, go for it
accu_path="${one_path_array[0]}" mv "outils/config.py" "${ci_data_dir}/ci_old_cfg_file_${now}.py"
pathlen=${#one_path_array[@]} cp "coops_configurations/config_${coop}.py" "outils/config.py"
while [[ $j -lt ${pathlen} ]] && ! test -f "${accu_path}/__openerp__.py"; do else
((j++)) echo "config files are identical"
accu_path="${accu_path}/${one_path_array[j]}" fi
done fi
#Update key of modules if (we have found openerp.py (j<path) + module has not been added already),
#so that we do not add twice same module in modules_str if [[ ${repo} == "Odoo" ]]; then
#and add module in modules_str #Loop on updated_filenames, for each filename, look for the directory of __openerp__.py file
if [[ $j -lt ${pathlen} ]] && [[ ! -v modules["${one_path_array[$j]}"] ]]; then #Ff found, just store the parent directory
modules["${one_path_array[$j]}"]= SAVEIFS=$IFS
if [[ ${modules_str} == "" ]]; then IFS=$'\n'
modules_str="${one_path_array[$j]}" if [[ ${updated_filepaths} == "" ]]; then
else updated_filepaths_array=()
modules_str="${modules_str},${one_path_array[$j]}" else
fi read -rd '' -a updated_filepaths_array <<<"${updated_filepaths}"
fi fi
done
IFS=$SAVEIFS IFS='/'
l=${#updated_filepaths_array[@]}
declare -A modules #Modules to update
modules_str=""
for (( i=0; i<l; i++ ));
do
read -rd '' -a one_path_array <<<"${updated_filepaths_array[$i]}"
j=0
accu_path="${one_path_array[0]}"
pathlen=${#one_path_array[@]}
while [[ $j -lt ${pathlen} ]] && ! test -f "${accu_path}/__openerp__.py"; do
((j++))
accu_path="${accu_path}/${one_path_array[j]}"
done
#Update key of modules if (we have found openerp.py (j<path) + module has not been added already),
#so that we do not add twice same module in modules_str
#and add module in modules_str
if [[ $j -lt ${pathlen} ]] && [[ ! -v modules["${one_path_array[$j]}"] ]]; then
modules["${one_path_array[$j]}"]=
if [[ ${modules_str} == "" ]]; then
modules_str="${one_path_array[$j]}"
else
modules_str="${modules_str},${one_path_array[$j]}"
fi
fi
done
echo "${modules_str}" IFS=$SAVEIFS
restart_odoo_cmd="/home/odoo/Odoo/odoo/odoo.py -c /home/odoo/odoo-server.conf" echo "${modules_str}"
if [[ -n "${modules_str}" ]]; then
echo "restart odoo service with module update" restart_odoo_cmd="/home/odoo/Odoo/odoo/odoo.py -c /home/odoo/odoo-server.conf"
su odoo -c "${restart_odoo_cmd} -u${modules_str} --stop-after-init" #TODO : make sure this is working fine if [[ -n "${modules_str}" ]]; then
echo "restart odoo service with module update"
su odoo -c "${restart_odoo_cmd} -u${modules_str} --stop-after-init"
fi
fi fi
fi
echo "Starting ${service} service" #Restart service
/etc/init.d/${service} start echo "Starting ${service} service"
/etc/init.d/${service} start
fi
} }
\ No newline at end of file
<div id="faqBDM" class=" mt-3"> <div id="faqBDM" class=" mt-3">
<div class="page_title txtcenter"> <div class="page_title txtcenter">
...@@ -157,8 +158,8 @@ ...@@ -157,8 +158,8 @@
href="javascript:void(0);" href="javascript:void(0);"
target="_blank" target="_blank"
type="button" type="button"
class="btn--primary faq_link_button ask_bdm_form_link" class="btn--primary faq_link_button"
id="request_form_link_btn3" id="late_service_form_link_btn"
> >
Oubli validation service Oubli validation service
</a> </a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment