[
https://issues.apache.org/jira/browse/SCB-779?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16563166#comment-16563166
]
ASF GitHub Bot commented on SCB-779:
------------------------------------
asifdxtreme closed pull request #402: SCB-779 Add docker builder pattern
scripts
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/402
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/.gitignore b/.gitignore
index 74de4dd0..84fb8827 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,8 @@ service-center.iml
.idea/
**/*junit.xml
**/*.exe
+**/*.tgz
+**/apache-servicecomb-incubating-service-center-*
vendor/**
!vendor/manifest
diff --git a/DockerGuide.md b/DockerGuide.md
deleted file mode 100644
index 654b2713..00000000
--- a/DockerGuide.md
+++ /dev/null
@@ -1,20 +0,0 @@
-### Guide to build the Docker Image
-
-###### Step 1:
-Clone the Dependency
-```
-glide install
-```
-
-###### Step 2:
-Make the release
-
-```
-bash -x scripts/release/make_release.sh linux 1.0.0 latest
-```
-
-###### Step 3:
-Make the Docker Image
-```
-docker build -t service-center:dev .
-```
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 1b51c34e..00000000
--- a/Dockerfile
+++ /dev/null
@@ -1,22 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-FROM ubuntu
-
-ADD apache-servicecomb-incubating-service-center-latest-linux-amd64 /app/
-
-RUN sed -i 's/httpaddr = 127.0.0.1/httpaddr = 0.0.0.0/g' /app/conf/app.conf
-
-ENTRYPOINT ["/app/service-center"]
diff --git a/Dockerfile.build b/Dockerfile.build
new file mode 100644
index 00000000..9a96cabc
--- /dev/null
+++ b/Dockerfile.build
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM golang:1.8.3
+
+WORKDIR /go/src/github.com/apache/incubator-servicecomb-service-center
+
+COPY . .
+
+RUN bash -x scripts/build/local.sh linux 1.0.0 latest
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..6a9ec642
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,33 @@
+version: '3'
+services:
+ etcd:
+ image: 'quay.io/coreos/etcd:latest'
+ # restart: always
+ #ports:
+ # - "2379:2379"
+ environment:
+ ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
+ ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
+ ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd:2380
+ ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
+ ETCD_INITIAL_CLUSTER: default=http://etcd:2380
+
+ service-center:
+ depends_on:
+ - etcd
+ image: 'servicecomb/service-center:latest'
+ # restart: always
+ ports:
+ - "30100:30100"
+ environment:
+ BACKEND_ADDRESS: http://etcd:2379
+
+ scfrontend:
+ depends_on:
+ - service-center
+ image: 'servicecomb/scfrontend:latest'
+ # restart: always
+ ports:
+ - "30103:30103"
+ environment:
+ BACKEND_ADDRESS: http://service-center:30100
diff --git a/docs/README.md b/docs/README.md
index 26c5894b..481d3f8e 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -8,7 +8,9 @@
#### [Contribution Guide](/docs/contribution.md)
-#### [Docker Image Guide](/docs/create-docker-image.md)
+#### [Docker Image Guide](/scripts/docker)
+
+- [Making Service-Center Image](/scripts/docker/build-image)
- [Making Front-end Image](/scripts/docker/build-frontend-image)
diff --git a/docs/create-docker-image.md b/docs/create-docker-image.md
deleted file mode 100644
index de497272..00000000
--- a/docs/create-docker-image.md
+++ /dev/null
@@ -1,74 +0,0 @@
-### Creating Custom Docker Image for
[Service-Center](https://github.com/apache/incubator-servicecomb-service-center)
-
-There is already a docker image in our dockerhub
[repo](https://hub.docker.com/r/servicecomb/service-center/), you can use this
to run the service-center in docker container.
-```
-docker run -d -p 30100:30100 servicecomb/service-center
-```
-
-However if you want to customize the service-center and make your own docker
image then follow the steps below. By default we use `quay.io/coreos/etcd` as
our base image as we need etcd to be running before starting service-center, if
you want to change the base image then you can change
[here](scripts/docker/build-image/build.sh#L30).
-
-##### 1. Make Sure your service-center is in correct GOPATH and then download
all the dependencies
-```
-git clone https://github.com/apache/incubator-servicecomb-service-center.git
$GOPATH/src/github.com/apache/incubator-servicecomb-service-center
-cd $GOPATH/src/github.com/apache/incubator-servicecomb-service-center
-
-curl https://glide.sh/get | sh
-glide install
-```
-
-##### 2. Run the build script to make the docker image
-```
-# cd scripts/docker/build-image/
-# bash +x build.sh
-Sending build context to Docker daemon 40.95MB
-Step 1/3 : FROM quay.io/coreos/etcd:v3.1.0
- ---> d611dede458a
-Step 2/3 : COPY ./service-center ./start.sh /root/
- ---> 8df8858f0720
-Removing intermediate container 3ffea40f15b2
-Step 3/3 : ENTRYPOINT /root/start.sh
- ---> Running in 6aadc39c2d17
- ---> f9f8fbb0e612
-Removing intermediate container 6aadc39c2d17
-Successfully built f9f8fbb0e612
-Successfully tagged developement/servicecomb/service-center:latest
-```
-```
-# docker images
-REPOSITORY TAG IMAGE ID
CREATED SIZE
-developement/servicecomb/service-center latest f9f8fbb0e612
35 seconds ago 74.6MB
-```
-
-##### 3. Run the docker image
-```
-# docker run -d -p 30100:30100 developement/servicecomb/service-center
-c140cc4bdc449636cc911584e769bb75d1c973085014da3d530650cc4927ec45
-
-# docker ps
-CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
-c140cc4bdc44 developement/servicecomb/service-center "/root/start.sh"
4 seconds ago Up 3 seconds 2379-2380/tcp,
0.0.0.0:30100->30100/tcp amazing_leakey
-```
-
-##### 4. Verify the status of running container
-```
-# curl -v http://0.0.0.0:30100/health
-* Hostname was NOT found in DNS cache
-* Trying 0.0.0.0...
-* Connected to 0.0.0.0 (127.0.0.1) port 30100 (#0)
-> GET /health HTTP/1.1
-> User-Agent: curl/7.35.0
-> Host: 0.0.0.0:30100
-> Accept: */*
->
-< HTTP/1.1 200 OK
-< Content-Type: application/json;charset=utf-8
-* Server SERVICECENTER/3.0.0 is not blacklisted
-< Server: SERVICECENTER/3.0.0
-< X-Response-Status: 200
-< Date: Fri, 04 Aug 2017 06:29:14 GMT
-< Content-Length: 296
-<
-* Connection #0 to host 0.0.0.0 left intact
-{"instances":[{"instanceId":"043e7fa678de11e7b7300242ac110002","serviceId":"043dbea978de11e7b7300242ac110002","endpoints":["rest://0.0.0.0:30100"],"hostName":"service_center_172_17_0_2","status":"UP","healthCheck":{"mode":"push","interval":30,"times":3},"timestamp":"1501828060","environment":"production"}]}
-```
-
diff --git a/frontend/Readme.md b/frontend/Readme.md
index f5c64fa1..77e6f85f 100644
--- a/frontend/Readme.md
+++ b/frontend/Readme.md
@@ -42,7 +42,7 @@ cd ..
go run main.go
```
This will bring up the Service-Center UI on
[http://127.0.0.1:30103](http://127.0.0.1:30103).
-If you want to change the listening ip/port, you can modify it in the
configuration file (service-center/frontend/conf/app.conf : FRONTEND_HOST_IP,
FRONTEND_HOST_PORT).
+If you want to change the listening ip/port, you can modify it in the
configuration file (service-center/frontend/conf/app.conf : frontend_host_ip,
frontend_host_port).
### Preview of Service-Center UI

diff --git a/scripts/build/deps.sh b/scripts/build/deps.sh
new file mode 100644
index 00000000..5d477ac6
--- /dev/null
+++ b/scripts/build/deps.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+script_path=$(cd "$(dirname "$0")"; pwd)
+
+project_path=$script_path/../..
+
+source $script_path/tools.sh
+
+prepare_env() {
+ local force=${1:-""}
+
+ cd $project_path
+
+ mkdir -p vendor
+
+ if [ "X"$force != "X"-f ]; then
+ if [ ! $(ls vendor | wc -l) -gt 0 ]; then
+ sc_deps
+ fi
+
+ if [ ! -d frontend/app/bower_components ]; then
+ frontend_deps
+ fi
+ else
+ sc_deps
+
+ frontend_deps
+ fi
+}
+
+prepare_env $@
diff --git a/scripts/build/local.sh b/scripts/build/local.sh
new file mode 100644
index 00000000..5fdeb9f7
--- /dev/null
+++ b/scripts/build/local.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+export GOOS=${1:-"linux"}
+export GOARCH=${4:-"amd64"}
+
+RELEASE=${2:-"0.0.1"}
+
+PACKAGE=${3:-"${RELEASE}"}
+
+PACKAGE_PREFIX=apache-servicecomb-incubating-service-center
+
+script_path=$(cd "$(dirname "$0")"; pwd)
+
+source ${script_path}/tools.sh
+
+personal_build() {
+ source ${script_path}/deps.sh
+
+ build_service_center
+
+ build_frontend
+
+ package
+}
+
+personal_build
diff --git a/scripts/build/tools.sh b/scripts/build/tools.sh
new file mode 100644
index 00000000..b9643594
--- /dev/null
+++ b/scripts/build/tools.sh
@@ -0,0 +1,148 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+fail() {
+ echo "$1"
+ exit 1
+}
+
+install_glide() {
+ set +e
+ GLIDE=$(which glide)
+ if [ "$?" == "1" ]; then
+ set -e
+ curl https://glide.sh/get | sh
+ else
+ set -e
+ fi
+}
+
+install_bower() {
+ set +e
+ BOWER=$(which bower)
+ if [ "$?" == "1" ]; then
+ set -e
+
+ curl -sL https://deb.nodesource.com/setup_8.x | bash -
+ apt-get install -y nodejs
+
+ npm install -g bower
+ else
+ set -e
+ fi
+}
+
+build_service_center() {
+ local app=$PACKAGE_PREFIX-$PACKAGE-$GOOS-$GOARCH
+
+ set +e
+ rm -rf $app
+ rm -rf $app.tar.gz
+
+ set -e
+ mkdir -p $app
+
+ ## Build the Service-Center releases
+ export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
+ export BUILD_NUMBER=$RELEASE
+ GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date
+%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
+ GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.VERSION=$BUILD_NUMBER'"
+
+ local BINARY_NAME=$app/service-center
+ if [ "$GOOS" == "windows" ]; then
+ BINARY_NAME=${BINARY_NAME}.exe
+ fi
+ go build --ldflags "${GO_LDFLAGS}" -o $BINARY_NAME
+}
+
+build_frontend() {
+ ## Build Frontend Release
+ cd frontend
+ local BINARY_NAME=$PACKAGE_PREFIX-$PACKAGE-$GOOS-$GOARCH/frontend
+ if [ "$GOOS" == "windows" ]; then
+ BINARY_NAME=${BINARY_NAME}.exe
+ fi
+ go build -o ../$BINARY_NAME
+ cd ..
+}
+
+sc_deps() {
+ install_glide
+
+ glide install
+}
+
+frontend_deps() {
+ install_bower
+
+ ## Download the frontend dependencies using bower
+ cd frontend/app
+ bower install
+ cd ../..
+}
+
+## Prepare the Configuration and Make package
+package() {
+ local app=$PACKAGE_PREFIX-$PACKAGE-$GOOS-$GOARCH
+
+ cp -r etc/conf $app/
+ sed -i 's/# manager_name = \"sc-0\"/manager_name = \"sr-0\"/g'
$app/conf/app.conf
+ sed -i 's/# manager_addr = \"http:\/\/127.0.0.1:2380\"/manager_addr =
\"http:\/\/127.0.0.1:2380\"/g' $app/conf/app.conf
+ sed -i 's/# manager_cluster =
\"sc-0=http:\/\/127.0.0.1:2380\"/manager_cluster =
\"sr-0=http:\/\/127.0.0.1:2380\"/g' $app/conf/app.conf
+ sed -i 's/manager_cluster = \"127.0.0.1:2379\"/# manager_cluster =
\"127.0.0.1:2379\"/g' $app/conf/app.conf
+ sed -i 's/registry_plugin = etcd/registry_plugin = embeded_etcd/g'
$app/conf/app.conf
+
+ ## Copy the Service-Center Releases
+ cp -r scripts/release/LICENSE $app/
+ cp -r scripts/release/licenses $app/
+ cp -r scripts/release/NOTICE $app/
+ cp -r DISCLAIMER $app/
+ cp -r README.md $app/
+
+ ## Copy the frontend releases
+ cp -r frontend/app $app/
+
+ ## Copy Start Scripts
+ cp -r scripts/release/start_scripts/$GOOS/* $app/
+ if [ "$GOOS" != "windows" ]; then
+ chmod +x $app/*.sh
+ fi
+
+ ## Archive the release
+ tar -czvf $app.tar.gz $app
+}
+
+docker_builder_pattern() {
+ local dockerfile=${1:-"."}
+ local output=${2:-"."}
+ local builder_name=servicecomb/service-center:build
+ local
builder_path=/go/src/github.com/apache/incubator-servicecomb-service-center
+ local app=$PACKAGE_PREFIX-$PACKAGE-linux-amd64
+
+ set +e
+
+ docker rmi $builder_name
+
+ set -e
+
+ docker build -t $builder_name . -f $dockerfile/Dockerfile.build
+ docker create --name builder $builder_name
+ docker cp builder:$builder_path/$app $output
+ docker rm -f builder
+}
\ No newline at end of file
diff --git a/scripts/docker/README.md b/scripts/docker/README.md
index d97b4ae8..d98d529d 100644
--- a/scripts/docker/README.md
+++ b/scripts/docker/README.md
@@ -3,3 +3,7 @@
For Making docker images for Service-Center you can refer to this
[doc](/scripts/docker/build-image)
For Making the Front-end images you can refer to this
[doc](/scripts/docker/build-frontend-image)
+
+After Making the images, you can run the following command at the PROJECT_ROOT
to startup all
+
+ docker-compose up
\ No newline at end of file
diff --git a/scripts/docker/build-frontend-image/Dockerfile.tmpl
b/scripts/docker/build-frontend-image/Dockerfile.tmpl
index 318d8455..ddce1305 100644
--- a/scripts/docker/build-frontend-image/Dockerfile.tmpl
+++ b/scripts/docker/build-frontend-image/Dockerfile.tmpl
@@ -13,10 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM ubuntu
+FROM {{.BASE_IMAGE}}:{{.BASE_IMAGE_VERSION}}
-ADD frontend.tar.gz /opt
+ADD ./frontend /opt/frontend
-WORKDIR /opt/frontend
+EXPOSE 30103
-ENTRYPOINT ["/opt/frontend/start_linux.sh"]
+ENTRYPOINT ["/opt/frontend/start.sh"]
diff --git a/scripts/docker/build-frontend-image/README.md
b/scripts/docker/build-frontend-image/README.md
index f05b24a5..532ddaff 100644
--- a/scripts/docker/build-frontend-image/README.md
+++ b/scripts/docker/build-frontend-image/README.md
@@ -6,24 +6,17 @@ This script helps you to make the docker image of
service-center frontend presen
This script assumes you have already downloaded all the dependencies using
'glide install'. Make sure service-center application is running and get
service-center applications IP and PORT addresses.
-Update "PROJECT_ROOT/frontend/conf/app.conf" with service-center applications
IP and PORT address.
-
-Example app.conf file,
-
- frontend_host_ip=0.0.0.0
- frontend_host_port=30103
-
-Note: Configuring SC_HOST_IP will enable you to setup the EIP of the
Service-center.
-
Then build docker image of frontend from folder
"PROJECT_ROOT/scripts/docker/build-frontend-image/".
-
bash -x build.sh
Once the script finishes you will see image scfrontend-dev.tgz in the same
directory. You can use this this image to load the docker and start using. Run
following command, open Web Browser and connect to URL "http://<HOST_IP>:30103"
to view frontend UI.
- docker run -d -p 30103:30103 -t servicecomb/scfrontend
+ docker run -d -p 30103:30103 -e BACKEND_ADDRESS=${BACKEND_ADDRESS} -t
servicecomb/scfrontend
Where HOST_IP is the ip of host machine where docker container for frontend is
executing.
-Note: The same image can be used to deploy in Huawei Public Cloud using
CFE/CCE or just deploy in a VM.
+Note:
+
+1. The same image can be used to deploy in Huawei Public Cloud using CFE/CCE
or just deploy in a VM.
+1. Configuring BACKEND_ADDRESS will enable you to setup the EIP of the
Service-center.
diff --git a/scripts/docker/build-frontend-image/build.sh
b/scripts/docker/build-frontend-image/build.sh
index 36ce3f80..4930dc24 100644
--- a/scripts/docker/build-frontend-image/build.sh
+++ b/scripts/docker/build-frontend-image/build.sh
@@ -20,37 +20,45 @@ set -e
umask 027
SCRIPT_DIR=$(cd $(dirname $0); pwd)
-BASE_DIR=${SCRIPT_DIR}/../../..
-mkdir -p $SCRIPT_DIR/frontend
-
-cd $BASE_DIR/frontend
+BASE_DIR=${SCRIPT_DIR}/../../../
-# make CGO_ENABLED=0 since busybox will not execute if it is dynamically linked
-export CGO_ENABLED=0
-export GOOS="linux"
-export GOARCH="amd64"
+# build all
+PACKAGE=${1:-"latest"}
-# buils scfrontend
-go build -o $SCRIPT_DIR/frontend/scfrontend
+PACKAGE_PREFIX=apache-servicecomb-incubating-service-center
-#go to the script directory
-#cd $SCRIPT_DIR
+PACKAGE_DIR=$SCRIPT_DIR/../$PACKAGE_PREFIX-$PACKAGE-linux-amd64
-# copy the app conf folders to build-frontend-image/frontend
-cp -r app conf $BASE_DIR/scripts/frontend/start_linux.sh $SCRIPT_DIR/frontend
+source ${SCRIPT_DIR}/../../build/tools.sh
-chmod 755 $SCRIPT_DIR/frontend/start_linux.sh $SCRIPT_DIR/frontend/scfrontend
+if [ ! -d $PACKAGE_DIR ]; then
+ docker_builder_pattern $BASE_DIR $SCRIPT_DIR/../
+fi
-sed -i "s|frontend_host_ip=127.0.0.1|frontend_host_ip=0.0.0.0|g"
$SCRIPT_DIR/frontend/conf/app.conf
+# create image base dir
+mkdir -p $SCRIPT_DIR/frontend
-#go to the script directory
+# go to the script directory
cd $SCRIPT_DIR
-tar cf frontend.tar.gz frontend
+
+# copy the conf folder to build-frontend-image/frontend
+cp -rp $PACKAGE_DIR/app $PACKAGE_DIR/conf $PACKAGE_DIR/frontend start.sh
frontend
+
+chmod 500 frontend/start.sh frontend/frontend
+
+# store the base image name and version
+BASE_IMAGE=${BASE_IMAGE:-"ubuntu"}
+
+BASE_IMAGE_VERSION=${BASE_IMAGE_VERSION:-"latest"}
+
cp Dockerfile.tmpl Dockerfile
-docker build -t servicecomb/scfrontend .
-docker save servicecomb/scfrontend:latest |gzip >scfrontend-dev.tgz
+sed -i "s|{{.BASE_IMAGE}}|${BASE_IMAGE}|g" Dockerfile
+sed -i "s|{{.BASE_IMAGE_VERSION}}|${BASE_IMAGE_VERSION}|g" Dockerfile
+
+docker build --no-cache -t servicecomb/scfrontend:$PACKAGE .
+docker save servicecomb/scfrontend:$PACKAGE |gzip >scfrontend-dev.tgz
# remove the frontend directory from the build-frontend-image path
-rm -rf frontend Dockerfile frontend.tar.gz
+rm -rf frontend Dockerfile
diff --git a/scripts/docker/build-frontend-image/start.sh
b/scripts/docker/build-frontend-image/start.sh
new file mode 100644
index 00000000..60934696
--- /dev/null
+++ b/scripts/docker/build-frontend-image/start.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e
+
+umask 027
+
+cd /opt/frontend
+
+sed -i 's/^frontend_host_ip.*=.*$/frontend_host_ip = 0.0.0.0/g' conf/app.conf
+
+sc_ip_port=${BACKEND_ADDRESS#*//}
+sc_ip=${sc_ip_port%:*}
+sc_port=${sc_ip_port#*:}
+
+if [ ! -z "${sc_ip}" ]; then
+ sed -i "s|^httpaddr.*=.*$|httpaddr = ${sc_ip}|g" conf/app.conf
+fi
+if [ "X"${sc_port} != "X"${sc_ip} ]; then
+ sed -i "s|^httpport.*=.*$|httpport = ${sc_port}|g" conf/app.conf
+fi
+
+./frontend
\ No newline at end of file
diff --git a/scripts/docker/build-image/Dockerfile.tmpl
b/scripts/docker/build-image/Dockerfile.tmpl
index 69d088ce..ba87c1b3 100644
--- a/scripts/docker/build-image/Dockerfile.tmpl
+++ b/scripts/docker/build-image/Dockerfile.tmpl
@@ -15,6 +15,8 @@
FROM {{.BASE_IMAGE}}:{{.BASE_IMAGE_VERSION}}
-ADD ./service-center /opt/service-center
+COPY ./service-center /opt/service-center
+
+EXPOSE 30100
ENTRYPOINT ["/opt/service-center/start.sh"]
diff --git a/scripts/docker/build-image/README.md
b/scripts/docker/build-image/README.md
index 3187b892..e63c8d78 100644
--- a/scripts/docker/build-image/README.md
+++ b/scripts/docker/build-image/README.md
@@ -2,7 +2,7 @@
This script helps you to make the docker image of service-center present in
your current working directory.
-Here quay.io/coreos/etcd:v3.1.0 used as etcd base image. start.sh will be the
entrypoint for the docker container to start.
+The start.sh will be the entrypoint for the docker container to start.
### How To Run
@@ -13,4 +13,4 @@ This script assumes you have already downloaded all the
dependencies using 'glid
Once the script finishes you will see image service-center-dev.tgz in the same
directory.
Load this image to the docker and start using.
- docker run -d -p 30100:30100 developement/servicecomb/service-center
+ docker run -d -p 30100:30100 servicecomb/service-center
diff --git a/scripts/docker/build-image/build.sh
b/scripts/docker/build-image/build.sh
index 0e023aa6..7dff7fc9 100644
--- a/scripts/docker/build-image/build.sh
+++ b/scripts/docker/build-image/build.sh
@@ -20,43 +20,45 @@ set -e
umask 027
SCRIPT_DIR=$(cd $(dirname $0); pwd)
+
BASE_DIR=${SCRIPT_DIR}/../../../
-mkdir -p $SCRIPT_DIR/service-center
+# build all
+PACKAGE=${1:-"latest"}
+
+PACKAGE_PREFIX=apache-servicecomb-incubating-service-center
-cd $BASE_DIR
+PACKAGE_DIR=$SCRIPT_DIR/../$PACKAGE_PREFIX-$PACKAGE-linux-amd64
-# make CGO_ENABLED=0 since busybox will not execute if it is dynamically linked
-export CGO_ENABLED=0
-export GOOS="linux"
-export GOARCH="amd64"
+source ${SCRIPT_DIR}/../../build/tools.sh
-# buils service-center
-go build -o $SCRIPT_DIR/service-center/service-center
+if [ ! -d $PACKAGE_DIR ]; then
+ docker_builder_pattern $BASE_DIR $SCRIPT_DIR/../
+fi
+
+# create image base dir
+mkdir -p $SCRIPT_DIR/service-center
-#go to the script directory
+# go to the script directory
cd $SCRIPT_DIR
-# copy the conf folder to build-image/service-center
-cp -r $BASE_DIR/etc/conf start.sh service-center
+# copy the conf folder to build-image/service-center
+cp -rp $PACKAGE_DIR/conf $PACKAGE_DIR/service-center start.sh service-center
chmod 500 service-center/start.sh service-center/service-center
-sed -i "s|^registry_plugin.*=.*$|registry_plugin = embeded_etcd|g"
service-center/conf/app.conf
-sed -i "s|^httpaddr.*=.*$|httpaddr = 0.0.0.0|g" service-center/conf/app.conf
-sed -i "s|\(^manager_cluster.*=.*$\)|# \1|g" service-center/conf/app.conf
+# store the base image name and version
+BASE_IMAGE=${BASE_IMAGE:-"ubuntu"}
-# store the etcd image name and version
-BASE_IMAGE=quay.io/coreos/etcd
-BASE_IMAGE_VERSION=v3.1.9
+BASE_IMAGE_VERSION=${BASE_IMAGE_VERSION:-"latest"}
cp Dockerfile.tmpl Dockerfile
sed -i "s|{{.BASE_IMAGE}}|${BASE_IMAGE}|g" Dockerfile
sed -i "s|{{.BASE_IMAGE_VERSION}}|${BASE_IMAGE_VERSION}|g" Dockerfile
-docker build -t developement/servicecomb/service-center:latest .
-docker save developement/servicecomb/service-center:latest |gzip
>service-center-dev.tgz
+docker build --no-cache -t servicecomb/service-center:$PACKAGE .
+docker save servicecomb/service-center:$PACKAGE |gzip >service-center-dev.tgz
# remove the service-center directory from the build-image path
rm -rf service-center Dockerfile
diff --git a/scripts/docker/build-image/start.sh
b/scripts/docker/build-image/start.sh
index 7632960a..02ab6771 100644
--- a/scripts/docker/build-image/start.sh
+++ b/scripts/docker/build-image/start.sh
@@ -16,10 +16,13 @@
# limitations under the License.
set -e
+
umask 027
cd /opt/service-center
+sed -i 's/^httpaddr.*=.*$/httpaddr = 0.0.0.0/g' conf/app.conf
+
if [ ! -z "${BACKEND_ADDRESS}" ]; then
sed -i "s|^registry_plugin.*=.*$|registry_plugin = etcd|g" conf/app.conf
sed -i "s|^# manager_cluster.*=.*$|manager_cluster = ${BACKEND_ADDRESS}|g"
conf/app.conf
diff --git a/scripts/release/make_release.sh b/scripts/release/make_release.sh
index fc52cb1e..1c14b2f1 100755
--- a/scripts/release/make_release.sh
+++ b/scripts/release/make_release.sh
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+set -e
+
## Get the Release Number
if [ $2 == "" ]; then
echo "Invalid version number....exiting...."
@@ -53,20 +55,21 @@ case $1 in
esac
-## Prepare the Configuration
-prepare_conf() {
- set +e
- rm -rf tmp
-
- set -e
- mkdir tmp
- cp -r etc/conf tmp/
- sed -i 's/# manager_name = \"sc-0\"/manager_name = \"sr-0\"/g'
tmp/conf/app.conf
- sed -i 's/# manager_addr = \"http:\/\/127.0.0.1:2380\"/manager_addr =
\"http:\/\/127.0.0.1:2380\"/g' tmp/conf/app.conf
- sed -i 's/# manager_cluster =
\"sc-0=http:\/\/127.0.0.1:2380\"/manager_cluster =
\"sr-0=http:\/\/127.0.0.1:2380\"/g' tmp/conf/app.conf
- sed -i 's/manager_cluster = \"127.0.0.1:2379\"/# manager_cluster =
\"127.0.0.1:2379\"/g' tmp/conf/app.conf
- #sed -i s@"manager_cluster.*=.*$"@"manager_name = \"sr-0\"\nmanager_addr =
\"http://127.0.0.1:2380\"\nmanager_cluster = \"sr-0=http://127.0.0.1:2380\""@g
tmp/conf/app.conf
- sed -i 's/registry_plugin = etcd/registry_plugin = embeded_etcd/g'
tmp/conf/app.conf
+## Get the arch type
+export GOARCH=${4:-"amd64"}
+
+root_path=$(cd "$(dirname "$0")"; pwd)
+
+source ${root_path}/../build/tools.sh
+
+build() {
+ frontend_deps
+
+ build_service_center
+
+ build_frontend
+
+ package
}
# Build Linux Release
@@ -78,50 +81,9 @@ build_linux(){
echo "Error in Making Linux Release.....Package Number not specified"
fi
- set +e
- rm -rf $PACKAGE_PREFIX-$PACKAGE-linux-amd64
- rm -rf $PACKAGE_PREFIX-$PACKAGE-linux-amd64.tar.gz
-
- set -e
- mkdir -p $PACKAGE_PREFIX-$PACKAGE-linux-amd64
-
- ## Build the Service-Center releases
export GOOS=linux
- export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
- export BUILD_NUMBER=$RELEASE
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date
+%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.VERSION=$BUILD_NUMBER'"
- go build --ldflags "${GO_LDFLAGS}" -o
$PACKAGE_PREFIX-$PACKAGE-linux-amd64/service-center
-
- ## Build Frontend Release
- cd frontend
- go build -o ../$PACKAGE_PREFIX-$PACKAGE-linux-amd64/frontend
-
- ## Download the frontend dependencies using bower
- cd app
- bower install
-
- cd ../..
-
- prepare_conf
-
- ## Copy the Service-Center Releases
- cp -r tmp/conf $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- cp -r scripts/release/LICENSE $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- cp -r scripts/release/licenses $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- cp -r scripts/release/NOTICE $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- cp -r DISCLAIMER $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- cp -r README.md $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- ## Copy the frontend releases
- cp -r frontend/app $PACKAGE_PREFIX-$PACKAGE-linux-amd64/
-
- ## Copy Start Scripts
- cp -r scripts/release/start_scripts/linux/*
$PACKAGE_PREFIX-$PACKAGE-linux-amd64/
- chmod +x $PACKAGE_PREFIX-$PACKAGE-linux-amd64/*.sh
-
- ## Archive the release
- tar -czvf $PACKAGE_PREFIX-$PACKAGE-linux-amd64.tar.gz
$PACKAGE_PREFIX-$PACKAGE-linux-amd64
+ build
}
# Build Windows Release
@@ -133,51 +95,9 @@ build_windows(){
echo "Error in Making Windows Release.....Package Number not specified"
fi
- set +e
- rm -rf $PACKAGE_PREFIX-$PACKAGE-windows-amd64
- rm -rf $PACKAGE_PREFIX-$PACKAGE-windows-amd64.zip
-
- set -e
- mkdir -p $PACKAGE_PREFIX-$PACKAGE-windows-amd64
-
- ## Build Service-Center Release
export GOOS=windows
- export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
- export BUILD_NUMBER=$RELEASE
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date
+%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.VERSION=$BUILD_NUMBER'"
- go build --ldflags "${GO_LDFLAGS}" -o service-center.exe
- cp -r service-center.exe $PACKAGE_PREFIX-$PACKAGE-windows-amd64
-
- ## Build Frontend release
- cd frontend
- go build -o frontend.exe
- cp -r frontend.exe ../$PACKAGE_PREFIX-$PACKAGE-windows-amd64
-
- ## Download the frontend dependencies using bower
- cd app
- bower install
-
- cd ../..
-
- prepare_conf
-
- ## Copy the service-center releases
- cp -r tmp/conf $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
- cp -r scripts/release/LICENSE $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
- cp -r scripts/release/licenses $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
- cp -r scripts/release/NOTICE $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
- cp -r DISCLAIMER $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
- cp -r README.md $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
-
- ## Copy the Frontend releases
- cp -r frontend/app $PACKAGE_PREFIX-$PACKAGE-windows-amd64/
-
- ## Copy start scripts
- cp -r scripts/release/start_scripts/windows/*
$PACKAGE_PREFIX-$PACKAGE-windows-amd64/
-
- ## Archive the Release
- tar -czvf $PACKAGE_PREFIX-$PACKAGE-windows-amd64.tar.gz
$PACKAGE_PREFIX-$PACKAGE-windows-amd64
+
+ build
}
# Build Mac Release
@@ -189,50 +109,9 @@ build_mac(){
echo "Error in Making Mac Release.....Package Number not specified"
fi
- set +e
- rm -rf $PACKAGE_PREFIX-$PACKAGE-darwin-amd64
- rm -rf $PACKAGE_PREFIX-$PACKAGE-darwin-amd64.tar.gz
-
- set -e
- mkdir -p $PACKAGE_PREFIX-$PACKAGE-darwin-amd64
-
- ## Build the Service-Center releases
export GOOS=darwin
- export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
- export BUILD_NUMBER=$RELEASE
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date
+%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
- GO_LDFLAGS="${GO_LDFLAGS} -X
'github.com/apache/incubator-servicecomb-service-center/version.VERSION=$BUILD_NUMBER'"
- go build --ldflags "${GO_LDFLAGS}" -o
$PACKAGE_PREFIX-$PACKAGE-darwin-amd64/service-center
-
- ## Build Frontend Release
- cd frontend
- go build -o ../$PACKAGE_PREFIX-$PACKAGE-darwin-amd64/frontend
-
- ## Download the frontend dependencies using bower
- cd app
- bower install
-
- cd ../..
-
- prepare_conf
-
- ## Copy the Service-Center Releases
- cp -r tmp/conf $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- cp -r scripts/release/LICENSE $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- cp -r scripts/release/licenses $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- cp -r scripts/release/NOTICE $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- cp -r DISCLAIMER $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- cp -r README.md $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
-
- ## Copy the frontend releases
- cp -r frontend/app $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
-
- ## Copy Start Scripts
- cp -r scripts/release/start_scripts/mac/*
$PACKAGE_PREFIX-$PACKAGE-darwin-amd64/
- chmod +x $PACKAGE_PREFIX-$PACKAGE-darwin-amd64/*.sh
- ## Archive the release
- tar -czvf $PACKAGE_PREFIX-$PACKAGE-darwin-amd64.tar.gz
$PACKAGE_PREFIX-$PACKAGE-darwin-amd64
+ build
}
## Compile the binary
diff --git a/scripts/release/start_scripts/mac/start-frontend.sh
b/scripts/release/start_scripts/darwin/start-frontend.sh
similarity index 100%
rename from scripts/release/start_scripts/mac/start-frontend.sh
rename to scripts/release/start_scripts/darwin/start-frontend.sh
diff --git a/scripts/release/start_scripts/mac/start-service-center.sh
b/scripts/release/start_scripts/darwin/start-service-center.sh
similarity index 100%
rename from scripts/release/start_scripts/mac/start-service-center.sh
rename to scripts/release/start_scripts/darwin/start-service-center.sh
diff --git a/scripts/release/start_scripts/mac/stop-frontend.sh
b/scripts/release/start_scripts/darwin/stop-frontend.sh
similarity index 100%
rename from scripts/release/start_scripts/mac/stop-frontend.sh
rename to scripts/release/start_scripts/darwin/stop-frontend.sh
diff --git a/scripts/release/start_scripts/mac/stop-service-center.sh
b/scripts/release/start_scripts/darwin/stop-service-center.sh
similarity index 100%
rename from scripts/release/start_scripts/mac/stop-service-center.sh
rename to scripts/release/start_scripts/darwin/stop-service-center.sh
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add docker builder pattern scripts
> ----------------------------------
>
> Key: SCB-779
> URL: https://issues.apache.org/jira/browse/SCB-779
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)