Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for settings.xml #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions 1.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ RUN yum install -y --enablerepo=centosplus \
tar -zx -C /usr/local) && \
ln -sf /usr/local/apache-maven-$MAVEN_VERSION/bin/mvn /usr/local/bin/mvn && \
mkdir -p /opt/app-root/source && \
mkdir -p /opt/s2i/destination
mkdir -p /opt/s2i/destination && \
mkdir -p $HOME/.m2

# Copy the S2I scripts from the specific language image to /usr/local/sti
COPY ./s2i/bin/ $STI_SCRIPTS_PATH

# Copy basic Maven settings
ADD ./contrib/settings.xml $HOME/.m2/

# Create wildfly swarm group and user, set file ownership to that user.
RUN chmod -R go+rw /opt/s2i/destination
RUN chown -R 1001:0 $HOME && \
chmod -R ug+rw $HOME && \
chmod -R g+rw /opt/s2i/destination

USER 1001

Expand Down
131 changes: 131 additions & 0 deletions 1.0/contrib/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<mirrors>
<!-- ### configured mirrors ### -->
</mirrors>

<proxies>
<!-- ### configured http proxy ### -->
</proxies>

<profiles>

<!-- JBoss Community Maven repository -->
<profile>
<id>jboss-community-repository</id>
<activation>
<property>
<name>com.redhat.xpaas.repo.jbossorg</name>
<value/>
</property>
</activation>
<repositories>
<repository>
<id>jboss-community-repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-community-plugin-repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

<!-- JBoss Community Maven repository (HTTP version, disabled by default) -->
<profile>
<id>jboss-community-repository-insecure</id>
<repositories>
<repository>
<id>jboss-community-repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-community-plugin-repository</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

<!-- Override the repository "central" from the Maven Super POM, to set HTTPS by default -->
<profile>
<id>securecentral</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>

<!-- central repositories via HTTP. Disabled by default. -->
<profile>
<id>insecurecentral</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>

</profiles>
<activeProfiles>
<activeProfile>securecentral</activeProfile>
</activeProfiles>
</settings>

66 changes: 65 additions & 1 deletion 1.0/s2i/bin/assemble
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#!/bin/bash

function configure_proxy() {
if [ -n "$HTTP_PROXY_HOST" -a -n "$HTTP_PROXY_PORT" ]; then
xml="<proxy>\
<id>genproxy</id>\
<active>true</active>\
<protocol>http</protocol>\
<host>$HTTP_PROXY_HOST</host>\
<port>$HTTP_PROXY_PORT</port>"
if [ -n "$HTTP_PROXY_USERNAME" -a -n "$HTTP_PROXY_PASSWORD" ]; then
xml="$xml\
<username>$HTTP_PROXY_USERNAME</username>\
<password>$HTTP_PROXY_PASSWORD</password>"
fi
if [ -n "$HTTP_PROXY_NONPROXYHOSTS" ]; then
xml="$xml\
<nonProxyHosts>$HTTP_PROXY_NONPROXYHOSTS</nonProxyHosts>"
fi
xml="$xml\
</proxy>"
sed -i "s|<!-- ### configured http proxy ### -->|$xml|" $HOME/.m2/settings.xml
fi
}

# insert settings for mirrors/repository managers into settings.xml if supplied
function configure_mirrors() {
if [ -n "$MAVEN_MIRROR_URL" ]; then
xml="<mirror>\
<id>mirror.default</id>\
<url>$MAVEN_MIRROR_URL</url>\
<mirrorOf>external:*</mirrorOf>\
</mirror>"
sed -i "s|<!-- ### configured mirrors ### -->|$xml|" $HOME/.m2/settings.xml
fi
}

# restore maven dependencies downloaded in a previous build,
# so they do not have to be downloaded again.
# /opt/s2i/destination/artifacts will only be present in the incremental build scenario
Expand All @@ -21,6 +56,20 @@ cp -Rf /opt/s2i/destination/src/. $LOCAL_SOURCE_DIR
chgrp -R 0 $LOCAL_SOURCE_DIR
chmod -R g+rw $LOCAL_SOURCE_DIR

if [ -d $LOCAL_SOURCE_DIR/configuration ]; then
echo "Copying config files from project..."

if [ -f $LOCAL_SOURCE_DIR/configuration/settings.xml ]; then
mkdir -p $HOME/.m2
mv $LOCAL_SOURCE_DIR/configuration/settings.xml $HOME/.m2
fi

cp -v $LOCAL_SOURCE_DIR/configuration/* $JBOSS_HOME/standalone/configuration/
fi

configure_proxy
configure_mirrors

# If a pom.xml is present, this is a normal build scenario
# so run maven.
if [ -f "$LOCAL_SOURCE_DIR/pom.xml" ]; then
Expand All @@ -33,11 +82,26 @@ if [ -f "$LOCAL_SOURCE_DIR/pom.xml" ]; then
if [ -z "$MAVEN_ARGS" ]; then
export MAVEN_ARGS="-U install -Popenshift -DskipTests"
fi
if [ -z "$MAVEN_ARGS_APPEND" ]; then
if [ ! -z "$MAVEN_ARGS_APPEND" ]; then
export MAVEN_ARGS="$MAVEN_ARGS $MAVEN_ARGS_APPEND"
fi
echo "Found pom.xml... attempting to build with 'mvn ${MAVEN_ARGS}'"

# If MAVEN_SETTINGS specified will always add to MAVEN_ARGS
# Can be relative to application root
# Can be global to image
if [ -z "$MAVEN_SETTINGS" ]; then
export MAVEN_ARGS="$MAVEN_ARGS -s $HOME/.m2/settings.xml"
else
if [[ "$MAVEN_SETTINGS" = /* ]]; then
[ ! -e "$MAVEN_SETTINGS" ] && echo "Specified settings file does not exist in the image. [$MAVEN_SETTINGS]" && exit 1
export MAVEN_ARGS="$MAVEN_ARGS -s $MAVEN_SETTINGS"
else
[ ! -e "$LOCAL_SOURCE_DIR/$MAVEN_SETTINGS" ] && echo "Specified settings file does not exist in your source code. [$MAVEN_SETTINGS]" && exit 1
export MAVEN_ARGS="$MAVEN_ARGS -s $LOCAL_SOURCE_DIR/$MAVEN_SETTINGS"
fi
fi

mvn --version
mvn $MAVEN_ARGS

Expand Down
10 changes: 5 additions & 5 deletions 1.0/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
LOCAL_SOURCE_DIR=${HOME}

if [ -z "$SWARM_JAR" ]; then
SWARM_JAR="target/*-swarm.jar"
SWARM_JAR="`find $LOCAL_SOURCE_DIR -name *-swarm.jar`"
else
SWARM_JAR="`$LOCAL_SOURCE_DIR/$SWARM_JAR`"
fi

BIND_IP=`hostname -i`

export OPENSHIFT_KUBE_PING_NAMESPACE=$OPENSHIFT_BUILD_NAMESPACE

exec java -Dswarm.bind.address=$BIND_IP -Dswarm.http.port=8080 \
exec java -Dswarm.bind.address=0.0.0.0 -Dswarm.http.port=8080 \
-Dswarm.port.offset=0 -Djava.net.preferIPv4Stack=true \
$SWARM_JVM_ARGS -jar $LOCAL_SOURCE_DIR/$SWARM_JAR $SWARM_JAR_ARGS
$SWARM_JVM_ARGS -jar $SWARM_JAR $SWARM_JAR_ARGS