Skip to content

Commit

Permalink
[CE-182] Refactor docker-compose and Dockerfile
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
krishvoor committed Dec 1, 2017
1 parent 1eafd52 commit e75be2a
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ifeq ($(DOCKER_BASE), )
$(error "Architecture \"$(ARCH)\" is unsupported")
endif

all: docker check
all: check

build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
build/docker/nginx/$(DUMMY): build/docker/nginx/$(DUMMY)
Expand All @@ -118,7 +118,7 @@ build/docker/%/$(DUMMY):

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

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

start: ##@Service Start service
start: docker ##@Service Start service
@$(MAKE) $(START_OPTIONS)
echo "Start all services..."
docker-compose up -d --no-recreate
Expand Down
11 changes: 9 additions & 2 deletions baseimage/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -x
#
# Copyright IBM Corp. All Rights Reserved.
#
Expand Down Expand Up @@ -77,7 +78,12 @@ rm -f /tmp/node*.tar.gz
# ----------------------------------------------------------------
# Install python3 and pip
# ----------------------------------------------------------------
apt-get -y install python3
if [[ $ARCH = 'ppc64le' ]];then
apt-get install build-essential libssl-dev libffi-dev python3-dev libxslt-dev python3 -y
else
apt-get install python3 -y
fi

update-alternatives --install /usr/bin/python python /usr/bin/python3 10
cd /tmp
wget https://bootstrap.pypa.io/get-pip.py
Expand All @@ -87,4 +93,5 @@ rm get-pip.py
# ----------------------------------------------------------------
# Install nginx
# ----------------------------------------------------------------
apt-get install nginx -y
groupadd -r nginx && useradd -r -g nginx nginx
apt-get install nginx apache2-utils -y
9 changes: 6 additions & 3 deletions config/nginx/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM _NS_/cello-baseimage:_TAG_

COPY nginx/ /tmp/

RUN cp /tmp/nginx.default.conf /etc/nginx/nginx.default.conf

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;"]
CMD ["/bin/bash", "/tmp/docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker-compose-build-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version: '2'
services:
# cello dashboard service
build-js:
image: node
image: hyperledger/cello-baseimage
volumes: # This should be removed in product env
- ./src/$STATIC_FOLDER:/app
- ./src/$TEMPLATE_FOLDER:/app/templates
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-npm-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version: '2'
services:
# cello dashboard service
npm-install:
image: node
image: hyperledger/cello-baseimage
volumes: # This should be removed in product env
- ./src/$STATIC_FOLDER:/app
environment:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-watch-mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version: '2'
services:
# cello dashboard service
watch-mode:
image: node
image: hyperledger/cello-baseimage
container_name: watch-mode
volumes: # This should be removed in product env
- ./src/themes/react/static:/app
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
build:
context: src
dockerfile: Dockerfile-dashboard
image: cello-dashboard
image: hyperledger/cello-dashboard
container_name: dashboard
hostname: cello-dashboard
restart: unless-stopped
Expand All @@ -38,7 +38,7 @@ services:
build:
context: src
dockerfile: Dockerfile-restserver
image: cello-restserver
image: hyperledger/cello-restserver
container_name: restserver
hostname: cello-restserver
restart: unless-stopped
Expand All @@ -57,7 +57,7 @@ services:
build:
context: src
dockerfile: Dockerfile-watchdog
image: cello-watchdog
image: hyperledger/cello-watchdog
container_name: watchdog
hostname: cello-watchdog
restart: unless-stopped
Expand All @@ -71,7 +71,7 @@ services:

# mongo database, may use others in future
mongo:
image: mongo:3.2
image: hyperledger/cello-mongo
hostname: mongo
container_name: mongo
restart: unless-stopped
Expand All @@ -87,7 +87,7 @@ services:

# nginx to forward front request, may split it out in future
nginx:
image: yeasy/nginx
image: hyperledger/cello-nginx
hostname: nginx
container_name: nginx
restart: always
Expand All @@ -107,7 +107,7 @@ services:
user-dashboard:
build:
context: user-dashboard
image: cello-user-dashboard
image: hyperledger/cello-user-dashboard
container_name: user-dashboard
links:
- mongo:dashboard_mongo
Expand Down
19 changes: 19 additions & 0 deletions nginx/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Based this file on https://github.com/yeasy/docker-nginx/blob/master/docker-entrypoint.sh

set -e
backend="${BACKEND:-localhost}"
port="${PORT:-80}"
username="${USERNAME:-user}"
password="${PASSWORD:-pass}"

htpasswd -c -b /etc/nginx/.htpasswd "$username" "$password"

sed "s/BACKEND/$backend/; s/PORT/$port/" /etc/nginx/nginx.default.conf > /etc/nginx/nginx.conf

nginx -c /etc/nginx/nginx.conf
64 changes: 64 additions & 0 deletions nginx/nginx.default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file should be put under /etc/nginx/conf.d/
# Or place as /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
daemon off;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

server_tokens off;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;
tcp_nodelay on;
client_body_timeout 15;

gzip on;
gzip_vary on;
gzip_min_length 1k;

upstream backend {
server BACKEND:PORT;
}

server {
listen 80;

location / {
if ($request_method !~ ^(GET|DELETE|POST|PUT)$ ) {
return 444;
}
auth_basic "Login";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

include /etc/nginx/conf.d/*.conf;
}
2 changes: 1 addition & 1 deletion scripts/master_node/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ command -v docker-compose >/dev/null 2>&1 || { echo_r >&2 "No docker-compose fou
&& 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
#bash ./download_images.sh

echo_b "Checking local mounted database path ${DB_DIR}..."
[ ! -d ${DB_DIR} ] \
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile-dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM python:3.5
FROM hyperledger/cello-baseimage
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
ENV TZ Asia/Shanghai

Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile-restserver
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM python:3.5
FROM hyperledger/cello-baseimage
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
ENV TZ Asia/Shanghai

Expand Down
4 changes: 2 additions & 2 deletions src/Dockerfile-watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM python:3.5
FROM hyperledger/cello-baseimage
MAINTAINER Baohua Yang <"baohyang@cn.ibm.com">
ENV TZ Asia/Shanghai

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

# use this in development
CMD ["python", "watchdog.py"]
CMD ["python", "watchdog.py"]
4 changes: 2 additions & 2 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
build:
context: ../src
dockerfile: Dockerfile-dashboard
image: cello-dashboard
image: hyperledger/cello-dashboard
container_name: dashboard-test
hostname: cello-dashboard
environment:
Expand All @@ -36,7 +36,7 @@ services:

# mongo database, may use others in future
mongo:
image: mongo:3.2
image: hyperledger/cello-mongo
hostname: mongo
container_name: mongo-test
mem_limit: 2048m
Expand Down
4 changes: 2 additions & 2 deletions user-dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM node
FROM hyperledger/cello-baseimage
MAINTAINER li xu cheng "lixucheng@aliyun.com"
RUN npm install -g requirejs
RUN mkdir -p /usr/app/src
Expand All @@ -14,4 +14,4 @@ RUN mv /usr/app/src/js /reactjs && \
cd /reactjs/home && npm install && npm run build && rm -rf node_modules && \
cd /usr/app/src && npm install && npm run build && npm cache clean --force
EXPOSE 8080
CMD ["npm", "start"]
CMD ["npm", "start"]

0 comments on commit e75be2a

Please sign in to comment.