Skip to content

Commit

Permalink
can make docker image, suitable for standalone use or wrapping as an …
Browse files Browse the repository at this point in the history
…app quick-launcher
  • Loading branch information
ahgittin committed Oct 31, 2016
1 parent 058e469 commit 5fe9910
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,68 @@
#
# 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:latest

This comment has been minimized.

Copy link
@andreaturli

andreaturli Oct 31, 2016

Contributor

Do you need ubuntu or alpine with java can be enough?

MAINTAINER Alex Heneveld "alex@cloudsoft.io"

RUN apt-get update

# pre-reqs for Brooklyn
RUN apt-get install -y default-jre

# and for the script
RUN apt-get install -y ssh

ARG debug

# admin tools (optional)
RUN if [ -n "${debug}" ] ; then apt-get install -y vim ; fi
RUN if [ -n "${debug}" ] ; then apt-get install -y zip tar less curl ; fi
RUN if [ -n "${debug}" ] ; then apt-get install -y sudo ; fi

RUN adduser brooklyn
WORKDIR /home/brooklyn

COPY target/files/ .
RUN cp ./bin/br /usr/bin/br
RUN chown -R brooklyn:brooklyn .

USER brooklyn

# remove option not relevant for java v8
RUN sed -i.bk "s/ -XX:MaxPermSize=256m//" bin/brooklyn

ARG application
ARG install_bom

RUN if [ -n "${debug}" ] ; then echo debug=true >> brooklyn-docker-start.opts ; fi
RUN if [ -n "${application}" ] ; then echo application=${application} >> brooklyn-docker-start.opts ; fi

RUN if [ -n "${install_bom}" ] ; then \
echo "brooklyn.catalog:" > conf/brooklyn/default.catalog.bom ; \
echo " items:" >> conf/brooklyn/default.catalog.bom ; \
for x in ${install_bom} ; do \
echo Installing $x to catalog ; \
echo " - "$x >> conf/brooklyn/default.catalog.bom ; \
done \
fi

ENTRYPOINT ["bin/brooklyn-docker-start"]
CMD []

43 changes: 43 additions & 0 deletions docker/Makefile
@@ -0,0 +1,43 @@

BROOKLYN_VERSION=0.10.0-SNAPSHOT

This comment has been minimized.

Copy link
@andreaturli

andreaturli Oct 31, 2016

Contributor

Maybe https://github.com/fabric8io/docker-maven-plugin in a specific profile can replace makefile ?


default: all

clean:
rm -rf target/

prep: clean
mkdir -p target/files/
cp -a ../dist/target/brooklyn-dist/brooklyn/* target/files
cp -a target/files/bin/brooklyn-client-cli/linux.386/br target/files/bin/
cp -a brooklyn-docker-start target/files/bin/

image-only:
docker build -t brooklyncentral/brooklyn:$(BROOKLYN_VERSION) .

image-debug: prep
docker build -t brooklyncentral/brooklyn:${BROOKLYN_VERSION} --build-arg debug=true .

all: prep image-only

# copy this if you want to pass arguments
run:
# BROOKLYN_VERSION_BELOW
docker run -p 8081:8081 brooklyncentral/brooklyn:0.10.0-SNAPSHOT

run-shell:
docker run -ti --entrypoint /bin/bash brooklyncentral/brooklyn:$(BROOKLYN_VERSION)


# an example

example-image-hyperledger: prep
docker build -t brooklyncentral/brooklyn-hyperledger \
--build-arg install_bom="https://raw.githubusercontent.com/cloudsoft/brooklyn-hyperledger/master/docker.bom https://raw.githubusercontent.com/cloudsoft/brooklyn-hyperledger/master/catalog.bom" \
--build-arg application=hyperledger-fabric-multi-cluster-application \
.

example-run-hyperledger:
docker run -p 8081:8081 brooklyncentral/brooklyn-hyperledger


14 changes: 14 additions & 0 deletions docker/README.md
@@ -0,0 +1,14 @@

This folder is not part of the build but exists to facilitate making Docker images containing Brooklyn.

To use, with `docker` tools installed, run `make all` after the Brooklyn `dist` has been built.
Then do `make run` to see the options (or look in [brooklyn-docker-start]()).

When building, you can use:

* `--build-arg debug=true` to install extra tools on the VM and show debug output from our script when booting the container
* `--build-arg application=my-app` to create a container which boots `my-app` by default
* `--build-arg install_bom="http://path/to/file.bom http://path/to/another.bom"` to replace the default catalog with one or more BOM files (useful with `application` above)

See examples in the `Makefile`.

184 changes: 184 additions & 0 deletions docker/brooklyn-docker-start
@@ -0,0 +1,184 @@
#!/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.
#

# This script facilitates setting up brooklyn.properties
# and launching the brooklyn server or the br client as appropriate

# some words/actions treated specially:

# --help shows help on this tool
# --username and --password set up brooklyn.properties
# <id:cred@location> parsed as location and --application appended (if application set?)
# <word> (not starting with -) passed as command to brooklyn along with everything that follows
# anything else (blank or options starting -) passed as args to brooklyn launch

function help() {
echo
# BROOKLYN_VERSION_BELOW
echo 'Apache Brooklyn 0.10.0-SNAPSHOT convenience launcher'${application:+" for ${application}"}
echo
echo 'Usage: [OPTIONS] [--help | LOCATION | COMMAND] [ARGS]'
echo
echo 'The main argument can be any of:'
echo ' --help display this help (or use `help` to show brooklyn help)'
if [ -n "$application" ] ; then
echo ' LOCATION location to launch '${application:-}', in form ID:CRED@CLOUD'
else
echo ' LOCATION location to launch APP (requires `--application APP`), in form ID:CRED@CLOUD'
fi
echo ' COMMAND command to pass to `brooklyn`, default `launch`'
echo
echo 'If no main argument is specified, `brooklyn launch` is used to start Apache Brooklyn.'
echo 'ARGS are passed to the resulting `brooklyn` command. Other OPTIONS available are:'
echo ' [ --username USER ] --password PASS set the default [username and] password'
echo ' [ --debug ] show additional debug info'
if [ -n "$application" ] ; then
echo ' [ --application APP ] override the default application to launch ('${application}')'
else
echo ' [ --application APP ] specify a default application to launch'
fi
echo
}

function make_brooklyn_properties() {
if [ -n "${brooklyn_properties}" ] ; then return ; fi
echo
echo Configuring brooklyn.properties...
export brooklyn_properties=~/.brooklyn/brooklyn.properties
mkdir -p `dirname ${brooklyn_properties}`
touch ${brooklyn_properties}
chmod 600 ${brooklyn_properties}
}

if [ -f brooklyn-docker-start.opts ] ; then
. ./brooklyn-docker-start.opts
fi

while [ -n "$1" ] ; do
case "$1" in

--help)
help
exit 0
;;

--username | --password | --application)
if [ -z "$2" ] ; then
echo ERROR: $1 requires an argument following it
exit 255
fi

export ${1#--}=$2
shift 2
continue
;;

--debug)
export ${1#--}=true
shift
continue
;;

*:*@*)
if [ -z "$application" ] ; then
# environment does not support location syntax
break
fi

location=$1
shift
break
;;

-*)
break
;;

*)
command=$1
shift
break
;;

esac
done

if [ -n "$debug" ] ; then
set -x # echo all commands
fi

if [ -n "$password" ] ; then
make_brooklyn_properties
echo brooklyn.webconsole.security.users=${username:-brooklyn} >> ${brooklyn_properties}
echo brooklyn.webconsole.security.user.${username:-brooklyn}.password=${password} >> ${brooklyn_properties}
# and set up the config file for `br` so it works
echo '{"auth":{"http://localhost:8081":{"password":"'${password}'","username":"'${username:-brooklyn}'"}},"skipSslChecks":false,"target":"http://localhost:8081"}}' > ~/.brooklyn_cli

echo Created user ${username:-brooklyn} and given password

elif [ -n "$username" ] ; then
echo ERROR: password must be specified if providing a username
exit 255
fi


if [ ! -f ~/.ssh/id_rsa ] ; then
echo
echo Creating ssh key to access remote machines...
mkdir -p ~/.ssh/
chmod 700 ~/.ssh/
if [ -n "$debug" ] ; then
ssh-keygen -f ~/.ssh/id_rsa -P ""
else
ssh-keygen -f ~/.ssh/id_rsa -P "" > ~/.ssh/id_rsa.log 2> ~/.ssh/id_rsa.log2
fi

cat ~/.ssh/id_rsa
fi


ARGS=(${command:-launch} $@)

if [[ -n "$application" && -n "$location" ]] ; then
echo
echo Launching blueprint...
creds=${location/@*/}
cat > initial.yaml << EOF
name: $application
services:
- type: $application
location:
${location/*@/}:
identity: ${creds/:*/}
credential: ${creds/*:/}
EOF
cat initial.yaml
ARGS+=(--app file://`pwd -P`/initial.yaml)
fi

# launch brooklyn
echo
echo Launching '`'brooklyn "${ARGS[@]}"'`'...

. bin/brooklyn "${ARGS[@]}"

0 comments on commit 5fe9910

Please sign in to comment.