-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathtask
More file actions
executable file
·2951 lines (2461 loc) · 95 KB
/
task
File metadata and controls
executable file
·2951 lines (2461 loc) · 95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
cd "$(dirname "$0")" || exit
# Commands such as git pull return exit code if there are no changes
# set -e
if [[ -a ".env" ]]; then
source .env
fi
help-table() {
local -a rows
local max_cmd=7 max_opt=6 max_desc=11
rows+=("Command|Option|Description")
rows+=("===ENV===| | ")
rows+=("backup-env-files|[path]|Archive and copy ,env files to target location.")
rows+=("copy-dotenv|[env][env]|Copy .env file.")
rows+=("create-dotenv|[env][type]|Create .env file of type nextcloud, odoo, upgrade.")
rows+=("edit-dotenv|[env]|Open .env file in default editor.")
rows+=("list-dotenv||List .env files.")
rows+=("load-dotenv|[env]|Load and export .env file.")
rows+=("remove-dotenv|[env]|Remove environment config.")
rows+=("rename-dotenv|[env][env]|Rename .env file.")
rows+=("restore-dotenv-files|[path]|Extract and copy .env files from backup file.")
rows+=("show-dotenv|[env]|Output content of the .env file.")
rows+=("===GIT===| | ")
rows+=("aggregate-git-folders|[path]|Run gitaggregate for the repos.yaml.")
rows+=("add-git-folder|[branch][url][path]|Add git folder to .gitmodules and .gitmodule.csv.")
rows+=("checkout|[version]|Checkout Odoo version.")
rows+=("checkout-git-folder|[branch][path]|Checkout git commit from .gitmodules.csv.")
rows+=("commit-git-folder|[message][path]|Commit all changes in path.")
rows+=("clean-git-folder|[path]|Clean git folder.")
rows+=("clone-git-folder|[branch][path][version]|Clone git folder listed in the .gitmodules file.")
rows+=("download-git-folder|[grep]|Download git folder listed in the .gitmodules file.")
rows+=("status-git-folder|[path]|Show status for git folder in path.")
rows+=("list-git-folder|[path]|List path and url of git folders.")
rows+=("pull-git-folder|[branch][path]|Pull all git folders listed in the .gitmodules file.")
rows+=("push-git-folder||Push all git folders in path.")
rows+=("remove-git-folder|[path]|Remove git folders in path.")
rows+=("ls-git-folder|[grep]|List git folders path space separated.")
rows+=("reset-git-folder|[path]|Abort rebase and reset git folder.")
rows+=("stage-git-folder|[path]|Stage all files in git folders in path.")
rows+=("switch-git-folder|[branch][path]|Switch branch for all git folders from the .gitmodules file.")
rows+=("sync-git-folder|[branch][path]|Switch, stash and pull all git folders.")
rows+=("run-pre-commit|[path]|Run pre-commit in path.")
rows+=("===DOCKER===| | ")
rows+=("archive-docker-tags||Archive Docker image tags on hub older than 1 year.")
rows+=("build-odoo|[output]|Build Odoo Docker image.")
rows+=("build-odoo-mailgate|[output]|Build Odoo Mailgate Docker image.")
rows+=("build-odoo-upgrade|[output]|Build Odoo Upgrade Docker image.")
rows+=("build-odoo-cli|[output]|Build Odoo CLI Docker image.")
rows+=("login-docker|[user][token]|Setup Docker Hub login credentials.")
rows+=("login-podman|[user][token]|Login into registry with podman.")
rows+=("container-ps||List container processes.")
rows+=("remove|[name]|Remove containers and volumes.")
rows+=("test-image|[folder]|Test Docker image from target folder.")
rows+=("test-odoo-version-regex||Test the Odoo module version regex filter.")
rows+=("===VUEPRESS===| | ")
rows+=("build-vuepress||Create Vuepress build.")
rows+=("install-vuepress||Install Node build dependencies.")
rows+=("dev-vuepress||Start Vuepress development server.")
rows+=("serve-vuepress||Serve Vuepress build.")
rows+=("===DATABASE===| | ")
rows+=("change-uuid|[env]|Change database uuid via xmlrpc.")
rows+=("clear-assets|[db]|Clear all assets of Odoo database.")
rows+=("clear-filestore|[db]|Clear local filestore folder.")
rows+=("clear-views|[db]|Clear all views of Odoo database.")
rows+=("cloc-odoo|[db]|Count custom line of codes.")
rows+=("drop-db|[db]|Drop target Odoo database.")
rows+=("init-db|[db]|Initialize the Odoo database.")
rows+=("load-language|[db][lang]|Install language package in Odoo db.")
rows+=("patch-database|[db][path]|Apply sql file to database.")
rows+=("reset-views|[db][key]|Execute hard reset on views matching keys.")
rows+=("set-admin|[db]|Sets the password for the first user in database.")
rows+=("update-module|[db][name,path]|Update target Odoo module.")
rows+=("update-module-list|[db]|Update module list of Odoo database.")
rows+=("===REVISION===| | ")
rows+=("checkout-latest-revision|[version]|Checkout the latest revision of the Odoo version.")
rows+=("checkout-revision|[revision]|Load Odoo revision env var and checkout git folders.")
rows+=("commit-and-push-revision|[revision]|Commit all changes and tag with current revision.")
rows+=("create-revision|[revision]|Create new Odoo revision.")
rows+=("list-revision||List available Odoo revisions.")
rows+=("load-latest-revision|[version]|Load the latest revision of the Odoo version.")
rows+=("load-revision|[revision]|Load env var from specified revision.")
rows+=("show-revision|[revision]|Show references of Odoo revision.")
rows+=("===LLM===| | ")
rows+=("commit-with-llm||Commit with llm generated commit message.")
rows+=("update-with-llm|[glob][prompt]|Feed module files with prompt to LLM and apply file changes.")
rows+=("===SNIPPETS===| | ")
rows+=("create-snippet|[xml-id]|Create snippet from template.")
rows+=("install-snippet|[env][path]|Install snippet definition.")
rows+=("disable-snippet|[env][path]|Disable snippet by path or xml-id.")
rows+=("enable-snippet|[env][path]|Enable snippet by path or xml-id.")
rows+=("lint-snippets||Run checks for all snippets.")
rows+=("remove-snippet|[env][path]|Remove snippet by path or xml-id.")
rows+=("update-snippet|[env][path]|Update snippet definition.")
rows+=("===INSTALL===| | ")
rows+=("activate-venv||Activate virtualenv.")
rows+=("init-venv||Initialize python virtual env.")
rows+=("disable-mailserver|[env]|Disable mail server settings via xmlrpc.")
rows+=("install||Install Odoo requirements in source folder.")
rows+=("install-ansible-build-scripts|[role]|Install scripts of the specified Ansbile role.")
rows+=("install-requirements|[db][path]|Install python packages from requirements.txt.")
rows+=("list-packages||List installed python packages.")
rows+=("init-module|[db][path,module]|Initialize Odoo module.")
rows+=("set-addons-path||Set Odoo addons path env variable.")
rows+=("===DATA===| | ")
rows+=("export-website-data|[env]|Export website data from Odoo database.")
rows+=("import-csv|[db][path]|Import data from csv. Filename is PostgreSQL table name.")
rows+=("import-website-data|[env]|Import website data to Odoo database.")
rows+=("===DEVELOP===| | ")
rows+=("create-module|[path]|Create new Odoo module from template.")
rows+=("create-repo|[path]|Odoo module repo from template.")
rows+=("generate-module-docs|[path]|Generate readme file for module with OCA tools.")
rows+=("generate-module-model|[path][model]|Generate model in module folder.")
rows+=("generate-module-inherit|[path][model]|Generate inherited model in module folder.")
rows+=("generate-module-views|[path][model]|Generate model views in module folder.")
rows+=("generate-module-security|[path][model]|Generate model access file.")
rows+=("generate-module-migration|[path]|Generate migration script for currentmodule version.")
rows+=("generate-module-snippet|[path][ref][model]|Generate snippet for referefenced view.")
rows+=("generate-module-report|[path][model]|Generate report for a model in module folder.")
rows+=("generate-module-translation|[path]|Generate module translation and update with llm.")
rows+=("generate-module-wizard|[path][model]|Generate wizard for a model in module folder.")
rows+=("generate-repo-docs|[path]|Generate repo files from template.")
rows+=("===MODULE===| | ")
rows+=("list-modules|[path]|Get modules in path as bash array.")
rows+=("pytest-module|[path]|Run module tests with pytest.")
rows+=("release-module|[path]|Create GitHub release for a module.")
rows+=("remove-module|[db][name]|Remove target Odoo module.")
rows+=("test-module|[path]|Test target Odoo module.")
rows+=("test-modules|[path]|Test target Odoo modules in repo folder.")
rows+=("translate-module|[path][lang][db]|Generate translation for Odoo module.")
rows+=("upload-module|[env][path]|Zip and upload Odoo module.")
rows+=("visualize-dependencies|[path]|Generate visualizations of module dependencies.")
rows+=("zip-module|[path]|Create zip file for module.")
rows+=("===HELPER===| | ")
rows+=("generate-admin-password|[pass]|Generate hash for Odoo master password.")
rows+=("generate-ssh-keys||Generate ssh key pair.")
rows+=("generate-pg-ssl-keys||Generate PostgreSQL SSL key material.")
rows+=("get-addons-path||Output addons path.")
rows+=("get-modules|[path][option]|Get list of modules in path. 'basename' or 'dirname'.")
rows+=("get-module-version|[path]|Get module version from manifest.")
rows+=("get-module-checksum|[path]|Get module checksum.")
rows+=("help|[grep]|Show help for commands.")
rows+=("info||Show values of project env vars.")
rows+=("load-ssh-key||Load SSH private key from env var.")
rows+=("update-module-license|[grep]|Update LICENSE file for each matching module.")
rows+=("===RUN===| | ")
rows+=("debug|[name]|Debugg application.")
rows+=("exec|[name][cmd]|Run command in container.")
rows+=("logs|[name]|Tail container logs. Default is '\''odoo'\''.")
rows+=("manifestoo|[param]|Execute manifestoo cli.")
rows+=("odoobin|[param]|Execute odoo binary.")
rows+=("odoocli|[param]|Execute odoocli cli.")
rows+=("psql|[db]|Start interactive psql shell.")
rows+=("restart|[name]|Restart container.")
rows+=("run|[name][cmd]|Run container with command.")
rows+=("shell|[db][code]|Start interactive odoo shell or run code.")
rows+=("source||Source the Python virtual env.")
rows+=("start|[name][db]|Start service. Use list to show services.")
rows+=("stop|[name]|Stop containers.")
rows+=("test-xmlrpc|[env]|Test xml rpc connection.")
rows+=("===PROJECT===| | ")
rows+=("lint||Run precommit for this project.")
rows+=("list-versions||List available Odoo versions.")
rows+=("check-version||Check if Odoo source is the correct version.")
rows+=("load-version|[version]|Load git refs from version folder.")
rows+=("save-version||Save git folder refs to version folder.")
rows+=("template-compose||Template the Docker compose file.")
rows+=("template-odoo-rc||Template the Odoo config file.")
rows+=("test-project|[cleanup]|Run tests for this project.")
rows+=("version||Show version of required tools.")
rows+=("===PERFORMANCE===| | ")
rows+=("record-with-memray|[name]|Record application memory usage with memray.")
rows+=("record-with-py-spy|[pid]|Record and create flamechart for a process.")
rows+=("===DOC===| | ")
rows+=("update-docs||Update all project docs.")
rows+=("update-modules-doc||Update modules docs file.")
rows+=("update-revisions-doc||Update revisions doc file.")
rows+=("update-snippets-doc||Update snippets doc file.")
rows+=("===UPGRADE===| | ")
rows+=("prepare-migration-brach|[path][module][version]|Create migration branch for a module.")
rows+=("migrate-module|[path]|Migrate module code from to target Odoo version.")
rows+=("upgrade-odoo|[env][step]|Run the Odoo upgrade for a target environment.")
for row in "${rows[@]}"; do
IFS='|' read -r cmd opt desc <<< "$row"
(( ${#cmd} > max_cmd )) && max_cmd=${#cmd}
(( ${#opt} > max_opt )) && max_opt=${#opt}
(( ${#desc} > max_desc )) && max_desc=${#desc}
done
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "Command" \
"$max_opt" "Option" \
"$max_desc" "Description"
printf '|-%*s-|-%*s-|-%*s-|\n' \
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
local first_row=true
for row in "${rows[@]:1}"; do
IFS='|' read -r cmd opt desc <<< "$row"
if [[ "$cmd" =~ ^===.*===$ ]]; then
group_name="${cmd/===/}"
group_name="${group_name/===/}"
if [ "$first_row" = true ]; then
first_row=false
else
printf '|-%*s-|-%*s-|-%*s-|\n' \
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
fi
local left_pad=$(( (max_cmd - ${#group_name}) / 2 ))
local right_pad=$(( max_cmd - left_pad - ${#group_name} ))
printf '| %*s%s%*s | %*s | %*s |\n' \
"$left_pad" "" \
"$group_name" \
"$right_pad" "" \
"$max_opt" "" \
"$max_desc" ""
printf '|-%*s-|-%*s-|-%*s-|\n' \
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
else
first_row=false
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "$cmd" \
"$max_opt" "$opt" \
"$max_desc" "$desc"
fi
done
}
help() {
echo
if [[ -n "$1" ]]; then
help-table | grep -i "$1" | column -t -s'|'
else
echo 'task <command> [options]'
echo
echo 'commands:'
echo
help-table
fi
echo
}
# Static env vars
ODOO_RC="odoo.conf"
TASK_DOTENV_DIR="$PWD/vault"
export PYTHONPATH="$PWD/odoo" # Required so upgrade-util does not overwrite the odoo namespace
ODOO_VERSION=$(echo "$ODOO_REVISION" | cut -d'.' -f1-2)
CONTAINER_CONFIG="$HOME/.docker/$CONTAINER_REGISTRY"
# Updateable env vars
USER_ORG=${USER_ORG:=Mint-System}
DB_NAME=${DB_NAME:="$ODOO_VERSION"}
WITHOUT_DEMO=${WITHOUT_DEMO:=False}
ODOO_LANGUAGE=${ODOO_LANGUAGE:=de_CH}
ODOO_PORT=${ODOO_PORT:=8069}
NGINX_PORT=${NGINX_PORT:=8080}
WORKERS=${WORKERS:=0}
POSTGRES_IMAGE=${POSTGRES_IMAGE:=postgres:16-alpine}
POSTGRES_PORT=${POSTGRES_PORT:=5432}
POSTGRES_SSL=${POSTGRES_SSL:=on}
PGSSLMODE=${PGSSLMODE:=prefer}
LOG_LEVEL=${LOG_LEVEL:=info}
CONTAINER_REGISTRY=${CONTAINER_REGISTRY:=mintsystem}
PLATFORM=${PLATFORM:=linux/amd64}
CONTAINER_ENGINE=${CONTAINER_ENGINE:=docker}
COMPOSE_COMMAND=${COMPOSE_COMMAND:=docker compose}
LLM_MODEL=${LLM_MODEL:=llama}
SMTP_SERVER=${SMTP_SERVER:=localhost}
SMTP_PORT=${SMTP_PORT:=1025}
SMTP_SSL=${SMTP_SSL:=False}
EMAIL_FROM=${EMAIL_FROM:=info@yourcompany.com}
MAIL_ALIAS_DOMAIN=${MAIL_ALIAS_DOMAIN:=yourcompany.com}
LIST_DB=${LIST_DB:=False}
CONTAINER_TAG="odoo:$ODOO_REVISION"
ODOO_INIT_LOGIN=${ODOO_INIT_LOGIN:=admin}
ODOO_INIT_PASSWORD=${ODOO_INIT_PASSWORD:=admin}
SNIPPET_PREFIX=${SNIPPET_PREFIX:=mint_system}
# Conditional env vars
if [[ "$CONTAINER_ENGINE" == "podman" ]]; then
COMPOSE_COMMAND="podman-compose"
fi
if [[ "$(uname)" == "Darwin" ]]; then
OS_RELEASE="Darwin"
PYTHON_NOTIFY=""
else
OS_RELEASE=$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"')
PYTHON_NOTIFY="inotify"
fi
if [[ "$WITHOUT_DEMO" = "True" ]]; then
ODOO_PARAM="--without-demo=all"
elif [[ "$ODOO_VERSION" = "19.0" ]]; then
ODOO_PARAM="--with-demo"
fi
# Import commands
clone-taskfile(){
if [[ ! -d "$HOME/taskfile.build" ]]; then
echo -e '\033[38;5;214mGit\033[0m: Clone taskfile repo'
git clone https://git.taskfile.build "$HOME/taskfile.build"
else
echo -e '\033[38;5;214mGit\033[0m: Pull taskfile repo'
git -C "$HOME/taskfile.build" pull
fi
}
if [[ -d "$HOME/taskfile.build/bin" ]]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
fi
# Help commands
info() {
set-addons-path
echo "OS Release: $OS_RELEASE"
echo "Odoo Revision: $ODOO_REVISION"
echo "Odoo Version: $ODOO_VERSION"
echo "Odoo Port: $ODOO_PORT"
echo "Postgres Port: $POSTGRES_PORT"
echo "Odoo Language: $ODOO_LANGUAGE"
echo "Odoo Param: $ODOO_PARAM"
echo "Container Registry: $CONTAINER_REGISTRY"
echo "Container Config: $CONTAINER_CONFIG"
echo "Addons Path: $ADDONS_PATH"
}
version() {
uv --version
activate-venv
python -V
wkhtmltopdf -V
if [[ "$CONTAINER_ENGINE" == "docker" ]]; then
docker -v
docker compose version
else
podman --version
podman-compose --version
fi
}
generate-admin-password() {
if [[ -z "$1" ]]; then echo '\$1 is empty.'; exit; fi
export ODOO_PASSWORD="$1"
bin/hash-password
}
# Env commands
init-venv() {
echo "Ensure Python version $(cat .python-version) is installed."
uv python install
if [[ ! -d ".venv$ODOO_VERSION" ]]; then
echo "Init .venv$ODOO_VERSION with $(uv --version)."
uv venv ".venv$ODOO_VERSION"
fi
}
activate-venv() {
if [[ -f ".venv$ODOO_VERSION/bin/activate" ]]; then
source ".venv$ODOO_VERSION/bin/activate"
else
echo "Could not find .venv$ODOO_VERSION/bin/active. Use init-venv to initalize."
fi
}
get-addons-path() {
set-addons-path
echo "$ADDONS_PATH"
}
template-odoo-rc() {
echo "Template $ODOO_RC"
# Load and export vars defined in odoo conf template
for var in $(grep -oE '\$([A-Z_][A-Z0-9_]*)|\$\{([A-Z_][A-Z0-9_]*)\}' odoo.conf.template); do
var=${var/\$/}
var=${var//\{\//}
export $var
done
local ir_config_parameter=${IR_CONFIG_PARAMETER:-""}
if [[ -n "$GIT_SSH_PRIVATE_KEY" ]]; then
local git_ssh_private_key=$(echo -e "$GIT_SSH_PRIVATE_KEY" | base64 -w0)
ir_config_parameter+=$'\n'"git.ssh_private_key = \"$git_ssh_private_key\""
fi
if [[ -n "$GIT_SSH_PUBLIC_KEY" ]]; then
ir_config_parameter+=$'\n'"git.ssh_public_key = \"$GIT_SSH_PUBLIC_KEY\""
fi
if [[ -n "$BASE_URL_WEBSITE" ]]; then
ir_config_parameter+=$'\n'"base_url_website = \"$BASE_URL_WEBSITE\""
fi
if [[ -n "$BASE_URL_APP" ]]; then
ir_config_parameter+=$'\n'"base_url_app = \"$BASE_URL_APP\""
fi
if [[ -n "$UPLOADCARE_PUBLIC_KEY" ]]; then
ir_config_parameter+=$'\n'"uploadcare.public_key = \"$UPLOADCARE_PUBLIC_KEY\""
fi
if [[ -n "$UPLOADCARE_SECRET_KEY" ]]; then
ir_config_parameter+=$'\n'"uploadcare.secret_key = \"$UPLOADCARE_SECRET_KEY\""
fi
if [[ -n "$KEYCLOAK_BASE_URL" ]]; then
ir_config_parameter+=$'\n'"keycloak.base_url = \"$KEYCLOAK_BASE_URL\""
fi
if [[ -n "$KEYCLOAK_CLIENT_ID" ]]; then
ir_config_parameter+=$'\n'"keycloak.client_id = \"$KEYCLOAK_CLIENT_ID\""
fi
if [[ -n "$KEYCLOAK_CLIENT_SECRET" ]]; then
ir_config_parameter+=$'\n'"keycloak.client_secret = \"$KEYCLOAK_CLIENT_SECRET\""
fi
if [[ -n "$KEYCLOAK_REALM" ]]; then
ir_config_parameter+=$'\n'"keycloak.realm = \"$KEYCLOAK_REALM\""
fi
export IR_CONFIG_PARAMETER="$ir_config_parameter"
envsubst < "odoo.conf.template" > "$ODOO_RC"
}
set-addons-path() {
# Read addons path from git module
local git_folders_path="$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | sort | tr '\n' ',' | sed 's/,*$//')"
# Remove excluded addons
local excludes="addons/theme_mint_system addons/company addons/web"
for exclude in $excludes; do
git_folders_path=$(echo "$git_folders_path" | sed "s|${exclude},||g; s|^${exclude}$||")
done
# Filter valid directories
local valid_paths=""
while IFS= read -r addon; do
addon=$(echo "$addon" | xargs)
[[ -z "$addon" ]] && continue
if [[ -d "$addon" ]]; then
valid_paths="${valid_paths:+$valid_paths,}$addon"
else
echo "Set Addons Path: Path '$addon' does not exist." >&2
fi
done < <(echo "$git_folders_path" | tr ',' '\n')
git_folders_path="$valid_paths"
# Convert to source paths (add /addons where needed)
local addons_path="$(echo "$git_folders_path" | sed 's|,odoo|,odoo/addons|g')"
# Append paths from config env var
if [[ -n "$ODOO_ADDONS_PATH" ]]; then
addons_path="${ODOO_ADDONS_PATH},${addons_path}"
fi
# Export the addons path
export ADDONS_PATH="$addons_path"
}
load-ssh-key() {
if [[ -n "$GIT_SSH_PRIVATE_KEY" ]]; then
echo 'Setup SSH key from env var.'
local decoded_git_ssh_private_key=$(echo -e "$GIT_SSH_PRIVATE_KEY" | base64 -d)
mkdir -p ~/.ssh
echo "$decoded_git_ssh_private_key" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 || (echo 'Dumping ~/.ssh/id_ed25519 content:' && cat ~/.ssh/id_ed25519)
else
echo 'The SSH key env var is empty.'
exit 1
fi
}
# Docs commands
lint() {
echo "Run pre-commit in $PWD"
pre-commit run
echo "Run snippet linting"
lint-snippets
}
update-snippets-doc() {
./bin/update-snippets-doc
}
update-revisions-doc() {
echo 'Update revisions doc file.'
rm -f "revisions.md"
echo -e "# Odoo Revisions \n\
A Odoo revision is a snapshot of git references of the Odoo source and modules at a specific date.\n\
For each major release there are multiple revisions.\n" > "revisions.md"
declare -A revisions
local path_url="https://github.com/${USER_ORG}/Odoo-Build/tree/main"
for file in $(ls revisions/ | sort -rV); do
local revision="$file"
local version=$(echo "$revision" | cut -d'.' -f1-2)
if [[ -z "${revisions[$version]}" ]]; then
revisions[$version]="## $version"
fi
revisions[$version]+=$'\n\n'
revisions[$version]+="#### $revision"
revisions[$version]+=$'\n\n```bash\n'
revisions[$version]+=$(cat "revisions/$file")
revisions[$version]+=$'\n```'
done
for revision in $(echo "${!revisions[@]}" | tr ' ' '\n' | sort -rV); do
echo -e "${revisions[$revision]}\n" >> "revisions.md"
done
}
update-modules-doc() {
echo 'Update module doc file.'
./bin/update-modules-doc
}
update-docs() {
update-modules-doc
update-revisions-doc
update-snippets-doc
}
update-module-license() {
if [[ -z "$1" ]]; then echo '\$1 is empty.'; exit; fi
local git_folders=$(list-module "$1")
for git_folder in $git_folders; do
echo "Update license file for $git_folder."
cp templates/module/LICENSE "$git_folder/"
done
}
generate-repo-docs(){
if [[ -z "$1" ]]; then echo '\$1 is empty.'; exit; fi
local repo_path="$1"
echo "Copy task file to $repo_path."
cp "templates/task" "$repo_path"
echo "Template README.md to $repo_path."
export REPO_FOLDER=$(basename "$repo_path")
export REPO_MODEL=${REPO_FOLDER%%_*}
export REPO_TITLE=$(echo "$REPO_FOLDER" | sed 's/_/ /g' | sed 's/\b\(.\)/\u\1/g')
export REPO_NAME=$(echo "$REPO_FOLDER" | sed 's/_/-/g' | sed 's/\b\(.\)/\u\1/g')
envsubst < "templates/README.md" > "$repo_path/README.md"
echo "Copy $ODOO_VERSION template files to $repo_path."
cp -r "templates/$ODOO_VERSION/." "$repo_path"
echo 'Remove deprecated repo files.'
rm -f "$repo_path/.flake8"
rm -f "$repo_path/.isort.cfg"
rm -f "$repo_path/.pylintrc-mandatory"
}
# Module commands
get-modules() {
if [[ -z "$1" ]]; then echo '\$1 is empty.'; exit; fi
local option="$2"
if [[ -z "$option" ]]; then
option="dirname"
fi
local modules
if [[ "$option" == "dirname" ]]; then
modules=$(echo "$1" | tr "," "\n" | xargs -I {} find {} -type f -name "__manifest__.py" | xargs grep -l -iE "version.*([0-9]+\.[0-9]+(\.[0-9]+)?|${ODOO_VERSION}(\.[0-9]+)*)" | xargs -r dirname | sort -u | tr "\n" "," | sed 's/,$//')
fi
if [[ "$option" == "basename" ]]; then
modules=$(echo "$1" | tr "," "\n" | xargs -I {} find {} -type f -name "__manifest__.py" | xargs grep -l -iE "version.*([0-9]+\.[0-9]+(\.[0-9]+)?|${ODOO_VERSION}(\.[0-9]+)*)" | xargs -r dirname | xargs -r -I {} basename {} | sort -u | tr "\n" "," | sed 's/,$//')
fi
echo "$modules"
}
get-module-version() {
if [[ -z "$1" ]]; then
echo '\$1 is empty.'
else
# Get version of module
local version=$(python -c "import ast; print(ast.literal_eval(open('$1/__manifest__.py').read())['version'])")
# Set default version
[[ -z "$version" ]] && version=0.0
local count_dots=$(echo "$version" | grep -o "\." | wc -l)
# Check if oca version or enterprise version
if [[ $count_dots == 2 ]]; then
version="$ODOO_VERSION.$version"
fi
if [[ $count_dots == 1 ]]; then
version="$ODOO_VERSION.$version"
fi
echo "$version"
fi
}
get-module-checksum() {
if [[ -z "$1" ]]; then
echo '\$1 is empty.'
else
bin/get-module-checksum "$1"
fi
}
list-modules() {
if [[ -z "$1" ]]; then echo '\$1 is empty.'; exit; fi
local modules=$(get-modules "$1" dirname)
echo "$modules" | tr ',' '\n'
}
# Container commands
archive-docker-tags() {
export CONTAINER_CONFIG
python bin/archive-docker-tags
}
template-compose() {
echo 'Template compose.yml'
# Load and export vars defined in compose template
for var in $(grep -oE '\$\{?[A-Z_][A-Z0-9_]*\}?' compose.yml.template); do
# Strip $, ${, }
var=${var#\$\{} # Remove leading ${
var=${var%\}} # Remove trailing }
var=${var#\$} # Remove leading $
export "$var"
done
# Add volume mounts
VOLUME_MOUNTS=""
if [[ -d "./tmp/postgres-odoo" ]]; then
VOLUME_MOUNTS="${VOLUME_MOUNTS} - ./tmp/postgres-odoo:/mnt/postgres-odoo"$'\n'
fi
if [[ -d "./addons" ]]; then
VOLUME_MOUNTS="${VOLUME_MOUNTS} - ./addons:/mnt/addons"$'\n'
fi
if [[ -d "./oca" ]]; then
VOLUME_MOUNTS="${VOLUME_MOUNTS} - ./oca:/mnt/oca"$'\n'
fi
if [[ -d "./enterprise" ]]; then
VOLUME_MOUNTS="${VOLUME_MOUNTS} - ./enterprise:/mnt/enterprise"$'\n'
fi
if [[ -d "./themes" ]]; then
VOLUME_MOUNTS="${VOLUME_MOUNTS} - ./themes:/mnt/themes"$'\n'
fi
VOLUME_MOUNTS="${VOLUME_MOUNTS%$'\n'}"
export VOLUME_MOUNTS
envsubst < "compose.yml.template" > "compose.yml"
}
container-ps() {
$CONTAINER_ENGINE ps
}
build-odoo() {
odoo_date=$(echo "$ODOO_REVISION" | cut -d'.' -f3-)
source "revisions/$ODOO_REVISION"
manifest_file="images/odoo/Dockerfile"
container_tag="odoo:$ODOO_VERSION"
container_revision_tag="odoo:$ODOO_REVISION"
case "$ODOO_VERSION" in
"15.0")
local python_version="3.9"
PLATFORM="linux/amd64"
;;
"16.0")
local python_version="3.11"
;;
"17.0")
local python_version="3.11"
;;
"18.0")
local python_version="3.12"
;;
"19.0")
local python_version="3.13"
;;
*)
local python_version="3.12"
;;
esac
local docker_output="--load"
if [[ -n "$1" ]]; then
docker_output="$1"
fi
echo "Python Version: $python_version"
echo "Platform: $PLATFORM"
echo "Enterprise Ref: $ODOO_ENTERPRISE_REF"
echo "Docker Output: $docker_output"
echo "Remove container image with tag ${CONTAINER_REGISTRY}/${container_revision_tag}"
docker image rm -f "${CONTAINER_REGISTRY}/${container_revision_tag}"
if ! docker buildx inspect odoo_builder >/dev/null 2>&1; then
docker buildx create --name odoo_builder --use
docker buildx inspect --bootstrap
else
docker buildx use odoo_builder
fi
echo "Run Docker build ${CONTAINER_REGISTRY}/${container_revision_tag} for ${PLATFORM}"
SOURCE_DATE_EPOCH=$(git -C odoo log -1 --pretty=%ct) docker buildx build --platform "$PLATFORM" . \
--file "$manifest_file" \
--build-arg PYTHON_VERSION="$python_version" \
--build-arg ODOO_VERSION="$ODOO_VERSION" \
--build-arg ODOO_DATE="$odoo_date" \
--build-arg ODOO_ENTERPRISE_REF="$ODOO_ENTERPRISE_REF" \
--tag "${CONTAINER_REGISTRY}/${container_tag}" \
--tag "${CONTAINER_REGISTRY}/${container_revision_tag}" \
"$docker_output"
}
build-odoo-cli() {
manifest_file="images/odoo-cli/Dockerfile"
container_tag="odoo-cli:latest"
local docker_output="--load"
if [[ -n "$1" ]]; then
docker_output="$1"
fi
echo "Platform: $PLATFORM"
echo "Docker Output: $docker_output"
echo "Remove container image with tag ${CONTAINER_REGISTRY}/${container_tag}"
docker image rm -f "${CONTAINER_REGISTRY}/${container_tag}"
if ! docker buildx inspect odoo_builder >/dev/null 2>&1; then
docker buildx create --name odoo_builder --use
docker buildx inspect --bootstrap
else
docker buildx use odoo_builder
fi
echo "Run Docker build ${CONTAINER_REGISTRY}/${container_tag} for ${PLATFORM}"
SOURCE_DATE_EPOCH=$(git -C odoo log -1 --pretty=%ct) docker buildx build --platform "$PLATFORM" . \
--file "$manifest_file" \
--tag "${CONTAINER_REGISTRY}/${container_tag}" \
"$docker_output"
}
build-odoo-mailgate() {
manifest_file="images/odoo-mailgate/Dockerfile"
container_tag="odoo-mailgate:latest"
local docker_output="--load"
if [[ -n "$1" ]]; then
docker_output="$1"
fi
echo "Platform: $PLATFORM"
echo "Docker Output: $docker_output"
echo "Remove container image with tag ${CONTAINER_REGISTRY}/${container_tag}"
docker image rm -f "${CONTAINER_REGISTRY}/${container_tag}"
if ! docker buildx inspect odoo_builder >/dev/null 2>&1; then
docker buildx create --name odoo_builder --use
docker buildx inspect --bootstrap
else
docker buildx use odoo_builder
fi
echo "Run Docker build ${CONTAINER_REGISTRY}/${container_tag} for ${PLATFORM}"
SOURCE_DATE_EPOCH=$(git -C odoo log -1 --pretty=%ct) docker buildx build --platform "$PLATFORM" . \
--file "$manifest_file" \
--tag "${CONTAINER_REGISTRY}/${container_tag}" \
"$docker_output"
}
build-odoo-upgrade() {
local manifest_file="images/odoo-upgrade/Dockerfile"
local postgres_versions="14 15 16 17"
local docker_output="--load"
if [[ -n "$1" ]]; then
docker_output="$1"
fi
if ! docker buildx inspect odoo_builder >/dev/null 2>&1; then
docker buildx create --name odoo_builder --use
docker buildx inspect --bootstrap
else
docker buildx use odoo_builder
fi
for postgres_version in $postgres_versions; do
container_tag="odoo-upgrade:$postgres_version"
echo "Posgres Version: $postgres_version"
echo "Platform: $PLATFORM"
echo "Docker Output: $docker_output"
echo "Removing existing image: $full_tag"
docker image rm -f "$full_tag" 2>/dev/null || true
echo "Running Docker build for $full_tag on platform $PLATFORM"
SOURCE_DATE_EPOCH=$(git -C odoo log -1 --pretty=%ct) \
docker buildx build --platform "$PLATFORM" . \
--file "$manifest_file" \
--build-arg POSTGRES_VERSION="$postgres_version" \
--tag "${CONTAINER_REGISTRY}/${container_tag}" \
"$docker_output"
if [[ $? -ne 0 ]]; then
echo "Build failed for PostgreSQL $postgres_version"
return 1
fi
echo "Build succeeded for PostgreSQL $postgres_version"
done
}
load-latest-revision() {
if [[ -n "$1" ]]; then
ODOO_VERSION="$1"
fi
ODOO_REVISION=$(list-revision | grep "$ODOO_VERSION" | tail -n1)
load-revision "$ODOO_REVISION"
}
checkout-latest-revision() {
if [[ -n "$1" ]]; then
ODOO_VERSION="$1"
fi
ODOO_REVISION=$(list-revision | grep "$ODOO_VERSION" | tail -n1)
checkout-revision "$ODOO_REVISION"
check-version
}
container-login() {
if [[ -n "$1" ]]; then
CONTAINER_REGISTRY_USERNAME="$1"
fi
if [[ -n "$2" ]]; then
CONTAINER_REGISTRY_PASSWORD="$2"
fi
echo "Docker login with username $CONTAINER_REGISTRY_USERNAME."
echo "$CONTAINER_REGISTRY_PASSWORD" | docker --config "$CONTAINER_CONFIG" login --username "$CONTAINER_REGISTRY_USERNAME" --password-stdin
echo "$CONTAINER_REGISTRY_PASSWORD" | docker --config "$CONTAINER_CONFIG" login dhi.io --username "$CONTAINER_REGISTRY_USERNAME" --password-stdin
}
login-podman() {
if [[ -n "$1" ]]; then
CONTAINER_REGISTRY_USERNAME="$1"
fi
if [[ -n "$2" ]]; then
CONTAINER_REGISTRY_PASSWORD="$2"
fi
echo "Podman login with username $CONTAINER_REGISTRY_USERNAME."
podman login --username "$CONTAINER_REGISTRY_USERNAME" --password "$CONTAINER_REGISTRY_PASSWORD" docker.io
}
test-odoo-version-regex() {
# If ODOO_VERSION=19.0 then
# 1.0 Match
# 1.1 Match
# 2.5 Match
# 2.0.0 Match
# 13.0.1.0.0 No match
# 14.0.2.1.1 No match
# 13.0.1.0.0 No match
# 19.0.0.0.0 Match
# Variations of the version key:
# 'version': '19.0.x',
# "version": "1.0",
# 'version': '19.0.1.0.0',
echo -e "\033[38;5;214mTEST\033[0m: Find and check versions in module"
versions=$(grep -r --include="__manifest__.py" '[\"'\'']version[\"'\'']:.[\"'\'']' addons enterprise oca odoo themes |
sed -E 's/.+[\"'\'']version[\"'\'']:.[\"'\'']([0-9].+)[\"'\''].+/\1/g' |
sort -u)
ODOO_VERSION="19.0"
for version in $versions; do
echo -n "Check version $version: "
# 1. regex: version.[0-9]\.[0-9]$
# 2. regex: version.[0-9]\.[0-9]\.[0-9]$
# 3. regex: version.${ODOO_VERSION}\.[0-9]\.[0-9]\.[0-9]$
if [[ $version =~ ^[0-9]+\.[0-9]+$ ||
$version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ||
$version =~ ^${ODOO_VERSION}\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "✓ Match"
else
echo "✗ No match"
fi
done
echo -e "\033[38;5;214mTEST\033[0m: Run set-addons-path"
export PATH=./images/odoo/bin/:$PATH
export TEST_ADDONS_DIR="./templates,./themes,./enterprise,/gugus,./oca,./addons"
export ODOO_VERSION="19.0"
source ./images/odoo/bin/set-addons-path
echo "ADDONS_PATH: $ADDONS_PATH"
}
test-image() {
# Test the scripts of the Docker images without starting the enviroment.
set -e
if [[ -z "$1" ]]; then
echo '$1 is empty.'
exit
fi
if [[ "$1" == "images/odoo-upgrade" ]]; then
container_tag="odoo-upgrade"
elif [[ "$1" == "images/odoo-cli" ]]; then
container_tag="odoo-cli"
fi
if [[ "$container_tag" =~ ^odoo: ]]; then
generate-ssh-keys
export GIT_SSH_PRIVATE_KEY
export GIT_SSH_PUBLIC_KEY
export PATH=./images/odoo/bin/:$PATH
export LOCAL_PATH="./tmp"
mkdir -p "$LOCAL_PATH"
echo -e "\033[38;5;214mTEST\033[0m: Run git clone addons"
local server_tools_git_ref=$(curl -s "https://api.github.com/repos/OCA/server-tools/branches/$ODOO_VERSION" | grep '"sha":' | head -n 1 | awk -F '"' '{print $4}')
export ADDONS_GIT_REPOS="https://github.com/OCA/server-tools.git#${ODOO_VERSION}#${server_tools_git_ref}"
# This will remove all SSH keys at the end
./images/odoo/bin/clone-git-addons
rm -rf "$LOCAL_PATH/github.com" # Cleanup for next run
echo -e "\033[38;5;214mTEST\033[0m: Install python package."
export PYTHON_INSTALL="prometheus-client,pyjwt"
./images/odoo/bin/install-python-packages
echo -e "\033[38;5;214mTEST\033[0m: Sync python project."
cat > tmp/pyproject.toml << 'EOF'
[project]
name = "odoo-build-project"
version = "0.1.0"
description = "Test project for uv sync."
dependencies = [
"requests>=2.28.0",
"click>=8.0.0",
]
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[tool.uv]
dev-dependencies = [
"pytest>=7.0.0",
"black>=23.0.0",
]