From d7ffeb208d139b653f31393d8f10a8d206c6c38c Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Mon, 8 Jan 2018 14:05:54 +0800 Subject: [PATCH] [CE-214] Improve service provision process * Refine the makefile and add more comments; * Detect docker image existence before rebuilding; * Enable pulling images from dockerhub. Change-Id: I66177fdf2499639433737bd0f0f0e7ae0293f525 Signed-off-by: Baohua Yang --- Makefile | 63 +++++++++++++++++--------- docker-compose.yml | 1 + scripts/master_node/download_images.sh | 17 ++++--- scripts/master_node/setup.sh | 4 +- 4 files changed, 56 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index a1c09482..95bda09d 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,22 @@ # # SPDX-License-Identifier: Apache-2.0 # +# +# ------------------------------------------------------------- +# This makefile defines the following targets +# +# - all (default): Builds all targets and runs all tests/checks +# - checks: Runs all tests/checks, will be triggered by CI +# - clean: Cleans the build area +# - doc: Start a local web service to explore the documentation +# - docker[-clean]: Ensures all docker images are available[/cleaned] +# - help: Output the help instructions for each command +# - log: Check the recent log output of all services +# - restart: Stop the cello service and then start +# - setup-master: Setup the host as a master node +# - setup-worker: Setup the host as a worker node +# - start: Start the cello service +# - stop: Stop the cello service, and remove all service containers GREEN := $(shell tput -Txterm setaf 2) WHITE := $(shell tput -Txterm setaf 7) @@ -24,18 +40,19 @@ DOCKER_BASE_s390x=s390x/debian:jessie DOCKER_BASE=$(DOCKER_BASE_$(ARCH)) BASE_VERSION ?= $(ARCH)-$(VERSION) -ifneq ($(IS_RELEASE),true) +ifeq ($(IS_RELEASE),false) EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD) - DOCKER_TAG=$(BASE_VERSION)-$(EXTRA_VERSION) + IMG_TAG=$(BASE_VERSION)-$(EXTRA_VERSION) else - DOCKER_TAG=$(BASE_VERSION) + IMG_TAG=$(BASE_VERSION) endif +# Docker images needed to run cello services DOCKER_IMAGES = baseimage mongo nginx -DUMMY = .$(DOCKER_TAG) +DUMMY = .$(IMG_TAG) ifeq ($(DOCKER_BASE), ) -$(error "Architecture \"$(ARCH)\" is unsupported") + $(error "Architecture \"$(ARCH)\" is unsupported") endif # Frontend needed @@ -57,8 +74,10 @@ else SED = sed -i endif -ifneq (${THEME}, basic) - ifeq (${THEME}, react) +ifeq (${THEME}, basic) # basic theme doesn't need js compiling + START_OPTIONS = initial-env +else + ifeq (${THEME}, react) # react needs compiling js first ifneq ($(wildcard ./src/${STATIC_FOLDER}/js/dist),) BUILD_JS= else @@ -72,8 +91,6 @@ ifneq (${THEME}, basic) endif endif START_OPTIONS = initial-env $(BUILD_JS) -else - START_OPTIONS = initial-env endif @@ -85,31 +102,35 @@ build/docker/mongo/$(DUMMY): build/docker/mongo/$(DUMMY) build/docker/%/$(DUMMY): $(eval TARGET = ${patsubst build/docker/%/$(DUMMY),%,${@}}) - $(eval DOCKER_NAME = $(BASENAME)-$(TARGET)) + $(eval IMG_NAME = $(BASENAME)-$(TARGET)) @mkdir -p $(@D) @echo "Building docker $(TARGET)" @cat config/$(TARGET)/Dockerfile.in \ | sed -e 's|_DOCKER_BASE_|$(DOCKER_BASE)|g' \ | sed -e 's|_NS_|$(DOCKER_NS)|g' \ - | sed -e 's|_TAG_|$(DOCKER_TAG)|g' \ + | sed -e 's|_TAG_|$(IMG_TAG)|g' \ > $(@D)/Dockerfile - docker build -f $(@D)/Dockerfile \ - -t $(DOCKER_NAME) \ - -t $(DOCKER_NAME):$(DOCKER_TAG) \ - . + if [ "$$(docker images -q $(IMG_NAME) 2> /dev/null)" == "" ]; then \ + docker build -f $(@D)/Dockerfile \ + -t $(IMG_NAME) \ + -t $(IMG_NAME):$(IMG_TAG) \ + . ; \ + fi @touch $@ build/docker/%/.push: build/docker/%/$(DUMMY) @docker login \ --username=$(DOCKER_HUB_USERNAME) \ --password=$(DOCKER_HUB_PASSWORD) - @docker push $(BASENAME)-$(patsubst build/docker/%/.push,%,$@):$(DOCKER_TAG) + @docker push $(BASENAME)-$(patsubst build/docker/%/.push,%,$@):$(IMG_TAG) docker: $(patsubst %,build/docker/%/$(DUMMY),$(DOCKER_IMAGES)) +docker-clean: image-clean ##@Clean all existing images + install: $(patsubst %,build/docker/%/.push,$(DOCKER_IMAGES)) -check: docker ##@Code Check code format +check: setup-master ##@Code Check code format tox @$(MAKE) test-case make start && sleep 10 && make stop @@ -203,10 +224,10 @@ HELP_FUN = \ while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \ print "usage: make [target]\n\n"; \ for (sort keys %help) { \ - print "${WHITE}$$_:${RESET}\n"; \ - for (@{$$help{$$_}}) { \ - $$sep = " " x (32 - length $$_->[0]); \ - print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \ + print "${WHITE}$$_:${RESET}\n"; \ + for (@{$$help{$$_}}) { \ + $$sep = " " x (32 - length $$_->[0]); \ + print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \ }; \ print "\n"; } diff --git a/docker-compose.yml b/docker-compose.yml index 3bbca9ec..98b2fbf2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -119,6 +119,7 @@ services: - USERNAME=admin - PASSWORD=pass + #TODO: need to follow other images to put at dockerhub user-dashboard: build: context: user-dashboard diff --git a/scripts/master_node/download_images.sh b/scripts/master_node/download_images.sh index 54caceb7..fedb7d96 100644 --- a/scripts/master_node/download_images.sh +++ b/scripts/master_node/download_images.sh @@ -23,10 +23,15 @@ else } fi -echo_b "This script will setup the docker images for master node" -echo_b "Pull python:3.5, mongo:3.2, mongo-express:0.30(optional for debugging) and yeasy/nginx" +echo_b "Downloading the docker images for master node" -docker pull python:3.5 \ - && docker pull mongo:3.2 \ - && docker pull mongo-express:0.30 \ - && docker pull yeasy/nginx:latest + +ARCH=$(uname -m) + +docker pull node:9.2 \ + && docker pull hyperledger/cello-baseimage:${ARCH}-latest \ + && docker pull hyperledger/cello-mongo:${ARCH}-latest \ + && docker pull hyperledger/cello-nginx:${ARCH}-latest \ + && docker tag hyperledger/cello-baseimage:${ARCH}-latest hyperledger/cello-baseimage \ + && docker tag hyperledger/cello-mongo:${ARCH}-latest hyperledger/cello-mongo \ + && docker tag hyperledger/cello-nginx:${ARCH}-latest hyperledger/cello-nginx diff --git a/scripts/master_node/setup.sh b/scripts/master_node/setup.sh index e8a9647c..f6a80fd9 100755 --- a/scripts/master_node/setup.sh +++ b/scripts/master_node/setup.sh @@ -105,8 +105,8 @@ command -v docker-compose >/dev/null 2>&1 || { echo_r >&2 "No docker-compose fou [ `sudo docker ps -qa|wc -l` -gt 0 ] \ && echo_r "Warn: existing containers may cause unpredictable failure, suggest to clean them using docker rm" -echo_b "Download dependent Images..." -#bash ./download_images.sh +echo_b "Download required Docker images..." +bash ./download_images.sh echo_b "Checking local mounted database path ${DB_DIR}..." [ ! -d ${DB_DIR} ] \