diff --git a/.travis.yml b/.travis.yml index 919d621..ab4a7f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ services: env: matrix: - - TESTS="1" - - LINT_CHECK="1" + - DOCKERFILE="9.0-Dockerfile" TESTS="1" + - DOCKERFILE="10.0-Dockerfile" TESTS="1" install: - git clone --depth=1 https://github.com/LasLabs/docker-quality-tools.git ${HOME}/docker-quality-tools diff --git a/10.0-Dockerfile b/10.0-Dockerfile new file mode 100644 index 0000000..8a7f313 --- /dev/null +++ b/10.0-Dockerfile @@ -0,0 +1,27 @@ +FROM tecnativa/odoo-base:10.0 + +ARG ODOO_VERSION=10.0 + +ARG CONFIG_BUILD=true + +ENV ODOO_VERSION="$ODOO_VERSION" \ + CONFIG_BUILD="$CONFIG_BUILD" + +CMD ["/opt/odoo/custom/src/upgrade-odoo"] + +# Metadata +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL maintainer="LasLabs Inc " \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Odoo Upgrade v10" \ + org.label-schema.description="Docker image used for upgrading Odoo v9 to v10 using OCA OpenUpgrade." \ + org.label-schema.url="https://laslabs.com/" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/LasLabs/docker-odoo-upgrade" \ + org.label-schema.vendor="LasLabs Inc." \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" + +USER root diff --git a/9.0-Dockerfile b/9.0-Dockerfile new file mode 100644 index 0000000..69d4330 --- /dev/null +++ b/9.0-Dockerfile @@ -0,0 +1,27 @@ +FROM tecnativa/odoo-base:9.0 + +ARG ODOO_VERSION=9.0 + +ARG CONFIG_BUILD=true + +ENV ODOO_VERSION="$ODOO_VERSION" \ + CONFIG_BUILD="$CONFIG_BUILD" + +CMD ["/opt/odoo/custom/src/upgrade-odoo"] + +# Metadata +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION +LABEL maintainer="LasLabs Inc " \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="Odoo Upgrade v9" \ + org.label-schema.description="Docker image used for upgrading Odoo v8 to v9 using OCA OpenUpgrade." \ + org.label-schema.url="https://laslabs.com/" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/LasLabs/docker-odoo-upgrade" \ + org.label-schema.vendor="LasLabs Inc." \ + org.label-schema.version=$VERSION \ + org.label-schema.schema-version="1.0" + +USER root diff --git a/README.md b/README.md index 05c6be1..2c50db7 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,180 @@ Docker Odoo Upgrade =================== -This image upgrades Odoo major versions using OpenUpgrade. +This image upgrades Odoo major versions using OpenUpgrade. This is an +experimental upgrade methodology, and care should be taken if using for +production environments. -This repository is versioned by the Odoo version that is being targeted, and -you can only upgrade one version at a time. For example, to upgrade version +This repository is tagged by the Odoo version that is being targeted, and +you can only upgrade one version at a time. Each tag is represented by a +Dockerfile, prefixed with the tag name.F or example, to upgrade version 8 to version 10, you need to use the: -* 9.0 branch first -* 10.0 branch next +* [9.0 image](./9.0-Dockerfile) first +* [10.0 imaqe](./10.0-Dockerfile) next + +In order to use this image, you must meet the following condition(s): + +* Have an existing Dockerized Odoo instance on the version prior to the target version, + or the knowledge to make the necessary adjustments to the tutorial. + +Basic Instructions +================== + +High level usage of this image is as follows: + +* Run the image with the following options: + * Mount the root of your current Odoo file store into the container as `/var/lib/odoo_old` + * Note that this should not the be `filestore` directory, but the one that contains the + `filestore` and `sessions` directories (among others). + * Mount your new Odoo file store into the container as `/var/lib/odoo` + * You can easily use the old file store path if you wish + * Note that this should not the be `filestore` directory, but the one that contains the + `filestore` and `sessions` directories (among others). + * Link your current PostgreSQL container as `db_old` + * Link your new PostgreSQL container as `db` + * You can easily use your old container if you wish. This is primarily to facilitate PSQL + major version upgrades. + * Add environment variables for the PostgreSQL credentials (`PGUSER`, `PGPASSWORD`) + * Add environment variables for the old PostgreSQL db. These will default to the new + db credentials if not defined. (`PGUSER_OLD`, `PGPASSWORD_OLD`) + * Add environment variables for the source and target database names (`DB_SOURCE`, `DB_TARGET`) + +Given the above, and assuming the below: + +* You have a database container named `postgresql` + * There is a user named `odoo_user` with the password `odoo_password` that has superuser + access to the database. +* You have an Odoo v8 database named `odoo_v8` +* You have an Odoo v8 filesystem on your host at `/var/lib/odoo_v8` +* You want to upgrade to Odoo v10 + +You would run the following commands: + +```bash +export PG_USER=odoo_user +export PG_PASSWORD=odoo_password + +# Migrate v8 to v9 +docker run \ + --link postgresql:db \ + --link postgresql:db_old \ + -v /var/lib/odoo_v8:/var/lib/odoo_old \ + -v /var/lib/odoo_v9:/var/lib/odoo \ + -e "PGDATABASE=odoo_v9" \ + -e "PGUSER=${PG_USER}" \ + -e "PGPASSWORD=${PG_PASSWORD}" \ + -e "DB_SOURCE=odoo_v8" \ + -e "DB_TARGET=odoo_v9" \ + laslabs/odoo-upgrade:9.0 +# Migrate v9 to v10 +docker run \ + --link postgresql:db \ + --link postgresql:db_old \ + -v /var/lib/odoo_v9:/var/lib/odoo_old \ + -v /var/lib/odoo_v10:/var/lib/odoo \ + -e "PGDATABASE=odoo_v10" \ + -e "PGUSER=${PG_USER}" \ + -e "PGPASSWORD=${PG_PASSWORD}" \ + -e "DB_SOURCE=odoo_v9" \ + -e "DB_TARGET=odoo_v10" \ + laslabs/odoo-upgrade:10.0 +``` + +Running the above, you will be left with an Odoo v9 and an Odoo v10 database & +filesystem. They will be named `odoo_v9` and `odoo_v10` respectively. + +You typically want to run one migration at a time, and validate that it works before +proceeding to the next one. Living on the edge can be fun though. + +Dock-Compose Instructions +========================= + +The above section is mostly instructional usage, in that it uses plain Docker and +does not consider custom addons that you may have in your installation. Instead, you +would want to use a `docker-compose.yml` file similar to the below: + +```yml +version: "2" + +services: + + postgresql: + image: postgres:9.6-alpine + environment: + PGDATA: /var/lib/postgresql/data/pgdata + POSTGRES_PASSWORD: odoo_password + POSTGRES_USER: odoo_user + volumes: + - ~/postgresql_data/:/var/lib/postgresql/data/ + + # This is your original Odoo v8 deploy. + # Use this as a reference for changes that need to be made in other sections + # in order to match your actual deploy. + # + # odoo_v8: + # image: your_organization/your_odoo_scaffold_image:8.0 + # environment: + # - PGDATABASE: odoo_v8 + # - PGPASSWORD: odoo_password + # - PGUSER: odoo_user + # volumes: + # - ~/odoo_v8_data:/var/lib/odoo + # links: + # - postgresql:db + + openupgrade_v9: + image: laslabs/odoo-upgrade:9.0 + volumes: + - ~/odoo_v8_data:/var/lib/odoo_old + - ~/odoo_v9_data:/var/lib/odoo + environment: + - DB_SOURCE: odoo_v8 + - DB_TARGET: odoo_v9 + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db + - postgresql:db_old + + custom_upgrader: + image: your_organization/your_odoo_scaffold_image:9.0 + command: "autoupdate" + volumes: + - ~/odoo_v9_data:/var/lib/odoo + environment: + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db + + custom_upgrader: + image: your_organization/your_odoo_scaffold_image:9.0 + volumes: + - ~/odoo_v9_data:/var/lib/odoo + environment: + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db + +``` + +Testing +======= + +``` +export DB_SOURCE=odoo +export DB_TARGET=odoo_new +docker run -d --name postgres -e "POSTGRES_PASSWORD=pass" -e "POSTGRES_USER=odoo" postgres:9.6-alpine +docker run --link postgres:db -e "PGDATABASE=odoo" -e "PGUSER=odoo" -e "PGPASSWORD=pass" -v /root/old_odoo_filestore/:/var/lib/odoo lasley/odoo-buildouts:miller-rentals-8 /usr/local/bin/odoo -d ${DB_SOURCE} --workers=0 -i all --stop-after-init + +docker build -t openuprade:9 . +docker run -it --link postgres:db --link postgres:db_old -e "PGDATABASE=odoo" -e "PGUSER=odoo" -e "PGPASSWORD=pass" -e "DB_SOURCE=${DB_SOURCE}" -e "DB_TARGET=${DB_TARGET}" -v /root/old_odoo_filestore/:/var/lib/odoo_old -v /root/new_odoo_filestore/:/var/lib/odoo openuprade:9 +``` Configuration ============= @@ -45,6 +211,13 @@ pleasure: | Name | Default | Description | |------|---------|-------------| +PGUSER +PGPASSWORD +PGUSER_OLD:=PGUSER +PGPASSWORD_OLD:=PGPASSWORD +DB_SOURCE +DB_TARGET +ODOO_UPDATE:=all Known Issues / Roadmap ====================== diff --git a/custom/dependencies/apt.txt b/custom/dependencies/apt.txt new file mode 100644 index 0000000..d6e0544 --- /dev/null +++ b/custom/dependencies/apt.txt @@ -0,0 +1 @@ +rsync diff --git a/custom/dependencies/apt_build.txt b/custom/dependencies/apt_build.txt new file mode 100644 index 0000000..e69de29 diff --git a/custom/dependencies/pip.txt b/custom/dependencies/pip.txt new file mode 100644 index 0000000..a8db8c4 --- /dev/null +++ b/custom/dependencies/pip.txt @@ -0,0 +1,2 @@ +git+https://github.com/OCA/openupgradelib.git +git+https://github.com/LasLabs/git-aggregator.git@feature/thread-download diff --git a/custom/entrypoint.d/99-do-upgrade.sh b/custom/entrypoint.d/99-do-upgrade.sh new file mode 100644 index 0000000..225dc41 --- /dev/null +++ b/custom/entrypoint.d/99-do-upgrade.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -e + +log INFO "Setting up the Postgres credentials" + +PGUSER_OLD=${PGUSER_OLD:=${PGUSER}} +PGPASSWORD_OLD=${PGPASSWORD_OLD:=${PGPASSWORD}} + +cat < ~/.pgpass +db:5432:${DB_TARGET}:${PGUSER}:${PGPASSWORD} +db_old:5432:${DB_SOURCE}:${PGUSER_OLD}:${PGPASSWORD_OLD} +EOF + +chmod 0600 ~/.pgpass + +log INFO "Rsyncing the old file store to the new file store" +# mkdir -p /var/lib/odoo/filestore/${DB_TARGET}/ +# rsync -avz /var/lib/odoo_old/filestore/${DB_SOURCE}/ /var/lib/odoo/filestore/${DB_TARGET}/ + +log INFO "Creating a clone of the database for upgrade" +# echo "CREATE DATABASE ${DB_TARGET};" | psql -h db +# pg_dump -h db_old -Fc "${DB_SOURCE}" | pg_restore -h db -d "${DB_TARGET}" + +# log INFO "Upgrading database clone" +# odoo -d "${DB_TARGET}" --workers 0 --stop-after-init --update "${ODOO_UPDATE:=all}" diff --git a/custom/src/addons.yaml b/custom/src/addons.yaml new file mode 100644 index 0000000..e69de29 diff --git a/custom/src/private/.empty b/custom/src/private/.empty new file mode 100644 index 0000000..e69de29 diff --git a/custom/src/repos.yaml b/custom/src/repos.yaml new file mode 100644 index 0000000..bb89f92 --- /dev/null +++ b/custom/src/repos.yaml @@ -0,0 +1,12 @@ +# Odoo is always required +./odoo: + defaults: + # Shallow repositories (1=1) are faster & thinner + # You may need a bigger depth when merging PRs + depth: "$DEPTH_DEFAULT" + remotes: + openupgrade: https://github.com/OCA/OpenUpgrade.git + target: + openupgrade $ODOO_VERSION + merges: + - openupgrade $ODOO_VERSION diff --git a/custom/src/upgrade-odoo b/custom/src/upgrade-odoo new file mode 100644 index 0000000..742a039 --- /dev/null +++ b/custom/src/upgrade-odoo @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +log INFO "Upgrading database clone" +odoo -d "${DB_TARGET}" --workers 0 --stop-after-init --update "${ODOO_UPDATE:=all}" diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml new file mode 100644 index 0000000..9c7d5be --- /dev/null +++ b/examples/docker-compose.yml @@ -0,0 +1,65 @@ +version: "2" + +services: + + postgresql: + image: postgres:9.6-alpine + environment: + PGDATA: /var/lib/postgresql/data/pgdata + POSTGRES_PASSWORD: odoo_password + POSTGRES_USER: odoo_user + volumes: + - ~/postgresql_data/:/var/lib/postgresql/data/ + + # This is your original Odoo v8 deploy. + # Use this as a reference for changes that need to be made in other sections + # in order to match your actual deploy. + # + # odoo_v8: + # image: your_organization/your_odoo_scaffold_image:8.0 + # environment: + # - PGDATABASE: odoo_v8 + # - PGPASSWORD: odoo_password + # - PGUSER: odoo_user + # volumes: + # - ~/odoo_v8_data:/var/lib/odoo + # links: + # - postgresql:db + + openupgrade_v9: + image: laslabs/odoo-upgrade:9.0 + volumes: + - ~/odoo_v8_data:/var/lib/odoo_old + - ~/odoo_v9_data:/var/lib/odoo + environment: + - DB_SOURCE: odoo_v8 + - DB_TARGET: odoo_v9 + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db + - postgresql:db_old + + custom_upgrader: + image: your_organization/your_odoo_scaffold_image:9.0 + command: "autoupdate" + volumes: + - ~/odoo_v9_data:/var/lib/odoo + environment: + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db + + custom_upgrader: + image: your_organization/your_odoo_scaffold_image:9.0 + volumes: + - ~/odoo_v9_data:/var/lib/odoo + environment: + - PGDATABASE: odoo_v9 + - PGUSER: odoo_user + - PGPASSWORD: odoo_password + links: + - postgresql:db