-
Notifications
You must be signed in to change notification settings - Fork 0
/
o-dev-start
executable file
·169 lines (149 loc) · 5.64 KB
/
o-dev-start
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
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-w <workspace>] [-d <devtools-dir>] [-u <ubuntu-version>] [--build] [--build-with-cache] [--db]
Start Docker containers for Odoo development.
The first build might take a while, since the image is built from scratch.
All tools in this repository will be available in the container as well.
To exit the interactive shell session, just run the command "exit".
Options:
-h, --help Print this help and exit.
-v, --verbose Print script debug info.
-w <workspace>, --workspace <workspace>
Specify the absolute path to the development workspace
to mount in the Docker container's /code directory.
(default: ~/code/odoo)
-d <devtools>, --devtools <devtools>
Specify the absolute path to your odoo-dev development
tools directory to mount in the Docker container's
/home/odoo/bin directory.
(default: this tool's directory)
-u <ubuntu-version>, --ubuntu-version <ubuntu-version>
Specify with which Ubuntu version to run this container.
(options: jammy|noble)
(default: jammy)
--build Force a full rebuild of the Docker image.
--build-with-cache Force a rebuild of the Docker image, but using the
existing cache.
--db Only start the PostgreSQL server (if you want to run
your Odoo server on your local machine).
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
}
# shellcheck disable=SC2034
setup_formatting() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT="\033[0m"
# Bold
B="\033[1m" B_END="\033[22m"
# Italic
I="\033[3m" I_END="\033[23m"
# Underline
U="\033[4m" U_END="\033[24m"
# Colors (_BG = Background, BR_ = Bright)
BLACK="\033[30m" BLACK_BG="\033[40m" BR_BLACK="\033[90m" BR_BLACK_BG="\033[100m"
RED="\033[31m" RED_BG="\033[41m" BR_RED="\033[91m" BR_RED_BG="\033[101m"
GREEN="\033[32m" GREEN_BG="\033[42m" BR_GREEN="\033[92m" BR_GREEN_BG="\033[102m"
YELLOW="\033[33m" YELLOW_BG="\033[43m" BR_YELLOW="\033[93m" BR_YELLOW_BG="\033[103m"
BLUE="\033[34m" BLUE_BG="\033[44m" BR_BLUE="\033[94m" BR_BLUE_BG="\033[104m"
MAGENTA="\033[35m" MAGENTA_BG="\033[45m" BR_MAGENTA="\033[95m" BR_MAGENTA_BG="\033[105m"
CYAN="\033[36m" CYAN_BG="\033[46m" BR_CYAN="\033[96m" BR_CYAN_BG="\033[106m"
WHITE="\033[37m" WHITE_BG="\033[47m" BR_WHITE="\033[97m" BR_WHITE_BG="\033[107m"
DEFAULT="\033[39m" DEFAULT_BG="\033[49m"
else
NOFORMAT="" B="" B_END="" I="" I_END="" U="" U_END=""
BLACK="" BLACK_BG="" BR_BLACK="" BR_BLACK_BG=""
RED="" RED_BG="" BR_RED="" BR_RED_BG=""
GREEN="" GREEN_BG="" BR_GREEN="" BR_GREEN_BG=""
YELLOW="" YELLOW_BG="" BR_YELLOW="" BR_YELLOW_BG=""
BLUE="" BLUE_BG="" BR_BLUE="" BR_BLUE_BG=""
MAGENTA="" MAGENTA_BG="" BR_MAGENTA="" BR_MAGENTA_BG=""
CYAN="" CYAN_BG="" BR_CYAN="" BR_CYAN_BG=""
WHITE="" WHITE_BG="" BR_WHITE="" BR_WHITE_BG=""
DEFAULT="" DEFAULT_BG=""
fi
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1}
msg "$msg"
exit "$code"
}
parse_params() {
ODOO_WORKSPACE_DIR=~/code/odoo
ODOO_DEVTOOLS_DIR="$script_dir"
UBUNTU_VERSION=jammy
build=false
build_with_cache=false
db=false
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-b | --branch)
ODOO_DEP_BRANCH="${2:-$ODOO_DEP_BRANCH}"
shift
;;
-w | --workspace)
ODOO_WORKSPACE_DIR="${2:-$ODOO_WORKSPACE_DIR}"
shift
;;
-d | --devtools)
ODOO_DEVTOOLS_DIR="${2:-$ODOO_DEVTOOLS_DIR}"
shift
;;
-u | --ubuntu-version)
UBUNTU_VERSION="${2:-$UBUNTU_VERSION}"
shift
;;
--build) build=true ;;
--build-with-cache) build_with_cache=true ;;
--db) db=true ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
return 0
}
parse_params "$@"
setup_formatting
docker="sudo docker"
if [[ "$OSTYPE" == "darwin"* ]]; then
# No need to sudo when on macOS
docker="docker"
fi
msg "🟣 ${MAGENTA}${B}Odoo Development Container${NOFORMAT}\n"
export ODOO_DEVTOOLS_DIR
export ODOO_WORKSPACE_DIR
export UBUNTU_VERSION
if $db; then
msg "🗄️ ${WHITE}${B}Starting the PostgreSQL server${NOFORMAT}"
$docker compose -f "$script_dir/docker/compose.yaml" up -d db
else
if $build || $build_with_cache; then
msg "🏗️ ${WHITE}${B}Force rebuilding the Docker image${NOFORMAT}"
msg " ${BR_BLACK}${I}This could take a while ...${NOFORMAT}\n"
$docker compose -f "$script_dir/docker/compose.yaml" down
if $build_with_cache; then
$docker compose -f "$script_dir/docker/compose.yaml" build odoo
else
$docker compose -f "$script_dir/docker/compose.yaml" build --no-cache odoo
fi
fi
msg "\n📦 ${WHITE}${B}Starting the Docker containers${NOFORMAT}\n"
msg " ${BR_BLACK}${I}If it's the first time, building could take a while ...${NOFORMAT}\n"
$docker compose -f "$script_dir/docker/compose.yaml" up -d
msg "\n💻 ${WHITE}${B}Starting an interactive shell to the Docker container${NOFORMAT}\n"
$docker compose -f "$script_dir/docker/compose.yaml" exec odoo bash
fi