diff --git a/.travis.yml b/.travis.yml index b280a167..d6486ec8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ env: - DOCKER_TAG=latest - IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG matrix: - - ODOO_VERSIONS=8.0 - - ODOO_VERSIONS=9.0 - - ODOO_VERSIONS=10.0 - - ODOO_VERSIONS=11.0 + - DOCKER_TAG=8.0 ODOO_VERSIONS=8.0 + - DOCKER_TAG=9.0 ODOO_VERSIONS=9.0 + - DOCKER_TAG=10.0 ODOO_VERSIONS=10.0 + - DOCKER_TAG=11.0 ODOO_VERSIONS=11.0 before_install: - sudo apt-get update diff --git a/hooks/build b/hooks/build index b2041cff..78f28081 100755 --- a/hooks/build +++ b/hooks/build @@ -1,50 +1,17 @@ -#!/usr/bin/env python -from __future__ import print_function -import json -import logging -import os -from datetime import datetime -from glob import iglob +#!/bin/bash +set -ex -import docker +if [ "$DOCKER_TAG" == latest ]; then + dockerfile=11.0.Dockerfile +else + dockerfile="$DOCKER_TAG.Dockerfile" +fi -CLIENT = docker.client.from_env() -DEFAULT_VERSION = "11.0" -DOCKER_REPO = os.environ.get("DOCKER_REPO", "tecnativa/odoo-base") -GIT_SHA1 = os.environ.get("GIT_SHA1", "") -ODOO_VERSIONS = frozenset(os.environ.get( - "ODOO_VERSIONS", "8.0 9.0 10.0 11.0").split()) - -logging.basicConfig(level=logging.INFO) - -# Build version-specific images -for dockerfile in iglob("*.Dockerfile"): - version = dockerfile.replace(".Dockerfile", "") - if version not in ODOO_VERSIONS: - continue - logging.info("Building image for version %s", version) - # Low-level api for building images and streaming output - response = CLIENT.api.build( - path=".", - dockerfile=dockerfile, - tag=u"{}:{}".format(DOCKER_REPO, version), - buildargs={ - "BUILD_DATE": datetime.utcnow().isoformat(), - "ODOO_VERSION": version, - "VCS_REF": GIT_SHA1, - } - ) - status = None - for line in response: - line = json.loads(line) - if line.get("status") not in {status, None}: - status = line["status"] - print(status) - if line.get("stream"): - print(line["stream"], end="") - -# Tag default version -if DEFAULT_VERSION in ODOO_VERSIONS: - logging.info("Tagging latest") - image = CLIENT.images.get(u"{}:{}".format(DOCKER_REPO, DEFAULT_VERSION)) - image.tag(DOCKER_REPO, "latest") +# See http://label-schema.org/rc1/#build-time-labels +time docker image build \ + --build-arg VCS_REF="$GIT_SHA1" \ + --build-arg BUILD_DATE="$(date --rfc-3339 ns)" \ + --build-arg ODOO_VERSION="$DOCKER_TAG" \ + --file "$dockerfile" \ + --tag "$IMAGE_NAME" \ + . diff --git a/hooks/post_push b/hooks/post_push deleted file mode 100755 index b4d31ceb..00000000 --- a/hooks/post_push +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python -import os -from glob import iglob - -import docker - -DEFAULT_VERSION = "11.0" -DOCKER_REPO = os.environ.get("DOCKER_REPO", "tecnativa/odoo-base") -DOCKER_TAG = os.environ.get("DOCKER_TAG") -IMAGE_NAME = os.environ.get("IMAGE_NAME", u"{}:{}") -CLIENT = docker.client.from_env() - -if DOCKER_TAG == "latest": - # Push other tags, that should have been built already - for image in CLIENT.images.list(DOCKER_REPO): - for tag in image.tags: - if tag != IMAGE_NAME: - CLIENT.images.push(tag)