Skip to content
Snippets Groups Projects
docker_build 2.11 KiB
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:

# Create docker script

# template version 2.10

# TODO add a way to bypass the value, maybe with a key in the setup.cfg file
here=$(dirname $0)
project_home=$(cd $here && cd .. && echo $PWD)
registry=$(python -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'registry') and c.get('odoo_scripts', 'registry')) or 'dockerhub.xcg.io'")
image_default=$(basename $(readlink -f $project_home))
image=$(python -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'image') and c.get('odoo_scripts', 'image')) or '$image_default'")

ignore_git=$(python -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'ignore_git') and c.get('odoo_scripts', 'ignore_git')) or 'False'")
docker_module_dir=

# Ensureconf 
pushd $project_home
if [ "$ignore_git" = "True" ];
then
    hg cfensureconf || echo "ignore all cfensureconf errors to bypass bad error code with git repositories"
else
    hg cfensureconf || { echo 'hg cfensureconf failed' ; popd ; exit 1; }
fi
popd

$here/docker_build_copy

docker build --pull=true --rm=true -t $registry/$image $project_home || { echo 'Build failed' ; exit 1; }

# tip is latest in docker
for tag in $(cd $project_home && hg id -t);
do
  if [[ ! -z "$tag" && "tip" != "$tag" ]]
  then
    echo "Docker tag with hg tag: $tag"
    docker tag -f $registry/$image $registry/$image:$tag || { echo 'Tag failed' ; exit 1; }
  fi
done

for bookmark in $(cd $project_home && hg id -B);
do
  echo "Docker tag with hg bookmark: $bookmark"
  docker tag $registry/$image $registry/$image:$bookmark || { echo 'Tag failed' ; exit 1; }
done

# TODO set as an option
if [ "$ODOO_SCRIPTS_PUSH" != "false" ]; then
  echo "Pushing docker image"
  docker push $registry/$image || { echo 'Push failed' ; exit 1; }
fi

$here/docker_build_clean