Skip to content

Commit e75be2a

Browse files
author
Krishna Harsha Voora
committed
[CE-182] Refactor docker-compose and Dockerfile
Currently docker-compose*yml files and Dockerfiles are strictly architecture x86_64 dependent. To make it architecture independent, [CE-170] was introduced. This PR leverages [CE-170] and restructures docker-compose*yml and Dockerfiles and makes it architecture independent. Change-Id: I30faf25797263dcc8ee65f61277a9bfab3000a96 Signed-off-by: Krishna Harsha Voora <krishvoor@in.ibm.com>
1 parent 1eafd52 commit e75be2a

15 files changed

+119
-26
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ifeq ($(DOCKER_BASE), )
9494
$(error "Architecture \"$(ARCH)\" is unsupported")
9595
endif
9696

97-
all: docker check
97+
all: check
9898

9999
build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
100100
build/docker/nginx/$(DUMMY): build/docker/nginx/$(DUMMY)
@@ -118,7 +118,7 @@ build/docker/%/$(DUMMY):
118118

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

121-
check: ##@Code Check code format
121+
check: docker ##@Code Check code format
122122
tox
123123
@$(MAKE) test-case
124124
make start && sleep 10 && make stop
@@ -164,7 +164,7 @@ initial-env: ##@Configuration Initial Configuration for dashboard
164164
$(SED) 's/\(DEV=\).*/\1${DEV}/' .env
165165
$(SED) 's/\(ROOT_PATH=\).*/\1${ROOT_PATH_REPLACE}/' .env
166166

167-
start: ##@Service Start service
167+
start: docker ##@Service Start service
168168
@$(MAKE) $(START_OPTIONS)
169169
echo "Start all services..."
170170
docker-compose up -d --no-recreate

baseimage/install.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -x
23
#
34
# Copyright IBM Corp. All Rights Reserved.
45
#
@@ -77,7 +78,12 @@ rm -f /tmp/node*.tar.gz
7778
# ----------------------------------------------------------------
7879
# Install python3 and pip
7980
# ----------------------------------------------------------------
80-
apt-get -y install python3
81+
if [[ $ARCH = 'ppc64le' ]];then
82+
apt-get install build-essential libssl-dev libffi-dev python3-dev libxslt-dev python3 -y
83+
else
84+
apt-get install python3 -y
85+
fi
86+
8187
update-alternatives --install /usr/bin/python python /usr/bin/python3 10
8288
cd /tmp
8389
wget https://bootstrap.pypa.io/get-pip.py
@@ -87,4 +93,5 @@ rm get-pip.py
8793
# ----------------------------------------------------------------
8894
# Install nginx
8995
# ----------------------------------------------------------------
90-
apt-get install nginx -y
96+
groupadd -r nginx && useradd -r -g nginx nginx
97+
apt-get install nginx apache2-utils -y

config/nginx/Dockerfile.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
FROM _NS_/cello-baseimage:_TAG_
2+
3+
COPY nginx/ /tmp/
4+
5+
RUN cp /tmp/nginx.default.conf /etc/nginx/nginx.default.conf
6+
27
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
38
&& ln -sf /dev/stderr /var/log/nginx/error.log
49

5-
EXPOSE 80 443
6-
7-
CMD ["nginx", "-g", "daemon off;"]
10+
CMD ["/bin/bash", "/tmp/docker-entrypoint.sh"]

docker-compose-build-js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version: '2'
1414
services:
1515
# cello dashboard service
1616
build-js:
17-
image: node
17+
image: hyperledger/cello-baseimage
1818
volumes: # This should be removed in product env
1919
- ./src/$STATIC_FOLDER:/app
2020
- ./src/$TEMPLATE_FOLDER:/app/templates

docker-compose-npm-install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version: '2'
1414
services:
1515
# cello dashboard service
1616
npm-install:
17-
image: node
17+
image: hyperledger/cello-baseimage
1818
volumes: # This should be removed in product env
1919
- ./src/$STATIC_FOLDER:/app
2020
environment:

docker-compose-watch-mode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version: '2'
1414
services:
1515
# cello dashboard service
1616
watch-mode:
17-
image: node
17+
image: hyperledger/cello-baseimage
1818
container_name: watch-mode
1919
volumes: # This should be removed in product env
2020
- ./src/themes/react/static:/app

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
build:
1818
context: src
1919
dockerfile: Dockerfile-dashboard
20-
image: cello-dashboard
20+
image: hyperledger/cello-dashboard
2121
container_name: dashboard
2222
hostname: cello-dashboard
2323
restart: unless-stopped
@@ -38,7 +38,7 @@ services:
3838
build:
3939
context: src
4040
dockerfile: Dockerfile-restserver
41-
image: cello-restserver
41+
image: hyperledger/cello-restserver
4242
container_name: restserver
4343
hostname: cello-restserver
4444
restart: unless-stopped
@@ -57,7 +57,7 @@ services:
5757
build:
5858
context: src
5959
dockerfile: Dockerfile-watchdog
60-
image: cello-watchdog
60+
image: hyperledger/cello-watchdog
6161
container_name: watchdog
6262
hostname: cello-watchdog
6363
restart: unless-stopped
@@ -71,7 +71,7 @@ services:
7171

7272
# mongo database, may use others in future
7373
mongo:
74-
image: mongo:3.2
74+
image: hyperledger/cello-mongo
7575
hostname: mongo
7676
container_name: mongo
7777
restart: unless-stopped
@@ -87,7 +87,7 @@ services:
8787

8888
# nginx to forward front request, may split it out in future
8989
nginx:
90-
image: yeasy/nginx
90+
image: hyperledger/cello-nginx
9191
hostname: nginx
9292
container_name: nginx
9393
restart: always
@@ -107,7 +107,7 @@ services:
107107
user-dashboard:
108108
build:
109109
context: user-dashboard
110-
image: cello-user-dashboard
110+
image: hyperledger/cello-user-dashboard
111111
container_name: user-dashboard
112112
links:
113113
- mongo:dashboard_mongo

nginx/docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Based this file on https://github.com/yeasy/docker-nginx/blob/master/docker-entrypoint.sh
8+
9+
set -e
10+
backend="${BACKEND:-localhost}"
11+
port="${PORT:-80}"
12+
username="${USERNAME:-user}"
13+
password="${PASSWORD:-pass}"
14+
15+
htpasswd -c -b /etc/nginx/.htpasswd "$username" "$password"
16+
17+
sed "s/BACKEND/$backend/; s/PORT/$port/" /etc/nginx/nginx.default.conf > /etc/nginx/nginx.conf
18+
19+
nginx -c /etc/nginx/nginx.conf

nginx/nginx.default.conf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This file should be put under /etc/nginx/conf.d/
2+
# Or place as /etc/nginx/nginx.conf
3+
4+
user nginx;
5+
worker_processes auto;
6+
daemon off;
7+
8+
error_log /var/log/nginx/error.log warn;
9+
pid /var/run/nginx.pid;
10+
11+
events {
12+
worker_connections 1024;
13+
}
14+
15+
http {
16+
include /etc/nginx/mime.types;
17+
default_type application/octet-stream;
18+
19+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
20+
'$status $body_bytes_sent "$http_referer" '
21+
'"$http_user_agent" "$http_x_forwarded_for"';
22+
23+
access_log /var/log/nginx/access.log main;
24+
25+
server_tokens off;
26+
27+
sendfile on;
28+
tcp_nopush on;
29+
30+
keepalive_timeout 60;
31+
tcp_nodelay on;
32+
client_body_timeout 15;
33+
34+
gzip on;
35+
gzip_vary on;
36+
gzip_min_length 1k;
37+
38+
upstream backend {
39+
server BACKEND:PORT;
40+
}
41+
42+
server {
43+
listen 80;
44+
45+
location / {
46+
if ($request_method !~ ^(GET|DELETE|POST|PUT)$ ) {
47+
return 444;
48+
}
49+
auth_basic "Login";
50+
auth_basic_user_file /etc/nginx/.htpasswd;
51+
proxy_pass http://backend;
52+
proxy_set_header Host $host;
53+
proxy_set_header X-Forwarded-For $remote_addr;
54+
proxy_set_header X-Real-IP $remote_addr;
55+
}
56+
57+
error_page 500 502 503 504 /50x.html;
58+
location = /50x.html {
59+
root html;
60+
}
61+
}
62+
63+
include /etc/nginx/conf.d/*.conf;
64+
}

scripts/master_node/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ command -v docker-compose >/dev/null 2>&1 || { echo_r >&2 "No docker-compose fou
100100
&& echo_r "Warn: existing containers may cause unpredictable failure, suggest to clean them using docker rm"
101101

102102
echo_b "Download dependent Images..."
103-
bash ./download_images.sh
103+
#bash ./download_images.sh
104104

105105
echo_b "Checking local mounted database path ${DB_DIR}..."
106106
[ ! -d ${DB_DIR} ] \

src/Dockerfile-dashboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
FROM python:3.5
6+
FROM hyperledger/cello-baseimage
77
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
88
ENV TZ Asia/Shanghai
99

src/Dockerfile-restserver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
FROM python:3.5
6+
FROM hyperledger/cello-baseimage
77
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
88
ENV TZ Asia/Shanghai
99

src/Dockerfile-watchdog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
FROM python:3.5
6+
FROM hyperledger/cello-baseimage
77
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
88
ENV TZ Asia/Shanghai
99

@@ -14,4 +14,4 @@ RUN pip install -r requirements.txt
1414
COPY . /app
1515

1616
# use this in development
17-
CMD ["python", "watchdog.py"]
17+
CMD ["python", "watchdog.py"]

test/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
build:
1818
context: ../src
1919
dockerfile: Dockerfile-dashboard
20-
image: cello-dashboard
20+
image: hyperledger/cello-dashboard
2121
container_name: dashboard-test
2222
hostname: cello-dashboard
2323
environment:
@@ -36,7 +36,7 @@ services:
3636

3737
# mongo database, may use others in future
3838
mongo:
39-
image: mongo:3.2
39+
image: hyperledger/cello-mongo
4040
hostname: mongo
4141
container_name: mongo-test
4242
mem_limit: 2048m

user-dashboard/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
FROM node
6+
FROM hyperledger/cello-baseimage
77
MAINTAINER li xu cheng "lixucheng@aliyun.com"
88
RUN npm install -g requirejs
99
RUN mkdir -p /usr/app/src
@@ -14,4 +14,4 @@ RUN mv /usr/app/src/js /reactjs && \
1414
cd /reactjs/home && npm install && npm run build && rm -rf node_modules && \
1515
cd /usr/app/src && npm install && npm run build && npm cache clean --force
1616
EXPOSE 8080
17-
CMD ["npm", "start"]
17+
CMD ["npm", "start"]

0 commit comments

Comments
 (0)