IMAGE odoo10
LAYER shared/alpine
LAYER shared/libxml
LAYER shared/python2
LAYER shared/nodejs
LAYER odoo10/odoo10

FIXLAYER /usr/bin/fix-apk

RUN EOF
    # Install runtime dependencies
    apk --no-cache add libjpeg-turbo libpq py2-setuptools

    # Install build dependencies
    apk --no-cache add --virtual .deps build-base git libjpeg-turbo-dev libxml2-dev libxslt-dev linux-headers openldap-dev postgresql-dev py2-pip python2-dev yarn

    # Clone Odoo repository
    git clone -b 10.0 --single-branch --depth 1 https://github.com/odoo/odoo.git /srv/odoo

    # Clone addons
    git clone -b 10.0 --single-branch --depth 1 https://github.com/OCA/vertical-ngo /tmp/addons/vertical-ngo
    git clone -b 10.0 --single-branch --depth 1 https://github.com/OCA/stock-logistics-transport /tmp/addons/stock-logistics-transport
    git clone -b 10.0 --single-branch --depth 1 https://github.com/OCA/stock-logistics-warehouse /tmp/addons/stock-logistics-warehouse
    git clone -b 10.0 --single-branch --depth 1 https://github.com/OCA/stock-logistics-workflow /tmp/addons/stock-logistics-workflow
    git clone -b 10.0 --single-branch --depth 1 https://github.com/OCA/sale-workflow /tmp/addons/sale-workflow
    for ADDON in $(ls -d /tmp/addons/vertical-ngo/*/ /tmp/addons/stock-logistics-transport/*/ /tmp/addons/stock-logistics-warehouse/*/ /tmp/addons/stock-logistics-workflow/*/ /tmp/addons/sale-workflow/*/ | sed 's|/$||' | grep -v '/setup$'); do
        mv ${ADDON} /srv/odoo/addons/
    done
    rm -rf /tmp/addons

    # Install Odoo
    cd /srv/odoo
    pip install -r requirements.txt
    yarn global add less

    # Create OS user
    addgroup -S -g 8019 odoo
    adduser -S -u 8019 -h /srv/odoo -s /bin/false -g odoo -G odoo odoo
    chown -R odoo:odoo /srv/odoo

    # Cleanup
    apk --no-cache del .deps
    find /srv/odoo -name '.git*' -exec rm -rf {} +
    rm -rf /root/.cache/ /usr/local/share/.cache
EOF

MOUNT FILE /srv/odoo10/conf/odoo.conf srv/odoo/odoo.conf
MOUNT DIR /srv/odoo10/data srv/odoo/data

USER 8019 8019
CMD /srv/odoo/odoo-bin -c srv/odoo/odoo.conf
