From 12ca05299dea13c62952048e50a17d1ca354e328 Mon Sep 17 00:00:00 2001 From: Erich Cordoba Date: Tue, 19 Feb 2019 10:14:25 -0600 Subject: [PATCH] Move docker creation and deletion to tb.sh A makefile was used only for creation and clean up of the docker image for building. In this process, all the environment variables were sourced and included into the Makefile. However this can fail on systems that has functions and cause a failing makefile. Trying to fixing this issue I realize that this Makefile ain't needed, as all the logic for docker management is under `tb.sh`, therefore makes sense to remove this Makefile and use this script for the entire process. Story: 2002560 Change-Id: I2795593521a5d16dc2033861946fd09c2270424e Signed-off-by: Erich Cordoba --- Makefile | 44 -------------------------------------------- README.rst | 4 ++-- tb.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 48 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index c4ebff49..00000000 --- a/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -# TC Build container - -# Set defaults that may be overridden in the buidrc -MY_TC_RELEASE := tis-r5-pike - -UID := $(shell id -u) -USER := $(shell id -un) - -# Import the build config -NULL := $(shell bash -c "source buildrc; set | sed -E '/^[[:alnum:]_]+/s/=/:=/' | sed 's/^//' > .makeenv") -include .makeenv - -MYUNAME ?= $(USER) - -TC_CONTAINER_NAME := $(MYUNAME)-centos-builder -TC_CONTAINER_TAG := local/$(MYUNAME)-stx-builder:7.4 -TC_DOCKERFILE := Dockerfile - -all: - docker build \ - --build-arg MYUID=$(UID) \ - --build-arg MYUNAME=$(MYUNAME) \ - --ulimit core=0 \ - --network host \ - -t $(TC_CONTAINER_TAG) \ - -f $(TC_DOCKERFILE) \ - . - -clean: - docker rm $(TC_CONTAINER_NAME) || true - docker image rm $(TC_CONTAINER_TAG) - -env: - @echo "TC_DOCKERFILE=$(TC_DOCKERFILE)" - @echo "TC_CONTAINER_NAME=$(TC_CONTAINER_NAME)" - @echo "TC_CONTAINER_TAG=$(TC_CONTAINER_TAG)" - @echo "SOURCE_REMOTE_NAME=$(SOURCE_REMOTE_NAME)" - @echo "SOURCE_REMOTE_URI=$(SOURCE_REMOTE_URI)" - @echo "HOST_MIRROR_DIR=$(HOST_MIRROR_DIR)" - @echo "MY_TC_RELEASE=$(MY_TC_RELEASE)" - @echo "LOCALDISK=${LOCALDISK}" - @echo "GUEST_LOCALDISK=${GUEST_LOCALDISK}" - -.PHONY: all clean env diff --git a/README.rst b/README.rst index ea298fe0..f8651023 100644 --- a/README.rst +++ b/README.rst @@ -54,11 +54,11 @@ Build image ~~~~~~~~~~~ Once the configuration files have been customized, it is possible to build -the docker image. This process is automated by the Makefile. +the docker image. This process is automated by the ``tb.sh`` script. .. code-block:: bash - make + ./tb.sh create NOTE: ~~~~~ diff --git a/tb.sh b/tb.sh index e0508dd3..90ce3cae 100755 --- a/tb.sh +++ b/tb.sh @@ -25,6 +25,17 @@ TC_CONTAINER_NAME=${MYUNAME}-centos-builder TC_CONTAINER_TAG=local/${MYUNAME}-stx-builder:7.4 TC_DOCKERFILE=Dockerfile +function create_container { + docker build \ + --build-arg MYUID=$(id -u) \ + --build-arg MYUNAME=${USER} \ + --ulimit core=0 \ + --network host \ + -t ${TC_CONTAINER_TAG} \ + -f ${TC_DOCKERFILE} \ + . +} + function exec_container { docker cp ${WORK_DIR}/buildrc ${TC_CONTAINER_NAME}:/home/${MYUNAME} docker cp ${WORK_DIR}/localrc ${TC_CONTAINER_NAME}:/home/${MYUNAME} @@ -57,8 +68,13 @@ function kill_container { docker kill ${TC_CONTAINER_NAME} } +function clean_container { + docker rm ${TC_CONTAINER_NAME} || true + docker image rm ${TC_CONTAINER_TAG} +} + function usage { - echo "$0 [run|exec|env|stop|kill]" + echo "$0 [create|run|exec|env|stop|kill|clean]" } case $CMD in @@ -74,6 +90,9 @@ case $CMD in echo "MY_TC_RELEASE=${MY_TC_RELEASE}" echo "MY_REPO_ROOT_DIR=${MY_REPO_ROOT_DIR}" ;; + create) + create_container + ;; exec) exec_container ;; @@ -86,9 +105,12 @@ case $CMD in kill) kill_container ;; + clean) + clean_container + ;; *) echo "Unknown command: $CMD" - usage + usage exit 1 ;; esac