Skip to content

Commit

Permalink
Merge pull request #66 from guewen/update-example
Browse files Browse the repository at this point in the history
Update example
  • Loading branch information
guewen authored Sep 5, 2018
2 parents 5b10535 + 8a2177e commit ab59b55
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 115 deletions.
62 changes: 6 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,20 @@ IMAGE=$(NAME):$(VERSION)
ifeq ($(BATTERIES), True)
$TAG=$(TAG)-batteries
IMAGE_LATEST=$(IMAGE)-latest-batteries
DOCKERFILE='Dockerfile-batteries'
DOCKERFILE=Dockerfile-batteries
else
IMAGE_LATEST=$(IMAGE)-latest
DOCKERFILE='Dockerfile'
DOCKERFILE=Dockerfile
endif
ODOO_URL=https://github.com/odoo/odoo/archive/$(VERSION).tar.gz

export

all: build


.PHONY: build
build:
$(eval TMP := $(shell mktemp -u))
cp -r $(VERSION) $(TMP)
cp -r bin/ $(TMP)
cp -r common/* $(TMP)
sed -i "1i FROM $(IMAGE_LATEST)" $(TMP)/Dockerfile-onbuild
sed -i "1i FROM $(NAME):$(VERSION)-latest" $(TMP)/Dockerfile-batteries
cp -r install/ $(TMP)
cp -r start-entrypoint.d/ $(TMP)
cp -r before-migrate-entrypoint.d/ $(TMP)
docker build --no-cache -f $(TMP)/$(DOCKERFILE) -t $(IMAGE_LATEST) $(TMP)
docker build --no-cache -f $(TMP)/Dockerfile-onbuild -t $(IMAGE_LATEST)-onbuild $(TMP)
rm -rf $(TMP)
bash build.sh


.PHONY: tag
Expand Down Expand Up @@ -59,44 +49,4 @@ push_latest_main:

.PHONY: test
test:
$(eval TMP := $(shell mktemp -u))
cp -r example $(TMP)
rm -rf $(TMP)/odoo/src
wget -nv -O /tmp/odoo.tar.gz $(ODOO_URL)
tar xfz /tmp/odoo.tar.gz -C $(TMP)/odoo/
mv $(TMP)/odoo/odoo-$(VERSION) $(TMP)/odoo/src
echo '>>> Run test for base image'
sed 's|FROM .*|FROM $(IMAGE_LATEST)|' -i $(TMP)/odoo/Dockerfile
cat $(TMP)/odoo/Dockerfile
mkdir $(TMP)/.cachedb
# migration: standard
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -e LOAD_DB_CACHE="false" odoo odoo --stop-after-init
# runmigration: create the dump
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -v $(TMP)/.cachedb:/.cachedb -e CREATE_DB_CACHE="true" odoo runmigration
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) odoo dropdb odoodb
# runmigration: use dump
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -v $(TMP)/.cachedb:/.cachedb -e LOAD_DB_CACHE="true" odoo runmigration
cd $(TMP) && docker-compose -f docker-compose.yml down
echo " - version: 9.0.1" >> $(TMP)/odoo/migration.yml
echo " operations:">> $(TMP)/odoo/migration.yml
echo " post:" >> $(TMP)/odoo/migration.yml
echo " - anthem songs.install.demo::create_partners" >> $(TMP)/odoo/migration.yml
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) odoo dropdb odoodb
# runmigration: ceil
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -v $(TMP)/.cachedb:/.cachedb -e LOAD_DB_CACHE="true" -e MIG_LOAD_VERSION_CEIL="9.0.1" odoo runmigration
# runtests: standard
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -e LOAD_DB_CACHE="false" -e CREATE_DB_CACHE="false" odoo runtests
## runtests: create the dump
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -v $(TMP)/.cachedb:/.cachedb -e CREATE_DB_CACHE="true" -e SUBS_MD5=testcache odoo runtests
## runtests: use dump
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) -v $(TMP)/.cachedb:/.cachedb -e LOAD_DB_CACHE="true" -e SUBS_MD5=testcache odoo runtests
cd $(TMP) && docker-compose -f docker-compose.yml down
echo '>>> Run test for onbuild image'
cp $(TMP)/odoo/Dockerfile-onbuild $(TMP)/odoo/Dockerfile
sed 's|FROM .*|FROM $(IMAGE_LATEST)-onbuild|' -i $(TMP)/odoo/Dockerfile
cat $(TMP)/odoo/Dockerfile
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) odoo odoo --stop-after-init
cd $(TMP) && docker-compose -f docker-compose.yml run --rm -e LOCAL_USER_ID=$(shell id -u) odoo runtests
cd $(TMP) && docker-compose -f docker-compose.yml down
rm -f /tmp/odoo.tar.gz
rm -rf $(TMP)
bash test.sh
44 changes: 44 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -euo pipefail

#
# Build the image
#
# Normally run by the Makefile:
#
# $ make VERSION=$VERSION build
#
# It expects the following variables to be set:
#
# * VERSION (9.0, 10.0, 11.0, ...)
# * IMAGE_LATEST (tag of the 'latest' image built)
# * DOCKERFILE (name of the file used for the Docker build)
#

if [ -z "$VERSION" ]; then
echo "VERSION environment variable is missing"
exit 1
fi

TMP=$(mktemp -d)
echo "Working in $TMP"

on_exit() {
echo "Cleaning up temporary directory..."
rm -rf $TMP
rm -f /tmp/odoo.tar.gz
}

trap on_exit EXIT

cp -r ${VERSION}/. ${TMP}/
cp -r bin/ ${TMP}
cp -r common/* ${TMP}
sed -i "1i FROM ${IMAGE_LATEST}" ${TMP}/Dockerfile-onbuild
sed -i "1i FROM ${NAME}:${VERSION}-latest" ${TMP}/Dockerfile-batteries
cp -r install/ ${TMP}
cp -r start-entrypoint.d/ ${TMP}
cp -r before-migrate-entrypoint.d/ ${TMP}

docker build --no-cache -f ${TMP}/${DOCKERFILE} -t ${IMAGE_LATEST} ${TMP}
docker build --no-cache -f ${TMP}/Dockerfile-onbuild -t ${IMAGE_LATEST}-onbuild ${TMP}
7 changes: 2 additions & 5 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Follow the steps:

1. Create directories. This is mandatory, they will be copied in the image

mkdir -p odoo/external-src odoo/local-src odoo/data odoo/features
mkdir -p odoo/external-src odoo/local-src odoo/data odoo/songs

2. Add a submodule for Odoo (official or OCA/OCB)

Expand All @@ -21,13 +21,10 @@ Follow the steps:

4. Optionally add custom addons in `odoo/local-src`

5. Copy the configuration template `etc/openerp.cfg.tmpl` in your project, see [the example file](odoo/etc/openerp.cfg.tmpl).
Adapt the `addons_path` and the other options if needed.

6. Create the Dockerfile, the bare minimum being (see also [the example
file](odoo/Dockerfile) that installs additional dependencies):

FROM camptocamp/odoo-project:9.0
FROM camptocamp/odoo-project:11.0
MAINTAINER <name>

ENV ADDONS_PATH=/odoo/local-src,/odoo/external-src/server-tools,/odoo/src/addons
Expand Down
33 changes: 0 additions & 33 deletions example/docker-compose.override.yml

This file was deleted.

30 changes: 16 additions & 14 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ version: '2'

services:
odoo:
tty: true
stdin_open: true
build: ./odoo/
ports:
- 8069
depends_on:
- db
volumes:
- "data-odoo:/data/odoo"
- "data-odoo-pytest-cache:/odoo/.cache"
# to speed build of image customise your .dockerignore (this is an help there)
- "./odoo:/odoo"
environment:
- DB_USER=odoo
- DB_PASS=odoo
- DB_NAME=odoodb
- ADMIN_PASSWD=# set me
- RUNNING_ENV=dev
- MARABUNTA_MODE=demo
- LOG_HANDLER=:WARN
# cached database dumps config for `runmigration` and `runtests`
- CREATE_DB_CACHE=false # set it to 'true' to create dumps
- LOAD_DB_CACHE=true # by default will always search for existing dumps
# SUBS_MD5 is `runtests` only, you need to define it to identify dumps,
# a good practice is to generate it based on the content you have in
# your dependencies (`odoo/src`, `odoo/external-src`)
# See README.md for more.
- SUBS_MD5=
# MIG_LOAD_VERSION is `runmigration` only, define it if you want to load
# a prior release dump that doesn't match `odoo/VERSION` number.
# See README.md for more.
- MIG_LOAD_VERSION_CEIL=
- MARABUNTA_MODE=demo # could be 'full' for the db with all the data
- MARABUNTA_ALLOW_SERIE=True # should not be set in production

db:
image: postgres:9.6
ports:
- 5432
environment:
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=odoo
Expand All @@ -40,10 +38,14 @@ services:

# can be useful for dev when longpolling is required
nginx:
image: camptocamp/odoo-nginx:9.0-1.2.1
image: camptocamp/odoo-nginx:11.0-1.3.0
ports:
- 80:80
depends_on:
- odoo

volumes:
data-odoo:
data-db:
# store pytest cache, allowing to use --lf or --ff (replay last or first failures)
data-odoo-pytest-cache:
9 changes: 5 additions & 4 deletions example/odoo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM camptocamp/odoo-project:10.0-latest
FROM camptocamp/odoo-project:11.0-latest
MAINTAINER Camptocamp

# For installing odoo you have two possibility adding the whole root directory
# For installing odoo you have two possibility
# 1. either adding the whole root directory
#COPY . /odoo

# or adding each directory, this solution will reduce the download time
# of the image on the server (we can reuse layout)
# 2. or adding each directory, this solution will reduce the build and download
# time of the image on the server (layers are reused)
COPY ./src /odoo/src
COPY ./external-src /odoo/external-src
COPY ./local-src /odoo/local-src
Expand Down
2 changes: 1 addition & 1 deletion example/odoo/Dockerfile-onbuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM camptocamp/odoo-project:10.0-latest-onbuild
FROM camptocamp/odoo-project:11.0-latest-onbuild
MAINTAINER Camptocamp

# Project's specifics packages
Expand Down
2 changes: 1 addition & 1 deletion example/odoo/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.0
11.0.0
2 changes: 1 addition & 1 deletion example/odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ migration:
options:
install_command: odoo
versions:
- version: 9.0.0
- version: 11.0.0
operations:
pre:
- "sh -c 'psql -c \"CREATE EXTENSION pg_trgm;\"'"
Expand Down
45 changes: 45 additions & 0 deletions example/test-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Composition used to run automated tests on the images
# Used by the Makefile at the repository's root

version: '2'

services:
odoo:
build: ./odoo/
depends_on:
- db
volumes:
- "data-odoo:/data/odoo"
environment:
- DB_USER=odoo
- DB_PASS=odoo
- DB_NAME=odoodb
- RUNNING_ENV=dev
- LOG_HANDLER=:WARN
- MARABUNTA_MODE=demo # could be 'full' for the db with all the data
# cached database dumps config for `runmigration` and `runtests`
- CREATE_DB_CACHE=false # set it to 'true' to create dumps
- LOAD_DB_CACHE=true # by default will always search for existing dumps
# SUBS_MD5 is `runtests` only, you need to define it to identify dumps,
# a good practice is to generate it based on the content you have in
# your dependencies (`odoo/src`, `odoo/external-src`)
# See README.md for more.
- SUBS_MD5=
# MIG_LOAD_VERSION is `runmigration` only, define it if you want to load
# a prior release dump that doesn't match `odoo/VERSION` number.
# See README.md for more.
- MIG_LOAD_VERSION_CEIL=

db:
image: postgres:9.6
ports:
- 5432
environment:
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=odoo
volumes:
- "data-db:/var/lib/postgresql/data"

volumes:
data-odoo:
data-db:
Loading

0 comments on commit ab59b55

Please sign in to comment.