add restore db script @docker
This commit is contained in:
parent
25d50e9fb2
commit
6adcfc6a27
@ -5,7 +5,7 @@ on:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
# options in commit : @native @docker @push_image @run_test @no_cleanup
|
||||
# options in commit : @native @docker @push_image @run_test @no_cleanup @restore_db
|
||||
jobs:
|
||||
native:
|
||||
if: contains(github.event.head_commit.message, '@native')
|
||||
@ -92,6 +92,7 @@ jobs:
|
||||
run: sleep 10s
|
||||
|
||||
- name: Restore Database
|
||||
if: contains(github.event.head_commit.message, '@restore_db')
|
||||
run: make restore_database
|
||||
|
||||
- name: Run Tests
|
||||
|
12
Makefile
12
Makefile
@ -14,6 +14,7 @@ DEPLOY_PATH=${PWD}/deployment
|
||||
SETUP_PATH=${PWD}/setup
|
||||
CONFIG=odoo.conf
|
||||
HUB=hub.nextzenos.com
|
||||
CDN=https://cdn.nextzenos.com/CDN/NextERP
|
||||
ORGANIZATION=nexterp
|
||||
PROJECT := odoo18
|
||||
ODOO_IMAGE=${HUB}/${ORGANIZATION}/$(PROJECT)
|
||||
@ -21,7 +22,7 @@ TAG := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
CONTAINER_ID=${PROJECT}-${TAG}
|
||||
VERSION := community
|
||||
ADDONS=${PWD}/addons,${PWD}/odoo/addons
|
||||
|
||||
BACKUP=${CDN}/raw/branch/main/backup/${VERSION}/odoo18-main_2025-01-15_08-05-47.zip
|
||||
install:
|
||||
sudo apt update -y && \
|
||||
sudo apt install -y python3-pip libldap2-dev libpq-dev libsasl2-dev postgresql-client && \
|
||||
@ -55,14 +56,7 @@ run_server_docker:
|
||||
update_tag:
|
||||
${SETUP_PATH}/update_tag.sh $(CURR_BRANCH)
|
||||
restore_database:
|
||||
@echo "Checking for backup.zip in container..."
|
||||
@if sudo docker exec ${CONTAINER_ID} test -f /etc/odoo/backup/backup.zip; then \
|
||||
echo "Restoring database from backup..."; \
|
||||
sudo docker exec ${CONTAINER_ID} odoo db --config=/etc/odoo/${CONFIG} load backup /etc/odoo/backup/backup.zip; \
|
||||
else \
|
||||
echo "Error: backup.zip not found in container. Aborting restore."; \
|
||||
fi
|
||||
|
||||
${SETUP_PATH}/restore.sh ${BACKUP} ${CONTAINER_ID}
|
||||
stop_server_docker:
|
||||
@if ! docker ps | grep -q "${CONTAINER_ID}"; then \
|
||||
echo "Container not found. Skipping"; \
|
||||
|
Binary file not shown.
@ -18,7 +18,7 @@ services:
|
||||
volumes:
|
||||
- ${ODOO_ADDONS:-./addons}:/mnt/extra-addons
|
||||
- ${ODOO_CONFIG:-./etc}:/etc/odoo
|
||||
- ${ODOO_BACKUP:-./backup/ce}:/etc/odoo/backup
|
||||
- ${ODOO_BACKUP:-./backup}:/etc/odoo/backup
|
||||
restart: always
|
||||
db:
|
||||
image: postgres:16
|
||||
|
@ -87,9 +87,7 @@ def main():
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_IMAGE", value_to_set=image,quote_mode="never")
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_TAG", value_to_set=tag,quote_mode="never")
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_CONTAINER", value_to_set=container,quote_mode="never")
|
||||
if (backup == 'community'):
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_BACKUP", value_to_set=f'{base_dir}/backup/ce',quote_mode="never")
|
||||
if (backup == 'enterprise'):
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_BACKUP", value_to_set=f'{base_dir}/backup/enterprise',quote_mode="never")
|
||||
set_key(dotenv_path=env_file_path, key_to_set="ODOO_BACKUP", value_to_set=f'{base_dir}/backup',quote_mode="never")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
84
setup/restore_database.sh
Executable file
84
setup/restore_database.sh
Executable file
@ -0,0 +1,84 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
export PATH=/usr/sbin:$PATH
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
set -euo pipefail
|
||||
readonly COLOUR_RESET='\e[0m'
|
||||
readonly aCOLOUR=(
|
||||
'\e[38;5;154m' # green | Lines, bullets and separators
|
||||
'\e[1m' # Bold white | Main descriptions
|
||||
'\e[90m' # Grey | Credits
|
||||
'\e[91m' # Red | Update notifications Alert
|
||||
'\e[33m' # Yellow | Emphasis
|
||||
)
|
||||
trap 'onCtrlC' INT
|
||||
onCtrlC() {
|
||||
echo -e "${COLOUR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Show() {
|
||||
# OK
|
||||
if (($1 == 0)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# FAILED
|
||||
elif (($1 == 1)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
exit 1
|
||||
# INFO
|
||||
elif (($1 == 2)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
# NOTICE
|
||||
elif (($1 == 3)); then
|
||||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
||||
fi
|
||||
}
|
||||
|
||||
Warn() {
|
||||
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
|
||||
}
|
||||
|
||||
GreyStart() {
|
||||
echo -e "${aCOLOUR[2]}\c"
|
||||
}
|
||||
|
||||
ColorReset() {
|
||||
echo -e "$COLOUR_RESET\c"
|
||||
}
|
||||
|
||||
|
||||
main(){
|
||||
DEPLOYMENT_DIR=$(pwd)/deployment/backup/
|
||||
DOWNLOAD_URL="$1"
|
||||
CONTAINER_ID="$2"
|
||||
BACKUP_FILE="$DEPLOYMENT_DIR/backup.zip"
|
||||
|
||||
# Create the deployment directory if it doesn't exist
|
||||
mkdir -p "$DEPLOYMENT_DIR"
|
||||
|
||||
# Check if the download URL is valid
|
||||
echo "Checking if the URL is valid: $DOWNLOAD_URL"
|
||||
if curl --head --silent --fail "$DOWNLOAD_URL" > /dev/null; then
|
||||
echo "URL is valid. Proceeding with download..."
|
||||
else
|
||||
Show 1 "Error: Invalid or inaccessible URL: $DOWNLOAD_URL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Download the file
|
||||
wget -P "$DEPLOYMENT_DIR" -O "$BACKUP_FILE" "$DOWNLOAD_URL"
|
||||
|
||||
# Check if the file was downloaded
|
||||
if [[ -f "$BACKUP_FILE" ]]; then
|
||||
Show 0 "Backup file successfully downloaded to: $BACKUP_FILE"
|
||||
else
|
||||
Show 1 "Error: Backup file was not downloaded."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute the Docker command
|
||||
Show 2 "Running Docker command to load the backup..."
|
||||
sudo docker exec "${CONTAINER_ID}" odoo db --config=/etc/odoo/odoo.conf load backup /etc/odoo/backup/backup.zip
|
||||
}
|
||||
|
||||
main $1 $2
|
Loading…
Reference in New Issue
Block a user