AMBARI-21031. Add docker support for infra manager (oleewere)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8bf136a4 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8bf136a4 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8bf136a4 Branch: refs/heads/ambari-rest-api-explorer Commit: 8bf136a4b78b495de849565400f24a7cc2cbd834 Parents: 1568f80 Author: oleewere <oleew...@gmail.com> Authored: Tue May 16 13:57:12 2017 +0200 Committer: oleewere <oleew...@gmail.com> Committed: Wed May 17 19:35:46 2017 +0200 ---------------------------------------------------------------------- ambari-infra/ambari-infra-assembly/pom.xml | 6 +- ambari-infra/ambari-infra-manager/README.md | 6 ++ ambari-infra/ambari-infra-manager/build.xml | 1 + .../ambari-infra-manager/docker/Dockerfile | 52 ++++++++++++ .../ambari-infra-manager/docker/bin/start.sh | 21 +++++ .../docker/infra-manager-docker.sh | 85 ++++++++++++++++++++ .../src/main/resources/infra-manager-env.sh | 18 +++++ .../src/main/resources/infraManager.sh | 2 +- 8 files changed, 188 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-assembly/pom.xml ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-assembly/pom.xml b/ambari-infra/ambari-infra-assembly/pom.xml index 550d97c..fafef7e 100644 --- a/ambari-infra/ambari-infra-assembly/pom.xml +++ b/ambari-infra/ambari-infra-assembly/pom.xml @@ -140,6 +140,7 @@ <excludes> <exclude>log4j.xml</exclude> <exclude>infra-manager.properties</exclude> + <exclude>infra-manager-env.sh</exclude> </excludes> </source> </sources> @@ -152,6 +153,7 @@ <includes> <include>log4j.xml</include> <include>infra-manager.properties</include> + <include>infra-manager-env.sh</include> </includes> </source> </sources> @@ -341,7 +343,7 @@ <prefix>${infra-manager.mapping.path}</prefix> </mapper> <excludes> - log4j.xml,infra-manager.properties + log4j.xml,infra-manager.properties,infra-manager-env.sh </excludes> </data> <data> @@ -355,7 +357,7 @@ <filemode>644</filemode> </mapper> <includes> - log4j.xml,infra-manager.properties + log4j.xml,infra-manager.properties,infra-manager-env.sh </includes> </data> </dataSet> http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/README.md ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/README.md b/ambari-infra/ambari-infra-manager/README.md index 033bbb2..d3527c4 100644 --- a/ambari-infra/ambari-infra-manager/README.md +++ b/ambari-infra/ambari-infra-manager/README.md @@ -22,4 +22,10 @@ TODO ## Build & Run Application ```bash mvn clean package exec:java +``` + +## Build & Run Application in docker container +```bash +cd docker +./infra-manager-docker.sh ``` \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/build.xml ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/build.xml b/ambari-infra/ambari-infra-manager/build.xml index c7954d9..3d0f4da 100644 --- a/ambari-infra/ambari-infra-manager/build.xml +++ b/ambari-infra/ambari-infra-manager/build.xml @@ -35,6 +35,7 @@ </copy> <copy todir="target/package" includeEmptyDirs="no"> <fileset file="src/main/resources/infraManager.sh"/> + <fileset file="src/main/resources/infra-manager-env.sh"/> <fileset file="target/classes/infra-manager.properties"/> <fileset file="target/classes/log4j.xml"/> </copy> http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/docker/Dockerfile ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/docker/Dockerfile b/ambari-infra/ambari-infra-manager/docker/Dockerfile new file mode 100644 index 0000000..adb584a --- /dev/null +++ b/ambari-infra/ambari-infra-manager/docker/Dockerfile @@ -0,0 +1,52 @@ +# Licensed 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 centos:centos6 + +RUN echo root:changeme | chpasswd + +RUN yum clean all -y && yum update -y +RUN yum -y install vim wget rpm-build sudo which telnet tar openssh-server openssh-clients ntp git httpd lsof +RUN rpm -e --nodeps --justdb glibc-common +RUN yum -y install glibc-common + +ENV HOME /root + +#Install JAVA +ENV JAVA_VERSION 8u31 +ENV BUILD_VERSION b13 +RUN wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/jdk-$JAVA_VERSION-linux-x64.rpm" -O jdk-8-linux-x64.rpm +RUN rpm -ivh jdk-8-linux-x64.rpm +ENV JAVA_HOME /usr/java/default/ + +#Install Maven +RUN mkdir -p /opt/maven +WORKDIR /opt/maven +RUN wget http://archive.apache.org/dist/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz +RUN tar -xvzf /opt/maven/apache-maven-3.3.1-bin.tar.gz +RUN rm -rf /opt/maven/apache-maven-3.3.1-bin.tar.gz + +ENV M2_HOME /opt/maven/apache-maven-3.3.1 +ENV MAVEN_OPTS -Xmx2048m +ENV PATH $PATH:$JAVA_HOME/bin:$M2_HOME/bin + +# SSH key +RUN ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' +RUN cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys +RUN chmod 600 /root/.ssh/authorized_keys +RUN sed -ri 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config + +ADD bin/start.sh /root/start.sh +RUN chmod +x /root/start.sh + +WORKDIR /root +CMD /root/start.sh \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/docker/bin/start.sh ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/docker/bin/start.sh b/ambari-infra/ambari-infra-manager/docker/bin/start.sh new file mode 100755 index 0000000..076c06f --- /dev/null +++ b/ambari-infra/ambari-infra-manager/docker/bin/start.sh @@ -0,0 +1,21 @@ +#!/bin/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 + +export INFRA_MANAGER_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=5007,server=y,suspend=n" +touch /root/infra-manager.log +/root/ambari-infra-manager/infraManager.sh --port 61890 > /root/infra-manager.log +tail -f /root/infra-manager.log + http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/docker/infra-manager-docker.sh ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/docker/infra-manager-docker.sh b/ambari-infra/ambari-infra-manager/docker/infra-manager-docker.sh new file mode 100755 index 0000000..87d6b8a --- /dev/null +++ b/ambari-infra/ambari-infra-manager/docker/infra-manager-docker.sh @@ -0,0 +1,85 @@ +#!/bin/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 + +sdir="`dirname \"$0\"`" +: ${1:?"argument is missing: (start|stop|build-and-run|build|build-docker-and-run|build-mvn-and-run|build-docker-only|build-mvn-only)"} +command="$1" + +function build_infra_manager_container() { + pushd $sdir + docker build -t ambari-infra-manager:v1.0 . + popd +} + +function build_infra_manager_project() { + pushd $sdir/../ + mvn clean package -DskipTests + popd +} + +function kill_infra_manager_container() { + echo "Try to remove infra manager container if exists ..." + docker rm -f infra-manager +} + +function start_infra_manager_container() { + echo "Start infra manager container ..." + pushd $sdir/../ + local AMBARI_INFRA_MANAGER_LOCATION=$(pwd) + popd + kill_infra_manager_container + docker run -d --name infra-manager --hostname infra-manager.apache.org \ + -v $AMBARI_INFRA_MANAGER_LOCATION/target/package:/root/ambari-infra-manager -p 61890:61890 -p 5007:5007 \ + ambari-infra-manager:v1.0 + ip_address=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' logsearch) + echo "Ambari Infra Manager container started on $ip_address (for Mac OSX route to boot2docker/docker-machine VM address, e.g.: 'sudo route add -net 172.17.0.0/16 192.168.59.103')" + echo "You can follow Log Search logs with 'docker logs -f infra-manager' command" +} + +case $command in + "build-and-run") + build_infra_manager_project + build_infra_manager_container + start_infra_manager_container + ;; + "build") + build_infra_manager_project + start_infra_manager_container + ;; + "build-docker-and-run") + build_infra_manager_container + start_infra_manager_container + ;; + "build-mvn-and-run") + build_infra_manager_project + build_infra_manager_container + ;; + "build-docker-only") + build_infra_manager_container + ;; + "build-mvn-only") + build_infra_manager_project + ;; + "start") + start_infra_manager_container + ;; + "stop") + kill_infra_manager_container + ;; + *) + echo "Available commands: (start|stop|build-and-run|build|build-docker-and-run|build-mvn-and-run|build-docker-only|build-mvn-only)" + ;; +esac \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/src/main/resources/infra-manager-env.sh ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/src/main/resources/infra-manager-env.sh b/ambari-infra/ambari-infra-manager/src/main/resources/infra-manager-env.sh new file mode 100644 index 0000000..c7e11c3 --- /dev/null +++ b/ambari-infra/ambari-infra-manager/src/main/resources/infra-manager-env.sh @@ -0,0 +1,18 @@ +#!/bin/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. + +# Extend with java options or system properties. e.g.: INFRA_MANAGER_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=5007,server=y,suspend=n" +export INFRA_MANAGER_OPTS="" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/8bf136a4/ambari-infra/ambari-infra-manager/src/main/resources/infraManager.sh ---------------------------------------------------------------------- diff --git a/ambari-infra/ambari-infra-manager/src/main/resources/infraManager.sh b/ambari-infra/ambari-infra-manager/src/main/resources/infraManager.sh index 9f40d5c..65287b2 100644 --- a/ambari-infra/ambari-infra-manager/src/main/resources/infraManager.sh +++ b/ambari-infra/ambari-infra-manager/src/main/resources/infraManager.sh @@ -17,4 +17,4 @@ JVM="java" sdir="`dirname \"$0\"`" -PATH=$JAVA_HOME/bin:$PATH $JVM -classpath "/etc/ambari-infra-manager/conf:$sdir:$sdir/libs/*" org.apache.ambari.infra.InfraManager ${1+"$@"} \ No newline at end of file +PATH=$JAVA_HOME/bin:$PATH nohup $JVM -classpath "/etc/ambari-infra-manager/conf:$sdir:$sdir/libs/*" $INFRA_MANAGER_OPTS org.apache.ambari.infra.InfraManager ${1+"$@"} & \ No newline at end of file