[AETHER-421] Enabling onos build

CI/CD jobs will build locally a new onos image from onos-2.2
using the "tost" profile. This image tagged as "tost-onos" will be
used as initial stage for "tost" image.

Deprecate tost-onos:2.2-latest

Do not activate apps during the build process

Change-Id: I8efb93f3c99344822c74f277c52bba8adbc61dba
diff --git a/Dockerfile.tost b/Dockerfile.tost
index e191a9d..c4ecc44 100644
--- a/Dockerfile.tost
+++ b/Dockerfile.tost
@@ -16,7 +16,7 @@
 
 # We start from an onos image and install the apps.
 # We need at least an onos image built with 'tost' profile
-FROM onosproject/tost-onos:2.2-latest as install
+FROM tost-onos as install
 
 ARG KARAF_VERSION
 ARG LOCAL_APPS
@@ -45,7 +45,7 @@
 RUN ./app-install.sh
 
 # Create the final image coping over the installed applications from the install stage
-FROM onosproject/tost-onos:2.2-latest
+FROM tost-onos
 
 ARG KARAF_VERSION
 
diff --git a/Makefile b/Makefile
index c7f867f..84ef0df 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,8 @@
 MKFILE_PATH              := $(abspath $(lastword $(MAKEFILE_LIST)))
 CURRENT_DIR              := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
 LOCAL_APPS               := local-apps
+# Do not attach stdin if running in an environment without it (e.g., Jenkins)
+IT                       := $(shell test -t 0 && echo "-it" || echo "-t")
 
 # Docker related
 DOCKER_REGISTRY          ?=
@@ -45,9 +47,7 @@
 endif
 
 # ONOS related
-ONOS_VERSION                 ?= $(shell cat ./ONOS_VERSION)
-ONOS_DOCKER_TAG              ?= ${ONOS_VERSION}
-ONOS_IMAGENAME               := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost-onos:${ONOS_DOCKER_TAG}
+ONOS_IMAGENAME               := tost-onos
 ONOS_BRANCH                  ?=
 ONOS_REVIEW                  ?=
 export ONOS_ROOT             := $(shell pwd)/onos
@@ -141,22 +141,22 @@
 	| sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
 	@echo
 	@echo "Environment variables:"
-	@echo "ONOS_BRANCH              : Define to use the following branch to build the image"
-	@echo "ONOS_REVIEW              : Define to use the following review to build the image"
-	@echo "TRELLIS_CONTROL_BRANCH   : Define to use the following branch to build the image"
-	@echo "TRELLIS_CONTROL_REVIEW   : Define to use the following review to build the image"
-	@echo "TRELLIS_CONTROL_MVN      : Define to download the app using mvn"
-	@echo "TRELLIS_T3_BRANCH        : Define to use the following branch to build the image"
-	@echo "TRELLIS_T3_REVIEW        : Define to use the following review to build the image"
-	@echo "TRELLIS_T3_MVN           : Define to download the app using mvn"
-	@echo "FABRIC_TOFINO_BRANCH     : Define to use the following branch to build the image"
-	@echo "FABRIC_TOFINO_REVIEW     : Define to use the following review to build the image"
-	@echo "FABRIC_TOFINO_MVN        : Define to download the app using mvn"
-	@echo "UP4_BRANCH               : Define to use the following branch to build the image"
-	@echo "KAFKA_ONOS_BRANCH        : Define to use the following branch to build the image"
-	@echo "KAFKA_ONOS_REVIEW        : Define to use the following review to build the image"
-	@echo "KAFKA_ONOS_MVN           : Define to download the app using mvn"
-	@echo "FABRIC_TNA_BRANCH        : Define to use the following branch to build the image"
+	@echo "ONOS_BRANCH               : Define to use the following branch to build the image"
+	@echo "ONOS_REVIEW               : Define to use the following review to build the image"
+	@echo "TRELLIS_CONTROL_BRANCH    : Define to use the following branch to build the image"
+	@echo "TRELLIS_CONTROL_REVIEW    : Define to use the following review to build the image"
+	@echo "TRELLIS_CONTROL_MVN       : Define to download the app using mvn"
+	@echo "TRELLIS_T3_BRANCH         : Define to use the following branch to build the image"
+	@echo "TRELLIS_T3_REVIEW         : Define to use the following review to build the image"
+	@echo "TRELLIS_T3_MVN            : Define to download the app using mvn"
+	@echo "FABRIC_TOFINO_BRANCH      : Define to use the following branch to build the image"
+	@echo "FABRIC_TOFINO_REVIEW      : Define to use the following review to build the image"
+	@echo "FABRIC_TOFINO_MVN         : Define to download the app using mvn"
+	@echo "UP4_BRANCH                : Define to use the following branch to build the image"
+	@echo "KAFKA_ONOS_BRANCH         : Define to use the following branch to build the image"
+	@echo "KAFKA_ONOS_REVIEW         : Define to use the following review to build the image"
+	@echo "KAFKA_ONOS_MVN            : Define to download the app using mvn"
+	@echo "FABRIC_TNA_BRANCH         : Define to use the following branch to build the image"
 	@echo ""
 	@echo "'onos' clones onos if it does not exist in the workspace."
 	@echo "Uses current workspace unless above vars are defined."
@@ -214,7 +214,7 @@
 	# Dependencies are needed only by the mvn copy - contains repo settings
 	cp dependencies.xml ${TRELLIS_CONTROL_ROOT}/
 	# Mounting the current dir allows to cache the .m2 folder that is persisted and leveraged by subsequent builds
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn dependency:copy -Dartifact=${TRELLIS_CONTROL_ARTIFACT}:${TRELLIS_CONTROL_VERSION}:oar \
 		-DoutputDirectory=oar/target -Dmdep.useBaseVersion=true \
 		-Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
@@ -222,7 +222,7 @@
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 else
 	# Having the same mount file allows to reduce build time.
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 endif
@@ -250,14 +250,14 @@
 	cp mvn_settings.xml ${TRELLIS_T3_ROOT}/
 ifdef TRELLIS_T3_MVN
 	cp dependencies.xml ${TRELLIS_T3_ROOT}/
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn dependency:copy -Dartifact=${TRELLIS_T3_ARTIFACT}:${TRELLIS_T3_VERSION}:oar \
 		-DoutputDirectory=app/target -Dmdep.useBaseVersion=true \
 		-Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
 		-s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 else
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 endif
@@ -284,7 +284,7 @@
 	cp mvn_settings.xml ${FABRIC_TOFINO_ROOT}/
 ifdef FABRIC_TOFINO_MVN
 	cp dependencies.xml ${FABRIC_TOFINO_ROOT}/
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn dependency:copy -Dartifact=${FABRIC_TOFINO_ARTIFACT}:${FABRIC_TOFINO_VERSION}:oar \
 		-DoutputDirectory=target -Dmdep.useBaseVersion=true \
 		-Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
@@ -294,7 +294,7 @@
 	# This workaround is temporary - typically we need to build only the pipeconf
 	cd ${FABRIC_TOFINO_ROOT} && make ${FABRIC_TOFINO_TARGETS} SDE_DOCKER_IMG=${FABRIC_TOFINO_SDE_DOCKER_IMG} \
 		P4CFLAGS=${FABRIC_TOFINO_P4CFLAGS}
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 endif
@@ -312,7 +312,7 @@
 	cp mvn_settings.xml ${UP4_ROOT}/app
 	# Copy the p4 reources inside the app before the actual build
 	cd ${UP4_ROOT} && make ${UP4_TARGETS}
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/up4/app ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/up4/app ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 	cp ${UP4_ROOT}/app/app/target/${UP4_ARTIFACTID}-${UP4_VERSION}.oar ${LOCAL_APPS}/
@@ -338,14 +338,14 @@
 	cp mvn_settings.xml ${KAFKA_ONOS_ROOT}/
 ifdef KAFKA_ONOS_MVN
 	cp dependencies.xml ${KAFKA_ONOS_ROOT}/
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn dependency:copy -Dartifact=${KAFKA_ONOS_ARTIFACT}:${KAFKA_ONOS_VERSION}:oar \
 		-DoutputDirectory=target -Dmdep.useBaseVersion=true \
 		-Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
 		-s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 else
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 endif
@@ -363,7 +363,7 @@
 	cp mvn_settings.xml ${FABRIC_TNA_ROOT}/
 	# Rebuilds the artifact and the pipeconf
 	cd ${FABRIC_TNA_ROOT} && make ${FABRIC_TNA_TARGETS} SDE_DOCKER_IMG=${FABRIC_TNA_SDE_DOCKER_IMG}
-	docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tna ${DOCKER_MVN_IMAGE} \
+	docker run ${IT} --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tna ${DOCKER_MVN_IMAGE} \
 		bash -c "mvn clean install -s mvn_settings.xml; \
 		chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
 	cp ${FABRIC_TNA_ROOT}/target/${FABRIC_TNA_ARTIFACTID}-${FABRIC_TNA_VERSION}.oar ${LOCAL_APPS}/
@@ -385,6 +385,8 @@
 endif
 endif
 
+apps-build: trellis-control-build trellis-t3-build fabric-tofino-build up4-build kafka-onos-build fabric-tna-build ## : Build the onos apps
+
 onos-build: onos ## : Builds the tost-onos docker image
 	# Set some env variables
 	cd ${ONOS_ROOT} && \
@@ -411,7 +413,7 @@
 	docker push ${TOST_IMAGENAME}
 
 # Used for CI job
-docker-build: onos trellis-control-build trellis-t3-build fabric-tofino-build up4-build kafka-onos-build fabric-tna-build tost-build ## : Builds the tost image
+docker-build: onos-build apps-build tost-build ## : Builds the tost image
 
 # User for CD job
 docker-push: tost-push ## : Pushes the tost image
diff --git a/ONOS_VERSION b/ONOS_VERSION
deleted file mode 100644
index 877c2bd..0000000
--- a/ONOS_VERSION
+++ /dev/null
@@ -1 +0,0 @@
-2.2-latest
diff --git a/README.md b/README.md
index 6c1a1ba..32f40df 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@
 make ONOS_REVIEW=12345 onos-build
 ```
 
-Makefile will build also the apps. These are the apps currently integrated in the script: **trellis-control**, **trellis-t3**, **fabric-tofino**, **up4** and **kafka-onos**. For each one, there is a **build** target.
+Makefile will build also the apps. These are the apps currently integrated in the script: **trellis-control**, **trellis-t3**, **fabric-tofino**, **up4**, **kafka-onos** and **fabric-tna**. For each one, there is a **build** target.
 
 `app-name-build` builds the oar from the source code. If **APPNAME_MVN** is specified, the script will download the oar from the maven repositories. As prerequisite, the script prepares `mvn_settings.xml` file, creates the `local-apps` folder and checks out the code if it is not present (relies on `app-name` target). `app-name` allows the developers to specify an **APPNAME_BRANCH** or an **APPNAME_REVIEW**.
 
@@ -37,6 +37,13 @@
 make up4-build
 ```
 
+`apps-build` is an additional target that automates the build process of the apps building one by one all the apps.
+
+```sh
+# Build one by one all the apps
+make apps-build
+```
+
 Finally, the last build target is `tost-build`. It builds a `tost` monolithic image using as base the `tost-onos` image. It basically adds the external apps used by **TOST**. It does not activate all the required apps. This step is performed during the deployment and the required apps are specified in the chart.
 
 ```sh
@@ -57,10 +64,10 @@
 
 We provide multiple push target for the Makefile. Typically, you need to first login by `docker login` command to push the image on a repository.
 
-`onos-push` will push the `tost-onos` image on the defined **DOCKER_REGISTRY** and **DOCKER_REPOSITORY**.
+`onos-push` will push the `tost-onos` image.
 
 ```sh
-make DOCKER_REPOSITORY=onosproject/ onos-push
+make onos-push
 ```
 
 `tost-push` will push the `tost` image on the defined **DOCKER_REGISTRY** and **DOCKER_REPOSITORY**.
@@ -71,4 +78,4 @@
 
 ## CI/CD targets
 
-There are two special targets used by the CI/CD jobs: `docker-build` and `docker-push`. The first target automates the build process of the `tost` image. While the second one, it is just a `tost-push` called in a different way (temporary). Feel free to use them if you are ok with the prerequisites steps.
+There are two special targets used by the CI/CD jobs: `docker-build` and `docker-push`. The first target automates the build process of the `tost` image (`onos-build`, `apps-build` and `tost-build`). While the second one, it is just a `tost-push` called in a different way (temporary). Feel free to use them if you are ok with the prerequisites steps.
diff --git a/app-install.sh b/app-install.sh
index 3cbfe15..502f545 100644
--- a/app-install.sh
+++ b/app-install.sh
@@ -28,7 +28,6 @@
     name=$(grep "name=" $APP_INSTALL_ROOT/app.xml | sed 's/<app name="//g;s/".*//g')
     mkdir -p $APPS_ROOT/$name
     cp $APP_INSTALL_ROOT/app.xml $APPS_ROOT/$name/app.xml
-    touch $APPS_ROOT/$name/active
     [ -f $APP_INSTALL_ROOT/app.png ] && cp $APP_INSTALL_ROOT/app.png $APPS_ROOT/$name/app.png
     cp $APP_INSTALL_ROOT/$(basename $oar) $APPS_ROOT/$name/$name.oar
     cp -rf $APP_INSTALL_ROOT/m2/* $KARAF_M2