Add Docker push to nexus support 77/36077/2
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Thu, 15 Mar 2018 22:21:15 +0000 (15:21 -0700)
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Fri, 16 Mar 2018 23:24:27 +0000 (16:24 -0700)
This patch adds support to push built docker container to
Nexus.

Change-Id: I9c9d3c01c548c0d3dcfec70f299765f0221379dc
Issue-ID: MUSIC-59
Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
deployment/Dockerfile
deployment/Dockerfile_ubuntu [new file with mode: 0644]
deployment/docker-build.sh
deployment/docker-entrypoint.sh
deployment/run.sh
deployment/setup-dependency.sh
src/dkv/Makefile

index 7f6c6d5..e9fe30d 100644 (file)
@@ -1,4 +1,4 @@
-FROM ubuntu:14.04
+FROM alpine:3.7
 
 ARG HTTP_PROXY=${HTTP_PROXY}
 ARG HTTPS_PROXY=${HTTPS_PROXY}
@@ -8,18 +8,14 @@ ENV https_proxy $HTTPS_PROXY
 ENV CONSUL_IP $CONSUL_IP
 ENV CONSUL_VERSION 1.0.6
 
-# Run Docker build from dkv directory.
-WORKDIR /distributed-kv-store
-
-RUN apt-get update && \
-    apt-get install -y build-essential && \
-    apt-get install -y realpath && \
-    apt-get install -y unzip && \
-    apt-get install -y git && \
-    apt-get install -y curl && \
-    apt-get install -y wget && \
-    git clone https://git.onap.org/music/distributed-kv-store
-
+RUN apk update && \
+    apk add g++ && \
+    apk add make && \
+    apk add unzip && \
+    apk add git && \
+    apk add curl && \
+    apk add wget && \
+    apk add --no-cache bash
 
 RUN wget -qO /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" && \
     unzip -d /bin /tmp/consul.zip && \
@@ -29,15 +25,14 @@ RUN wget -qO /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VER
 EXPOSE 8200
 EXPOSE 8080
 
-# Change this when deployment gets merged.
-WORKDIR /distributed-kv-store/distributed-kv-store/deployment/
-ADD ./setup-dependency.sh /distributed-kv-store/distributed-kv-store/deployment/
-ADD ./docker-entrypoint.sh /distributed-kv-store/distributed-kv-store/deployment/
 
-WORKDIR /distributed-kv-store/distributed-kv-store
-RUN deployment/setup-dependency.sh
+RUN mkdir /dkv_mount_path && \
+    mkdir /dkv_mount_path/consul_data && \
+    mkdir /dkv_mount_path/configs && \
+    mkdir /dkv_mount_path/configs/default
 
-VOLUME /configs
+WORKDIR /dkv_mount_path
+ADD ./dkv /dkv_mount_path/
+ADD ./docker-entrypoint.sh /dkv_mount_path/
 
-ENTRYPOINT deployment/docker-entrypoint.sh
-#ENTRYPOINT /bin/bash
\ No newline at end of file
+ENTRYPOINT /dkv_mount_path/docker-entrypoint.sh
\ No newline at end of file
diff --git a/deployment/Dockerfile_ubuntu b/deployment/Dockerfile_ubuntu
new file mode 100644 (file)
index 0000000..f876805
--- /dev/null
@@ -0,0 +1,37 @@
+FROM ubuntu:14.04
+
+ARG HTTP_PROXY=${HTTP_PROXY}
+ARG HTTPS_PROXY=${HTTPS_PROXY}
+
+ENV http_proxy $HTTP_PROXY
+ENV https_proxy $HTTPS_PROXY
+ENV CONSUL_IP $CONSUL_IP
+ENV CONSUL_VERSION 1.0.6
+
+RUN apt-get update && \
+    apt-get install -y build-essential && \
+    apt-get install -y realpath && \
+    apt-get install -y unzip && \
+    apt-get install -y git && \
+    apt-get install -y curl && \
+    apt-get install -y wget
+
+RUN wget -qO /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" && \
+    unzip -d /bin /tmp/consul.zip && \
+    chmod 755 /bin/consul && \
+    rm /tmp/consul.zip
+
+EXPOSE 8200
+EXPOSE 8080
+
+RUN mkdir /dkv_mount_path && \
+    mkdir /dkv_mount_path/consul_data && \
+    mkdir /dkv_mount_path/configs && \
+    mkdir /dkv_mount_path/configs/default
+
+WORKDIR /dkv_mount_path
+ADD ./dkv /dkv_mount_path/
+ADD ./docker-entrypoint.sh /dkv_mount_path/
+
+ENTRYPOINT /dkv_mount_path/docker-entrypoint.sh
+#ENTRYPOINT /bin/bash
\ No newline at end of file
index 767554f..50a2a89 100755 (executable)
@@ -1,5 +1,14 @@
 #!/bin/bash
 
+BUILD_ARGS="--no-cache"
+ORG="onap"
+VERSION="1.0.0"
+PROJECT="music"
+IMAGE="distributed-kv-store"
+DOCKER_REPOSITORY="nexus3.onap.org:10003"
+IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}"
+TIMESTAMP=$(date +"%Y%m%dT%H%M%S")
+
 if [ $HTTP_PROXY ]; then
     BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
 fi
@@ -7,5 +16,28 @@ if [ $HTTPS_PROXY ]; then
     BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
 fi
 
-echo "Start build docker image"
-docker build ${BUILD_ARGS} -t dkv .
+function generate_binary {
+    pushd ../src/dkv
+    make build
+    popd
+    cp ../target/dkv .
+}
+
+function build_image {
+    echo "Start build docker image."
+    docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:latest .
+}
+
+function push_image {
+    echo "Start push docker image."
+    docker push ${IMAGE_NAME}:latest
+}
+
+function remove_binary {
+    rm dkv
+}
+
+generate_binary
+build_image
+push_image
+remove_binary
index 0ec8d0e..62cf23b 100755 (executable)
@@ -1,31 +1,14 @@
 #!/bin/bash
 
-function verify_consul_run {
-    consul --version
-}
-
 function start_consul_server {
-    # Running consul in server mode since we are doing a single node. If we need to add more,
-    # We need to run multiple consul agents in client mode without providing the -server arguements.
-
-    consul agent -bootstrap -server -bind=127.0.0.1 -data-dir=/dkv/consul &
+    consul agent -bootstrap -server -bind=127.0.0.1 -data-dir=/dkv_mount_path/consul_data &
 }
 
 function start_api_server {
-    # Uncomment the following after the mountpath is setup in the code base and the docker file.
-    # Until then, go run is used.
-    #cd target
-    #./dkv
-    cd src/dkv/
-    go run main.go
-}
-
-function set_paths {
-    export GOPATH=$PWD
-    source /etc/environment
+    pushd /dkv_mount_path/
+    ./dkv
 }
 
-set_paths
 if [ "$CONSUL_IP" = "localhost" ]; then
     start_consul_server
     sleep 5
index 2451ef9..1be2ef2 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 
 CONSUL_IP="localhost"
-MOUNTPATH="/configs/"
+MOUNTPATH="/dkv_mount_path/configs/"
+DEFAULT_CONFIGS=$(pwd)/../mountpath/default # TODO(sshank): Change this to think from Kubernetes Volumes perspective.
 
-docker run -e CONSUL_IP=$CONSUL_IP -e MOUNTPATH=$MOUNTPATH -it --name dkv -p 8200:8200 -p 8080:8080 dkv
+docker run -e CONSUL_IP=$CONSUL_IP -e MOUNTPATH=$MOUNTPATH -it \
+           --name dkv \
+           -v $DEFAULT_CONFIGS:/dkv_mount_path/configs/default \
+           -p 8200:8200 -p 8080:8080 nexus3.onap.org:10003/onap/music/distributed-kv-store
index fcb2d51..f1ca4c2 100755 (executable)
@@ -1,30 +1,7 @@
 #!/bin/bash
 
-function install_go {
-    local golang_version=go1.10.linux-amd64
-    if [ ! -d /opt/go ]; then
-        mkdir /opt/go
-        pushd /opt/go
-        curl -O https://dl.google.com/go/$golang_version.tar.gz
-        tar -zxf $golang_version.tar.gz
-        echo GOROOT=$PWD/go >> /etc/environment
-        echo PATH=$PATH:$PWD/go/bin >> /etc/environment
-        rm -rf tar -zxf $golang_version.tar.gz
-        popd
-    fi
-    source /etc/environment
-}
-
-function install_dependencies {
-    pushd src/dkv/
-    make all
-    popd
-}
-
 function create_mountpath {
     cp -r mountpath/ /configs
 }
 
-install_go
-install_dependencies
 create_mountpath
index 6eb2941..f540692 100644 (file)
@@ -8,7 +8,7 @@ all: test build
 deploy: test build
 
 build: deps format
-       go build -o $(GOPATH)/target/$(BINARY) -v main.go
+       CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w' -o $(GOPATH)/target/$(BINARY) -v main.go
 
 clean:
        go clean