Skip to content

Commit

Permalink
Fix [CE-170]
Browse files Browse the repository at this point in the history
Use platform specific xenial/jessie docker image and
build arch. specific hyperledger/cello-baseimage docker image

Change-Id: Ic62ef4bf5865d9c90e076313800ef2587e7b21b6
Signed-off-by: Krishna Harsha Voora <krishvoor@in.ibm.com>
  • Loading branch information
krishvoor committed Nov 26, 2017
1 parent 993c55f commit e9eb9f1
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 3 deletions.
55 changes: 52 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
ARCH := $(shell uname -m)

SLASH:=/
REPLACE_SLASH:=\/
Expand Down Expand Up @@ -49,7 +50,7 @@ endif

# changelog specific version tags
PREV_VERSION=0.6
BASE_VERSION=
#BASE_VERSION=

.PHONY: \
all \ # default to run check
Expand All @@ -66,8 +67,56 @@ BASE_VERSION=
start \ # start all services
restart \ # restart all services
stop \ # stop all services
docker \ # create docker image

DOCKER_NS ?= hyperledger
BASENAME ?= $(DOCKER_NS)/cello
VERSION ?= 0.7.0
IS_RELEASE=false

DOCKER_BASE_x86_64=ubuntu:xenial
DOCKER_BASE_ppc64le=ppc64le/ubuntu:xenial
DOCKER_BASE_s390x=s390x/debian:jessie
DOCKER_BASE=$(DOCKER_BASE_$(ARCH))
BASE_VERSION ?= $(ARCH)-$(VERSION)

ifneq ($(IS_RELEASE),true)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
DOCKER_TAG=$(BASE_VERSION)-$(EXTRA_VERSION)
else
DOCKER_TAG=$(BASE_VERSION)
endif

DOCKER_IMAGES = baseimage mongo nginx
DUMMY = .$(DOCKER_TAG)

ifeq ($(DOCKER_BASE), )
$(error "Architecture \"$(ARCH)\" is unsupported")
endif

all: check
all: docker check

build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
build/docker/nginx/$(DUMMY): build/docker/nginx/$(DUMMY)
build/docker/mongo/$(DUMMY): build/docker/mongo/$(DUMMY)

build/docker/%/$(DUMMY):
$(eval TARGET = ${patsubst build/docker/%/$(DUMMY),%,${@}})
$(eval DOCKER_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' \
> $(@D)/Dockerfile
docker build -f $(@D)/Dockerfile \
-t $(DOCKER_NAME) \
-t $(DOCKER_NAME):$(DOCKER_TAG) \
.
@touch $@

docker: $(patsubst %,build/docker/%/$(DUMMY),$(DOCKER_IMAGES))

check: ##@Code Check code format
tox
Expand Down Expand Up @@ -128,7 +177,7 @@ stop: ##@Service Stop service

restart: stop start ##@Service Restart service

setup-master: ##@Environment Setup dependency for master node
setup-master: docker ##@Environment Setup dependency for master node
cd scripts/master_node && bash setup.sh

setup-worker: ##@Environment Setup dependency for worker node
Expand Down
90 changes: 90 additions & 0 deletions baseimage/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Based thie file on https://github.com/docker-library/mongo/blob/master/3.4/Dockerfile &
# https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-ubuntu/#install-mongodb-enterprise

# ----------------------------------------------------------------
# Install mongo
# ----------------------------------------------------------------

groupadd -r mongodb && useradd -r -g mongodb mongodb

apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates jq numactl sudo\
&& rm -rf /var/lib/apt/lists/*

# grab gosu for easy step-down from root
export GOSU_VERSION=1.10

set -x \
&& apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true

mkdir /docker-entrypoint-initdb.d

# Add GPG Keys & update apt sources

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

echo "deb [ arch=amd64,arm64,ppc64el,s390x ] http://repo.mongodb.com/apt/ubuntu xenial/mongodb-enterprise/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-enterprise.list

apt-get update

export MONGO_PACKAGE=mongodb-enterprise
# export MONGO_REPO=repo.mongodb.com
# export MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}

export MONGO_MAJOR=3.4
export MONGO_VERSION=3.4.10

apt-get install -y \
${MONGO_PACKAGE}=$MONGO_VERSION \
${MONGO_PACKAGE}-server=$MONGO_VERSION \
${MONGO_PACKAGE}-shell=$MONGO_VERSION \
${MONGO_PACKAGE}-mongos=$MONGO_VERSION \
${MONGO_PACKAGE}-tools=$MONGO_VERSION

mkdir -p /data/db /data/configdb \
&& chown -R mongodb:mongodb /data/db /data/configdb

# ----------------------------------------------------------------
# Install NodeJS
# ----------------------------------------------------------------
NODE_VER=8.9.0

ARCH=`uname -m | sed 's|i686|x86|' | sed 's|x86_64|x64|'`
NODE_PKG=node-v$NODE_VER-linux-$ARCH.tar.gz
SRC_PATH=/tmp/$NODE_PKG

# First remove any prior packages downloaded in case of failure
cd /tmp
rm -f node*.tar.gz
wget --quiet https://nodejs.org/dist/v$NODE_VER/$NODE_PKG
cd /usr/local && sudo tar --strip-components 1 -xzf $SRC_PATH
rm -f /tmp/node*.tar.gz

# ----------------------------------------------------------------
# Install python3 and pip
# ----------------------------------------------------------------
apt-get -y install python3
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
cd /tmp
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
rm get-pip.py

# ----------------------------------------------------------------
# Install nginx
# ----------------------------------------------------------------
apt-get install nginx -y
5 changes: 5 additions & 0 deletions config/baseimage/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM _DOCKER_BASE_
COPY baseimage /tmp/baseimage
RUN cd /tmp/baseimage && \
bash install.sh && \
rm -rf /tmp/baseimage
11 changes: 11 additions & 0 deletions config/mongo/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM _NS_/cello-baseimage:_TAG_

COPY mongo/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

VOLUME /data/db /data/configdb

RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 27017
CMD ["mongod"]
7 changes: 7 additions & 0 deletions config/nginx/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM _NS_/cello-baseimage:_TAG_
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]
Loading

0 comments on commit e9eb9f1

Please sign in to comment.