Skip to content

Commit e9eb9f1

Browse files
author
Krishna Harsha Voora
committed
Fix [CE-170]
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>
1 parent 993c55f commit e9eb9f1

File tree

6 files changed

+419
-3
lines changed

6 files changed

+419
-3
lines changed

Makefile

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ GREEN := $(shell tput -Txterm setaf 2)
66
WHITE := $(shell tput -Txterm setaf 7)
77
YELLOW := $(shell tput -Txterm setaf 3)
88
RESET := $(shell tput -Txterm sgr0)
9+
ARCH := $(shell uname -m)
910

1011
SLASH:=/
1112
REPLACE_SLASH:=\/
@@ -49,7 +50,7 @@ endif
4950

5051
# changelog specific version tags
5152
PREV_VERSION=0.6
52-
BASE_VERSION=
53+
#BASE_VERSION=
5354

5455
.PHONY: \
5556
all \ # default to run check
@@ -66,8 +67,56 @@ BASE_VERSION=
6667
start \ # start all services
6768
restart \ # restart all services
6869
stop \ # stop all services
70+
docker \ # create docker image
71+
72+
DOCKER_NS ?= hyperledger
73+
BASENAME ?= $(DOCKER_NS)/cello
74+
VERSION ?= 0.7.0
75+
IS_RELEASE=false
76+
77+
DOCKER_BASE_x86_64=ubuntu:xenial
78+
DOCKER_BASE_ppc64le=ppc64le/ubuntu:xenial
79+
DOCKER_BASE_s390x=s390x/debian:jessie
80+
DOCKER_BASE=$(DOCKER_BASE_$(ARCH))
81+
BASE_VERSION ?= $(ARCH)-$(VERSION)
82+
83+
ifneq ($(IS_RELEASE),true)
84+
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
85+
DOCKER_TAG=$(BASE_VERSION)-$(EXTRA_VERSION)
86+
else
87+
DOCKER_TAG=$(BASE_VERSION)
88+
endif
89+
90+
DOCKER_IMAGES = baseimage mongo nginx
91+
DUMMY = .$(DOCKER_TAG)
92+
93+
ifeq ($(DOCKER_BASE), )
94+
$(error "Architecture \"$(ARCH)\" is unsupported")
95+
endif
6996

70-
all: check
97+
all: docker check
98+
99+
build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
100+
build/docker/nginx/$(DUMMY): build/docker/nginx/$(DUMMY)
101+
build/docker/mongo/$(DUMMY): build/docker/mongo/$(DUMMY)
102+
103+
build/docker/%/$(DUMMY):
104+
$(eval TARGET = ${patsubst build/docker/%/$(DUMMY),%,${@}})
105+
$(eval DOCKER_NAME = $(BASENAME)-$(TARGET))
106+
@mkdir -p $(@D)
107+
@echo "Building docker $(TARGET)"
108+
@cat config/$(TARGET)/Dockerfile.in \
109+
| sed -e 's|_DOCKER_BASE_|$(DOCKER_BASE)|g' \
110+
| sed -e 's|_NS_|$(DOCKER_NS)|g' \
111+
| sed -e 's|_TAG_|$(DOCKER_TAG)|g' \
112+
> $(@D)/Dockerfile
113+
docker build -f $(@D)/Dockerfile \
114+
-t $(DOCKER_NAME) \
115+
-t $(DOCKER_NAME):$(DOCKER_TAG) \
116+
.
117+
@touch $@
118+
119+
docker: $(patsubst %,build/docker/%/$(DUMMY),$(DOCKER_IMAGES))
71120

72121
check: ##@Code Check code format
73122
tox
@@ -128,7 +177,7 @@ stop: ##@Service Stop service
128177

129178
restart: stop start ##@Service Restart service
130179

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

134183
setup-worker: ##@Environment Setup dependency for worker node

baseimage/install.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Based thie file on https://github.com/docker-library/mongo/blob/master/3.4/Dockerfile &
8+
# https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-ubuntu/#install-mongodb-enterprise
9+
10+
# ----------------------------------------------------------------
11+
# Install mongo
12+
# ----------------------------------------------------------------
13+
14+
groupadd -r mongodb && useradd -r -g mongodb mongodb
15+
16+
apt-get update \
17+
&& apt-get install -y --no-install-recommends ca-certificates jq numactl sudo\
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# grab gosu for easy step-down from root
21+
export GOSU_VERSION=1.10
22+
23+
set -x \
24+
&& apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/* \
25+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
26+
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
27+
&& export GNUPGHOME="$(mktemp -d)" \
28+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
29+
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
30+
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
31+
&& chmod +x /usr/local/bin/gosu \
32+
&& gosu nobody true
33+
34+
mkdir /docker-entrypoint-initdb.d
35+
36+
# Add GPG Keys & update apt sources
37+
38+
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
39+
40+
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
41+
42+
apt-get update
43+
44+
export MONGO_PACKAGE=mongodb-enterprise
45+
# export MONGO_REPO=repo.mongodb.com
46+
# export MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
47+
48+
export MONGO_MAJOR=3.4
49+
export MONGO_VERSION=3.4.10
50+
51+
apt-get install -y \
52+
${MONGO_PACKAGE}=$MONGO_VERSION \
53+
${MONGO_PACKAGE}-server=$MONGO_VERSION \
54+
${MONGO_PACKAGE}-shell=$MONGO_VERSION \
55+
${MONGO_PACKAGE}-mongos=$MONGO_VERSION \
56+
${MONGO_PACKAGE}-tools=$MONGO_VERSION
57+
58+
mkdir -p /data/db /data/configdb \
59+
&& chown -R mongodb:mongodb /data/db /data/configdb
60+
61+
# ----------------------------------------------------------------
62+
# Install NodeJS
63+
# ----------------------------------------------------------------
64+
NODE_VER=8.9.0
65+
66+
ARCH=`uname -m | sed 's|i686|x86|' | sed 's|x86_64|x64|'`
67+
NODE_PKG=node-v$NODE_VER-linux-$ARCH.tar.gz
68+
SRC_PATH=/tmp/$NODE_PKG
69+
70+
# First remove any prior packages downloaded in case of failure
71+
cd /tmp
72+
rm -f node*.tar.gz
73+
wget --quiet https://nodejs.org/dist/v$NODE_VER/$NODE_PKG
74+
cd /usr/local && sudo tar --strip-components 1 -xzf $SRC_PATH
75+
rm -f /tmp/node*.tar.gz
76+
77+
# ----------------------------------------------------------------
78+
# Install python3 and pip
79+
# ----------------------------------------------------------------
80+
apt-get -y install python3
81+
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
82+
cd /tmp
83+
wget https://bootstrap.pypa.io/get-pip.py
84+
python get-pip.py
85+
rm get-pip.py
86+
87+
# ----------------------------------------------------------------
88+
# Install nginx
89+
# ----------------------------------------------------------------
90+
apt-get install nginx -y

config/baseimage/Dockerfile.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM _DOCKER_BASE_
2+
COPY baseimage /tmp/baseimage
3+
RUN cd /tmp/baseimage && \
4+
bash install.sh && \
5+
rm -rf /tmp/baseimage

config/mongo/Dockerfile.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM _NS_/cello-baseimage:_TAG_
2+
3+
COPY mongo/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
4+
5+
VOLUME /data/db /data/configdb
6+
7+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
8+
ENTRYPOINT ["docker-entrypoint.sh"]
9+
10+
EXPOSE 27017
11+
CMD ["mongod"]

config/nginx/Dockerfile.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM _NS_/cello-baseimage:_TAG_
2+
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
3+
&& ln -sf /dev/stderr /var/log/nginx/error.log
4+
5+
EXPOSE 80 443
6+
7+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)