Skip to content

Commit

Permalink
[ADD] Initial Release
Browse files Browse the repository at this point in the history
* Create a method to upgrade core Odoo using Docker. Support v8=>9 and v9=>10
  • Loading branch information
lasley committed Jan 10, 2018
1 parent e314ce9 commit 3f838a5
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions 10.0-Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <support@laslabs.com>" \
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
27 changes: 27 additions & 0 deletions 9.0-Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <support@laslabs.com>" \
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
183 changes: 178 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down Expand Up @@ -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
======================
Expand Down
1 change: 1 addition & 0 deletions custom/dependencies/apt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rsync
Empty file.
2 changes: 2 additions & 0 deletions custom/dependencies/pip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git+https://github.com/OCA/openupgradelib.git
git+https://github.com/LasLabs/git-aggregator.git@feature/thread-download
26 changes: 26 additions & 0 deletions custom/entrypoint.d/99-do-upgrade.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > ~/.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}"
Empty file added custom/src/addons.yaml
Empty file.
Empty file added custom/src/private/.empty
Empty file.
12 changes: 12 additions & 0 deletions custom/src/repos.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions custom/src/upgrade-odoo
Original file line number Diff line number Diff line change
@@ -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}"
65 changes: 65 additions & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f838a5

Please sign in to comment.