[SEBA-497]

Delayer XOS containers for xos-core and xos-client

Build venv-xos using the Makefile

Change-Id: I6d9324a51e574c847a0698040d930e2d947b185c
diff --git a/containers/xos/Dockerfile.libraries b/Dockerfile.client
similarity index 73%
rename from containers/xos/Dockerfile.libraries
rename to Dockerfile.client
index 088745b..6d60f3e 100644
--- a/containers/xos/Dockerfile.libraries
+++ b/Dockerfile.client
@@ -12,35 +12,33 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# xosproject/xos-libraries
-FROM xosproject/xos-base:3.2.2
+# xosproject/xos-client
+FROM xosproject/alpine-grpc-base:0.9.0
 
 # Add libraries
+RUN mkdir -p /opt/xos
 COPY lib /opt/xos/lib
 COPY VERSION /opt/xos
 
 # Install python using pip so their dependencies are installed
 RUN pip install -e /opt/xos/lib/xos-util \
  && pip install -e /opt/xos/lib/xos-config \
- && pip install -e /opt/xos/lib/xos-genx \
- && pip install -e /opt/xos/lib/xos-kafka \
- && pip install -e /opt/xos/lib/xos-synchronizer \
  && pip install -e /opt/xos/lib/xos-api \
- && pip freeze > /var/xos/pip_freeze_libraries_`date -u +%Y%m%dT%H%M%S`
+ && pip freeze > /var/xos/pip_freeze_xos-client_`date -u +%Y%m%dT%H%M%S`
 
 # Label image
-ARG org_label_schema_schema_version=1.0
-ARG org_label_schema_name=xos-libraries
 ARG org_label_schema_version=unknown
 ARG org_label_schema_vcs_url=unknown
 ARG org_label_schema_vcs_ref=unknown
 ARG org_label_schema_build_date=unknown
 ARG org_opencord_vcs_commit_date=unknown
 
-LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
-      org.label-schema.name=$org_label_schema_name \
+LABEL org.label-schema.schema-version=1.0 \
+      org.label-schema.name=xos-client \
       org.label-schema.version=$org_label_schema_version \
       org.label-schema.vcs-url=$org_label_schema_vcs_url \
       org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
       org.label-schema.build-date=$org_label_schema_build_date \
       org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date
+
+CMD ["xossh"]
diff --git a/containers/xos/Dockerfile.xos-core b/Dockerfile.core
similarity index 67%
rename from containers/xos/Dockerfile.xos-core
rename to Dockerfile.core
index abd6825..f94066a 100644
--- a/containers/xos/Dockerfile.xos-core
+++ b/Dockerfile.core
@@ -13,13 +13,27 @@
 # limitations under the License.
 
 # xosproject/xos-core
-FROM xosproject/xos-libraries:3.2.2
+FROM xosproject/alpine-grpc-base:0.9.0
+
+# Install libraries and python requirements
+COPY requirements.txt /tmp/requirements.txt
+RUN apk add --no-cache bash postgresql-dev \
+ && pip install -r /tmp/requirements.txt \
+ && pip freeze > /var/xos/pip_freeze_xos-core_`date -u +%Y%m%dT%H%M%S` \
+ && mkdir -p /opt/xos
 
 # Install XOS
-ADD xos /opt/xos
-ADD lib /opt/xos/lib
+COPY VERSION /opt/xos
+COPY xos /opt/xos
+COPY lib /opt/xos/lib
 
-RUN mkdir -p /opt/cord_profile /opt/xos-services /opt/xos_libraries \
+# Install XOS libraries
+RUN pip install -e /opt/xos/lib/xos-util \
+ && pip install -e /opt/xos/lib/xos-config \
+ && pip install -e /opt/xos/lib/xos-genx \
+ && pip install -e /opt/xos/lib/xos-kafka \
+ && pip freeze > /var/xos/pip_freeze_xos-core_libs_`date -u +%Y%m%dT%H%M%S` \
+ && mkdir -p /opt/cord_profile /opt/xos-services /opt/xos_libraries \
  && xosgenx --output /opt/xos/core/models --target django.xtarget --dest-extension py \
       --write-to-file model /opt/xos/core/models/core.xproto \
  && xosgenx --output /opt/xos/core/models --target django-security.xtarget --dest-file security.py \
@@ -34,16 +48,14 @@
 WORKDIR /opt/xos
 
 # Label image
-ARG org_label_schema_schema_version=1.0
-ARG org_label_schema_name=xos-core
 ARG org_label_schema_version=unknown
 ARG org_label_schema_vcs_url=unknown
 ARG org_label_schema_vcs_ref=unknown
 ARG org_label_schema_build_date=unknown
 ARG org_opencord_vcs_commit_date=unknown
 
-LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
-      org.label-schema.name=$org_label_schema_name \
+LABEL org.label-schema.schema-version=1.0 \
+      org.label-schema.name=xos-core \
       org.label-schema.version=$org_label_schema_version \
       org.label-schema.vcs-url=$org_label_schema_vcs_url \
       org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
diff --git a/Makefile b/Makefile
index c1f9032..08299be 100644
--- a/Makefile
+++ b/Makefile
@@ -18,26 +18,78 @@
 SHELL = bash -e -o pipefail
 
 # Variables
-XOS_LIBRARIES := $(wildcard lib/*)
-XOS_DIR := "."
+VERSION                  ?= $(shell cat ./VERSION)
+CORE_NAME                ?= xos-core
+CLIENT_NAME              ?= xos-client
 
+## Testing related
+XOS_LIBRARIES            := $(wildcard lib/*)
+
+## Docker related
+DOCKER_REGISTRY          ?=
+DOCKER_REPOSITORY        ?=
+DOCKER_BUILD_ARGS        ?=
+DOCKER_TAG               ?= ${VERSION}
+CORE_IMAGENAME           := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CORE_NAME}:${DOCKER_TAG}
+CLIENT_IMAGENAME         := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CLIENT_NAME}:${DOCKER_TAG}
+
+## Docker labels. Only set ref and commit date if committed
+DOCKER_LABEL_VCS_URL     ?= $(shell git remote get-url $(shell git remote))
+DOCKER_LABEL_VCS_REF     ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
+DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
+DOCKER_LABEL_BUILD_DATE  ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
+
+# Targets
+all: test
+
+## Docker targets
+docker-build:
+	docker build $(DOCKER_BUILD_ARGS) \
+    -t ${CORE_IMAGENAME} \
+    --build-arg org_label_schema_version="${VERSION}" \
+    --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+    --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+    --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+    --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+    -f Dockerfile.core .
+	docker build $(DOCKER_BUILD_ARGS) \
+    -t ${CLIENT_IMAGENAME} \
+    --build-arg org_label_schema_version="${VERSION}" \
+    --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+    --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+    --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+    --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+    -f Dockerfile.client .
+
+docker-push:
+	docker push ${CORE_IMAGENAME}
+	docker push ${CLIENT_IMAGENAME}
+
+# Create a virtualenv and install all the libraries
 venv-xos:
-	./scripts/setup_venv.sh
+	virtualenv $@;\
+    source ./$@/bin/activate ; set -u ;\
+    pip install -r requirements.txt nose2 mock requests_mock;\
+    pip install -e lib/xos-util ;\
+    pip install -e lib/xos-config ;\
+    pip install -e lib/xos-genx ;\
+    pip install -e lib/xos-kafka ;\
+    pip install -e lib/xos-api ;\
+    pip install -e lib/xos-synchronizer ;\
+    pip install -e lib/xos-migrate
 
 # tests
-test: lib-test xos-test migration-test core-xproto-test
+test: lib-test unit-test migration-test core-xproto-test
 
 lib-test:
 	for lib in $(XOS_LIBRARIES); do pushd $$lib; tox; popd; done
 
-xos-test: venv-xos
-	source ./venv-xos/bin/activate ; set -u ;\
-	nose2 -c tox.ini --verbose --junit-xml
-	# FIXME: should run `flake8 xos` as a part of this target
+unit-test:
+	tox
 
 migration-test: venv-xos
 	source ./venv-xos/bin/activate ; set -u ;\
-	xos-migrate --xos-dir . -s core --check
+    xos-migrate --xos-dir . -s core --check
 
 create-migrations: venv-xos
 	source ./venv-xos/bin/activate ; set -u ;\
@@ -45,7 +97,7 @@
 
 core-xproto-test: venv-xos
 	source ./venv-xos/bin/activate ; set -u ;\
-	xosgenx xos/core/models/core.xproto --lint --strict
+    xosgenx xos/core/models/core.xproto --lint --strict
 
 clean:
 	find . -name '*.pyc' | xargs rm -f
diff --git a/VERSION b/VERSION
index be94e6f..b347b11 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.2.2
+3.2.3
diff --git a/containers/chameleon/Makefile b/containers/chameleon/Makefile
deleted file mode 100644
index 067ae91..0000000
--- a/containers/chameleon/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-# Docker container Makefile for XOS
-#
-# Targets:
-#
-#  `base`   - XOS prerequistie files, no XOS code, builds xosproject/xos-base
-#  `build`  - base + XOS code, git pulled in Dockerfile from main repo,
-#             builds xosproject/xos
-#  `custom` - base + XOS code, git pulled in Dockerfile from selectable repo,
-#             builds xosproject/xos
-#  `devel`  - base + XOS code from local directory, builds xosproject/xos
-#  `test`   - xosproject/xos + nodejs testing frameworks, builds
-#             xosproject/xos-test
-#
-
-NO_DOCKER_CACHE    ?= false
-
-CONTAINER_NAME     ?= chameleon
-IMAGE_NAME         ?= xosproject/chameleon
-
-XOS_GIT_REPO       ?= https://github.com/opencord/xos.git
-XOS_GIT_BRANCH     ?= master
-
-XOS_GIT_COMMIT_HASH     ?= $(shell git log --pretty=format:'%H' -n 1 || echo -n "unknown" )
-XOS_GIT_COMMIT_DATE     ?= $(shell git log --pretty=format:'%ad' -n 1 || echo -n "unknown" )
-
-BUILD_ARGS =
-ifdef http_proxy
-BUILD_ARGS += --build-arg http_proxy=${http_proxy}
-endif
-ifdef https_proxy
-BUILD_ARGS += --build-arg https_proxy=${https_proxy}
-endif
-
-chameleon:
-	rm -rf tmp.chameleon
-	cp -R /opt/cord/component/chameleon tmp.chameleon
-	sudo docker build --no-cache=${NO_DOCKER_CACHE} --rm \
-	-f Dockerfile.chameleon -t ${IMAGE_NAME} ${BUILD_ARGS} .
-	rm -rf tmp.chameleon
diff --git a/containers/chameleon/README.md b/containers/chameleon/README.md
deleted file mode 100644
index 9222a9e..0000000
--- a/containers/chameleon/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-This directory contains a dockerfile for building Chameleon for XOS use.
-
-Expect that shortly Chameleon will be pulled from Dockerhub rather than
-built locally, and that this Dockerfile may be left only as a convenience 
-for developers.
diff --git a/containers/xos/Dockerfile.base b/containers/xos/Dockerfile.base
deleted file mode 100644
index 811901b..0000000
--- a/containers/xos/Dockerfile.base
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Dockerfile.base
-# This image isn't used, but installs the prereqs for the other XOS images
-FROM ubuntu:16.04
-
-# Install apt packages, including docker
-RUN apt-get update && apt-get install -y \
-    apt-transport-https \
-    build-essential \
-    curl \
-    libpq-dev \
-    libyaml-dev \
-    openssh-client \
-    python-pip \
-    software-properties-common \
-    sshpass \
- && rm -rf /var/lib/apt/lists/* \
- && mkdir /var/xos \
- && pip freeze > /var/xos/pip_freeze_apt_`date -u +%Y%m%dT%H%M%S`
-
-# Install python packages with pip
-COPY requirements.txt /tmp/requirements.txt
-RUN pip install -U -I pip==9.0.3 setuptools==39.0.1 \
- && pip install -r /tmp/requirements.txt \
- && pip freeze > /var/xos/pip_freeze_base_`date -u +%Y%m%dT%H%M%S`
-
-# Label image
-ARG org_label_schema_schema_version=1.0
-ARG org_label_schema_name=xos-base
-ARG org_label_schema_version=unknown
-ARG org_label_schema_vcs_url=unknown
-ARG org_label_schema_vcs_ref=unknown
-ARG org_label_schema_build_date=unknown
-ARG org_opencord_vcs_commit_date=unknown
-
-LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
-      org.label-schema.name=$org_label_schema_name \
-      org.label-schema.version=$org_label_schema_version \
-      org.label-schema.vcs-url=$org_label_schema_vcs_url \
-      org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
-      org.label-schema.build-date=$org_label_schema_build_date \
-      org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date
-
diff --git a/containers/xos/Makefile b/containers/xos/Makefile
deleted file mode 100644
index e0ffca1..0000000
--- a/containers/xos/Makefile
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright 2017 the original author or authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# Container are build via the `make build` commands.
-
-# Optional parameters are:
-# `REGISTRY=192.168.99.100:3000/ REPOSITORY=xosproject/ DOCKER_BUILD_ARGS="--no-cache" TAG=dev make build`
-
-# Variables
-VERSION                  ?= $(shell cat ../../VERSION)
-
-## Docker related
-DOCKER_REGISTRY          ?=
-DOCKER_REPOSITORY        ?=
-DOCKER_BUILD_ARGS        ?=
-DOCKER_TAG               ?= ${VERSION}
-DOCKER_IMAGENAME_BASE    := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}xos-base:${DOCKER_TAG}
-DOCKER_IMAGENAME_LIBRARIES := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}xos-libraries:${DOCKER_TAG}
-DOCKER_IMAGENAME_CLIENT  := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}xos-client:${DOCKER_TAG}
-DOCKER_IMAGENAME_CORE    := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}xos-core:${DOCKER_TAG}
-DOCKER_IMAGENAME_SYNC    := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}xos-synchronizer-base:${DOCKER_TAG}
-
-summary:
-	@echo Building images with:
-	@echo "    Build args:    $(DOCKER_BUILD_ARGS)"
-	@echo "    Registry:      ${DOCKER_REGISTRY}"
-	@echo "    Repository:    ${DOCKER_REPOSITORY}"
-	@echo "    Tag:           ${DOCKER_TAG}"
-
-build: summary xos-base xos-libraries xos-client xos-core xos-synchronizer-base
-
-xos-base:
-	docker build $(DOCKER_BUILD_ARGS) -t ${DOCKER_IMAGENAME_BASE} -f Dockerfile.base .
-
-xos-libraries:
-	docker build --no-cache $(DOCKER_BUILD_ARGS) -t ${DOCKER_IMAGENAME_LIBRARIES} -f Dockerfile.libraries ../..
-
-xos-client:
-	docker build --no-cache $(DOCKER_BUILD_ARGS) -t ${DOCKER_IMAGENAME_CLIENT} -f Dockerfile.client ../..
-
-xos-core:
-	docker build --no-cache $(DOCKER_BUILD_ARGS) -t ${DOCKER_IMAGENAME_CORE} -f Dockerfile.xos-core ../..
-
-xos-synchronizer-base:
-	docker build --no-cache $(DOCKER_BUILD_ARGS) -t ${DOCKER_IMAGENAME_SYNC} -f Dockerfile.synchronizer-base ../..
diff --git a/containers/xos/ansible-hosts b/containers/xos/ansible-hosts
deleted file mode 100644
index 75304a0..0000000
--- a/containers/xos/ansible-hosts
+++ /dev/null
@@ -1,2 +0,0 @@
-[localhost]
-localhost ansible_connection=local
diff --git a/containers/xos/requirements.txt b/containers/xos/requirements.txt
deleted file mode 100644
index 64fec10..0000000
--- a/containers/xos/requirements.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-Django~=1.11.20
-confluent-kafka==0.11.5
-django-extensions~=2.1.6
-django-timezones~=0.2
-djangorestframework~=3.9.1
-functools32~=3.2.3-2
-futures~=3.2.0
-kafkaloghandler~=0.9.0
-multistructlog~=2.1.0
-prometheus_client~=0.6.0
-psycopg2-binary~=2.7.7
-pytz~=2018.9
-semver~=2.8.1
-tosca-parser~=1.4.0
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..3478295
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,8 @@
+Django~=1.11.20
+django-extensions~=2.1.6
+django-timezones~=0.2
+djangorestframework~=3.9.2
+prometheus_client~=0.6.0
+psycopg2-binary~=2.8.2
+pytz~=2019.1
+semver~=2.8.1
diff --git a/scripts/setup_venv.sh b/scripts/setup_venv.sh
deleted file mode 100755
index ac912aa..0000000
--- a/scripts/setup_venv.sh
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# setup_venv_lite.sh
-# sets up a python virtualenv for testing and service development
-
-set -e -o pipefail
-
-WORKSPACE=${WORKSPACE:-.}
-XOS_DIR=${XOS_DIR:-.}
-PIP_REQS=${PIP_REQS:-${XOS_DIR}/containers/xos/requirements.txt}
-VENVDIR="${WORKSPACE}/venv-xos"
-
-# create venv if it's not yet there
-if [ ! -x "${VENVDIR}/bin/activate" ]; then
-  echo "Setting up dev/test virtualenv in ${VENVDIR} for XOS"
-  virtualenv -q "${VENVDIR}" --no-site-packages
-  echo "Virtualenv created."
-fi
-
-echo "Installing python requirements in virtualenv with pip"
-source "${VENVDIR}/bin/activate"
-pip install --upgrade pip
-pip install -r "$PIP_REQS" nose2 mock requests_mock
-
-pushd "$XOS_DIR/lib/xos-util"
-python setup.py install
-echo "xos-util Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-config"
-python setup.py install
-echo "xos-config Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-genx"
-python setup.py install
-echo "xos-genx Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-kafka"
-python setup.py install
-echo "xos-kafka Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-api"
-python setup.py install
-echo "xos-api Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-synchronizer"
-python ./setup.py install
-echo "xos-synchronizer Installed"
-popd
-
-pushd "$XOS_DIR/lib/xos-migrate"
-python ./setup.py install
-echo "xos-migrate Installed"
-popd
-
-
-echo "XOS dev/test virtualenv created. Run 'source ${VENVDIR}/bin/activate'."
diff --git a/tox.ini b/tox.ini
index ea5235b..7152507 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,9 +14,26 @@
 
 ; using tox.ini only to store config information for other tools
 
+[tox]
+envlist = py27
+# add to envlist when py3 compat is done py35,py36,py37
+skip_missing_interpreters = true
+skipsdist = True
+
+[testenv]
+deps =
+  -r requirements.txt
+  -e lib/xos-config
+  -e lib/xos-genx
+  multistructlog
+  nose2
+  flake8
+
+commands =
+  nose2 -c tox.ini --verbose --junit-xml
+#  flake8
+
 [flake8]
-; W503, allow breaks before binary operators (see: https://github.com/PyCQA/pycodestyle/issues/498)
-ignore = W503
 max-line-length = 119
 
 [unittest]
@@ -29,7 +46,8 @@
 
 [coverage]
 always-on = True
-coverage = xos
+coverage =
+  xos
 coverage-report =
   term
   xml