summaryrefslogtreecommitdiffstats
path: root/jjb/releng/opnfv-docker.sh
diff options
context:
space:
mode:
authorwutianwei <wutianwei1@huawei.com>2017-11-16 17:27:59 +0800
committerwutianwei <wutianwei1@huawei.com>2017-11-21 10:07:33 +0800
commitf8314a3e76bd4aac1ada4a174b7468f3604f86ea (patch)
treefa6539a917e33a8a6e9151b01089aecab4c9a406 /jjb/releng/opnfv-docker.sh
parent4245897311f394b2d4805337d85f28c0988320ae (diff)
compass: Build Docker images with jjb
JIRA: COMPASS-567 Add compass4nfv-docker.yml compass-tasks-k8s and compass-tasks-osa are dependent on compass-compass-tasks. So we have to phase to build docker images phase 1. execute the multijob 'build compass-tasks images' Only the phase 1 is successful then excute the phase 2 phase 2. execute the multijob 'build all compass images' Modify the opnfv-docker.sh 1. Add a function remove_containers_images 2. call the remove_containers_images when beginning and finishing build to solve the problem of rmove of images due to dependancy Change-Id: I66fb27260cf114da96417361e80c8183db3233bd Signed-off-by: wutianwei <wutianwei1@huawei.com>
Diffstat (limited to 'jjb/releng/opnfv-docker.sh')
-rw-r--r--jjb/releng/opnfv-docker.sh60
1 files changed, 35 insertions, 25 deletions
diff --git a/jjb/releng/opnfv-docker.sh b/jjb/releng/opnfv-docker.sh
index c179b1d8e..ec7b3fda3 100644
--- a/jjb/releng/opnfv-docker.sh
+++ b/jjb/releng/opnfv-docker.sh
@@ -17,6 +17,36 @@ echo "Starting opnfv-docker for $DOCKER_REPO_NAME ..."
echo "--------------------------------------------------------"
echo
+function remove_containers_images()
+{
+ # Remove previous running containers if exist
+ if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
+ echo "Removing existing $DOCKER_REPO_NAME containers..."
+ docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
+ t=60
+ # Wait max 60 sec for containers to be removed
+ while [[ $t -gt 0 ]] && [[ -n "$(docker ps| grep $DOCKER_REPO_NAME)" ]]; do
+ sleep 1
+ let t=t-1
+ done
+ fi
+
+
+ # Remove existing images if exist
+ if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
+ echo "Docker images to remove:"
+ docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
+ image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
+ for id in "${image_ids[@]}"; do
+ if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
+ echo "Removing docker image $DOCKER_REPO_NAME:$id..."
+ docker rmi -f $id
+ fi
+ done
+ fi
+}
+
+
count=30 # docker build jobs might take up to ~30 min
while [[ -n `ps -ef| grep 'docker build' | grep $DOCKER_REPO_NAME | grep -v grep` ]]; do
echo "Build or cleanup of $DOCKER_REPO_NAME in progress. Waiting..."
@@ -28,31 +58,8 @@ while [[ -n `ps -ef| grep 'docker build' | grep $DOCKER_REPO_NAME | grep -v grep
fi
done
-# Remove previous running containers if exist
-if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
- echo "Removing existing $DOCKER_REPO_NAME containers..."
- docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
- t=60
- # Wait max 60 sec for containers to be removed
- while [[ $t -gt 0 ]] && [[ -n "$(docker ps| grep $DOCKER_REPO_NAME)" ]]; do
- sleep 1
- let t=t-1
- done
-fi
-
-
-# Remove existing images if exist
-if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
- echo "Docker images to remove:"
- docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
- image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
- for id in "${image_ids[@]}"; do
- if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
- echo "Removing docker image $DOCKER_REPO_NAME:$id..."
- docker rmi -f $id
- fi
- done
-fi
+# Remove the existing containers and images before building
+remove_containers_images
cd "$WORKSPACE/$DOCKER_DIR" || exit 1
HOST_ARCH="$(uname -m)"
@@ -117,3 +124,6 @@ if [[ "$PUSH_IMAGE" == "true" ]]; then
echo
docker push $DOCKER_REPO_NAME:$DOCKER_TAG
fi
+
+# Remove the existing containers and images after building
+remove_containers_images