Doc, tools for lokavaluto development
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Valentin Lab 84408939e6 fix: deploy ``master`` branch by default on ``charm-store`` 2 years ago
src fix: deploy ``master`` branch by default on ``charm-store`` 2 years ago
README.org new: full docker-for-mac support 4 years ago

README.org

Lokavaluto Dev Pack

\hypersetup{ linkcolor=blue, pdfborder={0 0 0 0} }

Resources (docs, tools) to help getting things done in the lokavaluto team

Common dev environment

We recommend you to try to stick to a somewhat common environment to avoid as much as possible any problem stemming from your installation.

The most important part is the usage of the same docker image of odoo and the same version of postgres. Here are suggestion of how to install it.

Installation

Linux

We are using compose, and installation process will download compose binary, and our charm-store.

Requirements
  • bash >= 4.3

  • docker >= 17.06

  • curl ## for installation

  • git

Deployment

We have a magic script for you that will install or update your current installation of compose and of the charms. You can run this from any terminal, and don't care about the directory from where you launch this.

curl -sS https://git.myceliandre.fr/Lokavaluto/dev-pack/raw/branch/dev/src/install.sh | bash

If you are curious of what it is doing, check:

https://git.myceliandre.fr/Lokavaluto/dev-pack/src/branch/dev/src/install.sh#L252-L273

MacOSX

There are 2 ways to get docker on mac:

  • docker desktop for mac

  • docker toolbox for mac (obsolete, but works with older macs)

They are basically described here:

https://docs.docker.com/docker-for-mac/docker-toolbox/

Docker Desktop for mac

We are using compose, and installation process will download compose binary, and our charm-store.

Requirements

On MacOSX, you might need to install homebrew and gnu tools. Try the deployment section before. Report us your success or not. If it seems not to work in some way, this could help:

## Install homebrew (from: https://brew.sh/)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

brew install binutils diffutils findutils gawk gnu-indent \
   gnu-sed gnu-tar gnu-which gnutls grep gzip \
   wdiff wget bash wget bash \
   gpatch less m4 make git openssh python
Deployment
curl -sS https://git.myceliandre.fr/Lokavaluto/dev-pack/raw/branch/dev/src/install.sh | bash &&
ln -sf ~"/bin/compose" "/usr/local/bin/compose"
Docker Toolbox for mac

This docker installs will create a virtualbox with a linux inside. Your /Users will be automatically mapped into your virtualbox linux VM.

Requirements

You'll not need anything more than the Docker Toolbox for mac installed.

This link will help you with that: https://docs.docker.com/toolbox/toolbox_install_mac/

Deployment

We have a magic script for you that will install or update your current installation of compose and of the charms.

You need to run this code in the bash of your Virtualbox, and don't care about the directory from where you launch this.

curl -sS https://git.myceliandre.fr/Lokavaluto/dev-pack/raw/branch/dev/src/install.sh | bash

Windows

There are different ways to run docker on windows, the preferred is on WSL2 with a native docker daemon running in the WSL2 environment.

But this is still not out, so you might prefer to run "Docker For Windows". In that latter case you won't be able to use our tool compose for the moment. However you can use the full blown docker-compose method.

Windows - docker for windows
Requirements
  • bash >= 4.3

  • docker >= 17.06

  • docker-compose

Deployment

You'll need to get our charms if you want to use our same postgres image.

This script will take care of what you need if run from a bash in WSL, and don't care about the directory from where you launch this.

curl -sS https://git.myceliandre.fr/Lokavaluto/dev-pack/raw/branch/dev/src/install.sh | bash
Windows - docker in WSL2

Just run this script in a bash session under WSL2, and don't care about the directory from where you launch this.

curl -sS https://git.myceliandre.fr/Lokavaluto/dev-pack/raw/branch/dev/src/install.sh | bash

Usage

using compose

This method only works if you are on linux, MacOSX, or Windows WSL2 with docker installed inside WSL2.

You need to create a compose.yml that suits your need. You can create it wherever you want. We would recommend you to create a sub-directory for your project named "lokavaluto" for instance, and place the compose.yml inside. Here's a good way to create the compose file, once you are in the correct directory, you can execute these command in a shell:

cat <<EOF > compose.yml
odoo:
  charm: odoo-tecnativa
  docker-compose:
    #image: docker.0k.io/mirror/odoo:rc_12.0-MYC-INIT
    image: docker.0k.io/mirror/odoo:rc_13.0-MYC-INIT
    ## Important to keep as a list: otherwise it'll overwrite charm's arguments.
    #command:
    #  - "--log-level=debug"
    #environment:
    #  TOTO: TATA
  #options:
  #  workers: 1
  #  modules:  ## 'base' is automatically added
  #    - l10n_fr
  #    - mymodule
  #  database: mybase  ## defaults to database in relation
  #  ## Odoo configuration file
  #  conf:
  #    options:
  #      email_from: me@example.com

  ## Create a direct access from 0.0.0.0:80
  relations:
    web-proxy:
      apache:
        ## be sure to add the following domain to your /etc/hosts
        domain: odoo

EOF

You can then launch the service(s) with:

compose up
Access odoo from your browser

You should access your odoo through the web-proxy, but if this is not what you want, you can access it directly.

Using the web-proxy to access odoo

You'll need to modify your /etc/hosts to include the domain name 'odoo' as a domain name for 127.0.0.1.

cat <<EOF | sudo tee -a /etc/hosts
127.0.0.1 odoo
EOF

This will ask for your password as it need write access to /etc/hosts.

You can then use http://odoo to access your odoo instance.

Direct connection to odoo container

You should be able to point your browser to the ip of the odoo container. You can find this IP using docker-ip.

If you are lazy, this might work:

ODOO_IP=$(docker-ip | grep odoo | sed -r 's/ +/ /g' | cut -f 3 -d " ")
echo "Odoo is up and running on: http://$ODOO_IP:8069"

If your setup allow direct access from the host running your browser to the container's network, then you can point your browser towards the given address.

using docker-compose

If you are NOT using compose and are using docker-compose, (for instance because you are on windows and want to stay in the official way to install docker.

You'll need also to initialize the postgres database.

Creating docker-compose.yml

You can run this instructions from your bash to create both .env and docker-compose.yml files:

cat <<EOF > .env
## Location of the charm-store (to build postgres)
CHARM_STORE=~/.charm-store

## Password for postgres's 'odoo' user
PG_DATABASE=odoo
PG_USER=odoo
PG_PASS=odoopassword

## Password for odoo admin tasks (create/delete/archive databases)
ODOO_ADMIN_PASSWORD=adminpass

## Password for postgres admin user 'postgres'
POSTGRES_ROOT_PASSWORD=postgresrootpassword
EOF
cat <<EOF > docker-compose.yml
version: '2.0'
services:
  odoo:
    ports:
    - 8069:8069
    command:
    - odoo
    - --config=/opt/odoo/auto/odoo.conf
    - --workers=1
    - -i base,l10n_fr
    - --database=odoo
    environment:
      ADMIN_PASSWORD: \${ODOO_ADMIN_PASSWORD}
      INITIAL_LANG: fr_FR
      LIST_DB: 'true'
      PGDATABASE: \${PG_DATABASE}
      PGHOST: postgres
      PGPASSWORD: \${PG_PASS}
      PGUSER: \${PG_USER}
    #image: docker.0k.io/mirror/odoo:rc_12.0-MYC-INIT
    image: docker.0k.io/mirror/odoo:rc_13.0-MYC-INIT
    links:
    - postgres
    restart: unless-stopped
    tty: true
    volumes:
    ## Volume is changed from normal 'compose' build
    - odoo-data:/var/lib/odoo:rw
  postgres:
    build: \${CHARM_STORE}/postgres/build
    restart: unless-stopped
    volumes:
      ## Volume is changed from normal 'compose' build
      - postgres-data:/var/lib/postgresql/data:rw
    ## Was added, differing from the normal 'compose' build
    environment:
      - POSTGRES_ROOT_PASSWORD
      - PG_DATABASE
      - PG_USER
      - PG_PASS
## new section
volumes:
  odoo-data:
  postgres-data:
EOF

You can then run:

docker-compose up -d
initialisation

This is only needed if you use the 'docker-compose' method. You need to do it once.

Set master password and allow access from odoo container

container 'postgres' needs to be up before running the following:

You need to do this only once.

## Update postgres password
docker-compose exec -T postgres bash -c \
  'PGUSER=postgres psql <<<"ALTER USER postgres WITH ENCRYPTED password "'\\\''$POSTGRES_ROOT_PASSWORD'\\\'

## Set pg_hba.conf
docker-compose exec -T postgres bash -c '
PG_HBA=/var/lib/postgresql/data/pg_hba.conf
if ! grep -E "^host all all (0.0.0.0/0|all) md5\$" "$PG_HBA" >/dev/null 2>&1; then
     if grep -E "^host all all (0.0.0.0/0|all) trust\$" "$PG_HBA" >/dev/null 2>&1; then
         sed -ri '\''s%^host all all (0\.0\.0\.0/0|all) trust$%host all all \1 md5%g'\'' \
             "$PG_HBA"
         echo "Accepting connection from outside."
     else
         echo "Can'\''t ensure connection from outside." >&2
         exit 1
     fi
fi
'

if [ "$?" != 0 ]; then
    echo "Error: can't update pg_hba.conf" >&2
else
    docker-compose restart postgres
fi
Create odoo table and odoo user
docker-compose exec -T postgres bash -c \
  'PGUSER=postgres createdb $PG_DATABASE'

docker-compose exec -T postgres bash -c \
  'PGUSER=postgres psql "$PG_DATABASE"' \
  <<<'CREATE EXTENSION IF NOT EXISTS unaccent;'

docker-compose exec -T postgres bash -c \
  'PGUSER=postgres psql <<<"CREATE USER \"$PG_USER\" WITH PASSWORD '\''$PG_PASS'\'' CREATEDB NOCREATEROLE;"'

docker-compose exec -T postgres bash -c \
  'PGUSER=postgres prefix_pg_local_command=" " pgm chown $PG_USER $PG_DATABASE'