Skip to content
Snippets Groups Projects
docker_build 1.41 KiB
Newer Older
#!/bin/zsh
# template version 2.5

# TODO add a way to bypass the value, maybe with a key in the setup.cfg file
repository=dockerhub.xcg.io
# TODO add a way to bypass the value, maybe with a key in the setup.cfg file
project_home=$(dirname $0)/..
image=$(basename $(readlink -f $project_home))

pushd $project_home

# Ensureconf 
hg cfensureconf || { echo 'hg cfensureconf failed' ; popd ; exit 1; }

popd

# Grab latest base image
ODOO_TYPE=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print c.get('odoo_scripts', 'odoo_type', 'odoo8')")

if [ "$ODOO_TYPE" = "odoo8" ];
then
    docker pull xcgd/odoo:8.0 || { echo 'Pull failed' ; exit 1; }
else
    docker pull xcgd/odoo:7.0 || { echo 'Pull failed' ; exit 1; }
fi

docker build -t $repository/$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 $repository/$image $repository/$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 -f $repository/$image $repository/$image:$bookmark || { echo 'Tag failed' ; exit 1; }
done

echo "Pushing docker image"
docker push $repository/$image || { echo 'Push failed' ; exit 1; }