Skip to content

Commit

Permalink
[CE-214] Improve service provision process
Browse files Browse the repository at this point in the history
* 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 <yangbaohua@gmail.com>
  • Loading branch information
yeasy committed Jan 9, 2018
1 parent fc5418f commit d7ffeb2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
63 changes: 42 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -72,8 +91,6 @@ ifneq (${THEME}, basic)
endif
endif
START_OPTIONS = initial-env $(BUILD_JS)
else
START_OPTIONS = initial-env
endif


Expand All @@ -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
Expand Down Expand Up @@ -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"; }

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions scripts/master_node/download_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/master_node/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} ] \
Expand Down

0 comments on commit d7ffeb2

Please sign in to comment.