Skip to content

Instantly share code, notes, and snippets.

@osowski osowski/Dockerfile
Created Jul 2, 2015

What would you like to do?
WebSphere Liberty Dockerfile & custom scripts (executing prior to server start) updating server configuration files with IBM Bluemix service credential information dynamically
RUN apt-get update && apt-get install -y \
git \
# Add a SSH key, this will allow to perform SSH into containers
COPY /root/.ssh/
RUN chmod 600 /root/.ssh/ \
&& cat /root/.ssh/ >> /root/.ssh/authorized_keys \
&& rm -rf /opt/ibm/wlp/usr/servers/defaultServer/apps/* \
&& mkdir -p /opt/ibm/wlp/usr/extension/lib
# Extract binaries from public IDS repo
RUN rm -rf /src
RUN mkdir /src
# Clone MobileFirst Platform Foundation application into the local image
RUN git clone --verbose --progress /src/wishlist
COPY /src/
COPY /src/
RUN chmod +x /src/
CMD ["/src/"]
# Accept Liberty license
python /src/ /opt/ibm/wlp/usr/servers/defaultServer/server.xml /opt/ibm/wlp/usr/servers/defaultServer/server.xml
/opt/ibm/wlp/bin/server run defaultServer
## Usage: python [input server.xml] [output server.xml]
## This script will extract the appropriate Cloudant service instance credentials
## from the VCAP_SERVICES environment variable inside a running container. It will
## then update those credentials in the server.xml file, passed in as the primary parameter.
## These credentials are used to configure the Cloudant Data Proxy inside the MobileFirst
## Foundations Platform and saved in the output file passed in as the second parameter.
import sys
import os
import json
from lxml import etree as ETree
from io import StringIO
if "VCAP_SERVICES" in os.environ:
vcaps = json.loads(os.environ["VCAP_SERVICES"])
if "cloudantNoSQLDB" in vcaps:
hostname = vcaps["cloudantNoSQLDB"][0]["credentials"]["host"]
username = vcaps["cloudantNoSQLDB"][0]["credentials"]["username"]
password = vcaps["cloudantNoSQLDB"][0]["credentials"]["password"]
port = vcaps["cloudantNoSQLDB"][0]["credentials"]["port"]
protocol = vcaps["cloudantNoSQLDB"][0]["credentials"]["url"]
protocol = protocol.split(":")[0]
serverxml = sys.argv[1]
tree = ETree.parse(serverxml)
root = tree.getroot()
#set hostname
for element in root.xpath("/server/jndiEntry[@jndiName='datastore/CloudantProxyDbAccount']"):
element.attrib['value'] = hostname
#set protocol
for element in root.xpath("/server/jndiEntry[@jndiName='datastore/CloudantProtocol']"):
element.attrib['value'] = protocol
#set port
for element in root.xpath("/server/jndiEntry[@jndiName='datastore/CloudantPort']"):
element.attrib['value'] = str(port)
#set username
for element in root.xpath("/server/jndiEntry[@jndiName='datastore/CloudantProxyDbAccountUser']"):
element.attrib['value'] = username
#set password
for element in root.xpath("/server/jndiEntry[@jndiName='datastore/CloudantProxyDbAccountPassword']"):
element.attrib['value'] = password
tree.write(sys.argv[2], pretty_print=True, xml_declaration=True);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.