Skip to content

Commit

Permalink
Rancher 2.0 build
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 20, 2017
1 parent 7961e14 commit b808b6f
Show file tree
Hide file tree
Showing 5 changed files with 766 additions and 2,523 deletions.
1 change: 1 addition & 0 deletions agent/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ run_bootstrap()
if [ "$CATTLE_EXEC_AGENT" = "true" ]; then
exec bash $SCRIPT "$@"
else
cat $SCRIPT
bash $SCRIPT "$@"
fi
}
Expand Down
32 changes: 17 additions & 15 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,28 @@ EXPOSE 8080
ENV CATTLE_HOST_API_PROXY_MODE embedded

# Environment variables commonly updated when performing a release
ENV CATTLE_RANCHER_SERVER_VERSION v1.6.10
ENV DEFAULT_CATTLE_API_UI_INDEX //releases.rancher.com/ui/1.6.23
ENV CATTLE_CATTLE_VERSION v0.183.22
ENV CATTLE_RANCHER_CLI_VERSION v0.6.4
ENV CATTLE_RANCHER_COMPOSE_VERSION v0.12.5
ENV DEFAULT_CATTLE_CATALOG_URL='{"catalogs":{"community":{"url":"https://git.rancher.io/community-catalog.git","branch":"master"},"library":{"url":"https://git.rancher.io/rancher-catalog.git","branch":"${RELEASE}"}}}'
ENV CATTLE_RANCHER_SERVER_VERSION v2.0.0-alpha1
ENV DEFAULT_CATTLE_API_UI_INDEX //releases.rancher.com/ui/1.6.17
ENV CATTLE_CATTLE_VERSION v0.184.0
ENV CATTLE_RANCHER_CLI_VERSION v0.6.3
#ENV DEFAULT_CATTLE_CATALOG_URL='{"catalogs":{"community":{"url":"https://git.rancher.io/community-catalog.git","branch":"master"},"library":{"url":"https://git.rancher.io/rancher-catalog.git","branch":"${RELEASE}"}}}'
ENV DEFAULT_CATTLE_CATALOG_URL='{"catalogs":{"community":{"url":"https://git.rancher.io/community-catalog.git","branch":"master"},"library":{"url":"https://github.com/rancher/rancher-catalog.git","branch":"v2.0-development"}}}'

ENV DEFAULT_CATTLE_RANCHER_COMPOSE_LINUX_URL https://releases.rancher.com/compose/${CATTLE_RANCHER_COMPOSE_VERSION}/rancher-compose-linux-amd64-${CATTLE_RANCHER_COMPOSE_VERSION}.tar.gz
ENV DEFAULT_CATTLE_RANCHER_COMPOSE_DARWIN_URL https://releases.rancher.com/compose/${CATTLE_RANCHER_COMPOSE_VERSION}/rancher-compose-darwin-amd64-${CATTLE_RANCHER_COMPOSE_VERSION}.tar.gz
ENV DEFAULT_CATTLE_RANCHER_COMPOSE_WINDOWS_URL https://releases.rancher.com/compose/${CATTLE_RANCHER_COMPOSE_VERSION}/rancher-compose-windows-386-${CATTLE_RANCHER_COMPOSE_VERSION}.zip
ENV DEFAULT_CATTLE_RANCHER_CLI_LINUX_URL https://releases.rancher.com/cli/${CATTLE_RANCHER_CLI_VERSION}/rancher-linux-amd64-${CATTLE_RANCHER_CLI_VERSION}.tar.gz
ENV DEFAULT_CATTLE_RANCHER_CLI_DARWIN_URL https://releases.rancher.com/cli/${CATTLE_RANCHER_CLI_VERSION}/rancher-darwin-amd64-${CATTLE_RANCHER_CLI_VERSION}.tar.gz
ENV DEFAULT_CATTLE_RANCHER_CLI_WINDOWS_URL https://releases.rancher.com/cli/${CATTLE_RANCHER_CLI_VERSION}/rancher-windows-386-${CATTLE_RANCHER_CLI_VERSION}.zip

EXPOSE 3306
ADD https://github.com/rancherio/cattle/releases/download/${CATTLE_CATTLE_VERSION}/cattle.jar /usr/share/cattle/
RUN curl -sfL https://github.com/rancherio/cattle/releases/download/${CATTLE_CATTLE_VERSION}/cattle-${CATTLE_CATTLE_VERSION}.tar.gz | tar xvzf - -C /usr/share/cattle/ --strip-components=1

RUN cd / && for i in $(ls /s6-statics/*static.tar.gz);do tar -C /usr -zxvf $i;done && rm -rf /s6-statics/*static.tar.gz && \
mkdir -p $CATTLE_HOME && \
/usr/share/cattle/cattle.sh extract && \
curl -sL https:${DEFAULT_CATTLE_API_UI_INDEX}.tar.gz | tar xvzf - -C /usr/share/cattle/war --strip-components=1 && \
mkdir -p /usr/share/cattle/war/api-ui && \
curl -sL https:${CATTLE_API_UI_URL}.tar.gz | tar xvzf - -C /usr/share/cattle/war/api-ui --strip-components=1 && \
/usr/share/cattle/install_cattle_binaries && \
mkdir -p /usr/share/cattle/ui/api-ui && \
curl -sL https:${DEFAULT_CATTLE_API_UI_INDEX}.tar.gz | tar xvzf - -C /usr/share/cattle/ui --strip-components=1 && \
curl -sL https:${CATTLE_API_UI_URL}.tar.gz | tar xvzf - -C /usr/share/cattle/ui/api-ui --strip-components=1 && \
jar xvf /usr/share/cattle/lib/cattle-resources-${CATTLE_CATTLE_VERSION}.jar cattle-global.properties && \
bash -x /usr/share/cattle/install_cattle_binaries && \
rm cattle-global.properties && \
curl -sL https://github.com/prometheus/graphite_exporter/releases/download/v0.2.0/graphite_exporter-0.2.0.linux-amd64.tar.gz | tar -xzv -C /usr/bin/ --strip-components=1
RUN cd $CATTLE_HOME && \
echo "$DEFAULT_CATTLE_CATALOG_URL" | sed 's/${RELEASE}/'$(echo $CATTLE_RANCHER_SERVER_VERSION | sed -E 's/(v[0-9]+\.[0-9]+).*/\1-release/')/g > repo.json && \
Expand All @@ -80,7 +78,11 @@ ENV DEFAULT_CATTLE_CATALOG_EXECUTE true
ENV DEFAULT_CATTLE_AUTH_SERVICE_EXECUTE true
ENV DEFAULT_CATTLE_WEBHOOK_SERVICE_EXECUTE true
ENV DEFAULT_CATTLE_SECRETS_API_EXECUTE true
ENV DEFAULT_CATTLE_NETES_AGENT_EXECUTE true
ENV DEFAULT_CATTLE_NETES_EXECUTE true
ENV CATTLE_RANCHER_SERVER_IMAGE rancher/server

ENTRYPOINT ["/usr/bin/entry"]
CMD ["/usr/bin/s6-svscan", "/service"]

ENV REPOS "netes-agent"
135 changes: 15 additions & 120 deletions server/artifacts/cattle.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
#!/bin/bash
set -e
set -e -x

cd /var/lib/cattle

JAR=/usr/share/cattle/cattle.jar
HASH=$(md5sum $JAR | awk '{print $1}')
DEBUG_JAR=/var/lib/cattle/lib/cattle-debug.jar
SCRIPT=/usr/share/cattle/bin/cattle
HASH=$(md5sum $SCRIPT | awk '{print $1}')
LOG_DIR=/var/lib/cattle/logs
export S6_SERVICE_DIR=${S6_SERVICE_DIR:-$S6_SERVICE_DIR}

if [ "$URL" != "" ]
then
echo Downloading $URL
curl -sLf $URL > cattle-download.jar
JAR=cattle-download.jar
fi

if [ -e $DEBUG_JAR ]; then
JAR=$DEBUG_JAR
fi

setup_local_agents()
{
if [ "${CATTLE_USE_LOCAL_ARTIFACTS}" == "true" ]; then
Expand Down Expand Up @@ -77,76 +65,6 @@ setup_mysql()
fi
}

setup_redis()
{
local hosts=""
local i=1

while [ -n "$(eval echo \$REDIS${i}_PORT_6379_TCP_ADDR)" ]; do
local host="$(eval echo \$REDIS${i}_PORT_6379_TCP_ADDR:\$REDIS${i}_PORT_6379_TCP_PORT)"

if [ -n "$hosts" ]; then
hosts="$hosts,$host"
else
hosts="$host"
fi

i=$((i+1))
done

if [ -n "$hosts" ]; then
export CATTLE_REDIS_HOSTS=${CATTLE_REDIS_HOSTS:-$hosts}
fi

if [ -n "$CATTLE_REDIS_HOSTS" ]; then
export CATTLE_MODULE_PROFILE_REDIS=true
fi
}

setup_zk()
{
local hosts=""
local i=1

while [ -n "$(eval echo \$ZK${i}_PORT_2181_TCP_ADDR)" ]; do
local host="$(eval echo \$ZK${i}_PORT_2181_TCP_ADDR:\$ZK${i}_PORT_2181_TCP_PORT)"

if [ -n "$hosts" ]; then
hosts="$hosts,$host"
else
hosts="$host"
fi

i=$((i+1))
done

if [ -n "$hosts" ]; then
export CATTLE_ZOOKEEPER_CONNECTION_STRING=${CATTLE_ZOOKEEPER_CONNECTION_STRING:-$hosts}
fi

if [ -n "$CATTLE_ZOOKEEPER_CONNECTION_STRING" ]; then
export CATTLE_MODULE_PROFILE_ZOOKEEPER=true
fi

if [ -n "$CATTLE_ZOOKEEPER_CONNECTION_STRING" ]; then
local ok=false
for ((i=0; i<=30; i++)); do
local host="$(echo $CATTLE_ZOOKEEPER_CONNECTION_STRING | cut -f1 -d, | cut -f1 -d:)"
local port="$(echo $CATTLE_ZOOKEEPER_CONNECTION_STRING | cut -f1 -d, | cut -f2 -d:)"
echo Waiting for Zookeeper at ${host}:${port}
if [ "$(echo ruok | nc $host $port)" == "imok" ]; then
ok=true
break
fi
sleep 2
done
if [ "$ok" != "true" ]; then
echo Failed waiting for Zookeeper at ${host}:${port}
return 1
fi
fi
}

setup_proxy()
{
if [ -n "$http_proxy" ]; then
Expand Down Expand Up @@ -176,8 +94,6 @@ run() {
setup_prometheus
setup_gelf
setup_mysql
setup_redis
setup_zk
setup_proxy

env | grep CATTLE | grep -v PASS | sort
Expand All @@ -191,29 +107,10 @@ run() {
MX="1g"
fi

HASH_PATH=$(dirname $JAR)/$HASH
if [ -e $HASH_PATH ]; then
if [ -e $HASH_PATH/index.html ]; then
export DEFAULT_CATTLE_API_UI_INDEX=local
fi
exec java ${CATTLE_JAVA_OPTS:--XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Xms128m -Xmx${MX} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_DIR} -Dlogback.bootstrap.level=WARN $PROXY_ARGS $JAVA_OPTS -cp ${HASH_PATH}:${HASH_PATH}/etc/cattle io.cattle.platform.launcher.Main "$@" $ARGS
else
unset DEFAULT_CATTLE_API_UI_JS_URL
unset DEFAULT_CATTLE_API_UI_CSS_URL
exec java ${CATTLE_JAVA_OPTS:--XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Xms128m -Xmx${MX} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_DIR} $PROXY_ARGS $JAVA_OPTS -jar $JAR "$@" $ARGS
fi
}

extract()
{
cd $(dirname $JAR)
java -jar $JAR war
mkdir $HASH
ln -s $HASH war
cd war
unzip ../*.war
unzip $JAR etc\*
rm ../*.war
unset DEFAULT_CATTLE_API_UI_JS_URL
unset DEFAULT_CATTLE_API_UI_CSS_URL
export JAVA_OPTS="${CATTLE_JAVA_OPTS:--XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Xms128m -Xmx${MX} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_DIR} $PROXY_ARGS $JAVA_OPTS"
exec $SCRIPT "$@" $ARGS
}

master()
Expand Down Expand Up @@ -243,18 +140,18 @@ master()
get_source

cd cattle
cattle-binary-pull ./resources/content/cattle-global.properties /usr/bin >/tmp/download.log 2>&1 &
cattle-binary-pull ./modules/resources/src/main/resources/cattle-global.properties /usr/bin >/tmp/download.log 2>&1 &
cd ..

build_source

cd cattle
./mvnw package
wait || {
cat /tmp/download.log
exit 1
}
JAR=$(readlink -f code/packaging/app/target/cattle-app-*.war)
./gradlew distZip
EXTRACT=$(mktemp -d)
ZIP=$(readlink -f modules/main/build/distributions/cattle*.zip)
cd $EXTRACT
unzip $ZIP
SCRIPT=$(readlink -f */bin/cattle)
run
}

Expand Down Expand Up @@ -313,9 +210,7 @@ build_source()

update-rancher-ssl

if [ "$1" = "extract" ]; then
extract
elif [ "$CATTLE_MASTER" = true ]; then
if [ "$CATTLE_MASTER" = true ]; then
master
else
run
Expand Down
19 changes: 5 additions & 14 deletions server/artifacts/install_cattle_binaries
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

PROP=$(readlink -f cattle-global.properties)

mkdir -p /tmp/extracted_cattle
cd /tmp/extracted_cattle

Expand All @@ -16,14 +18,6 @@ install_build_tools()
rm -rf ${tmpdir}
}

unpack_jar()
{
unzip /usr/share/cattle/cattle.jar
mkdir -p res && cd res
unpack200 ../WEB-INF/lib/cattle-resources-*.jar.pack resources.jar
unzip resources.jar
}

clean_up()
{
cd /tmp
Expand All @@ -46,9 +40,6 @@ trap clean_up EXIT SIGINT SIGTERM

install_build_tools

if [ -f "/usr/share/cattle/cattle.jar" ]; then
unpack_jar
/usr/bin/cattle-binary-pull ./cattle-global.properties /usr/bin
local_agents
/usr/bin/cattle-binary-pull ./cattle-global.properties /usr/share/cattle/artifacts agent
fi
/usr/bin/cattle-binary-pull $PROP /usr/bin
local_agents
/usr/bin/cattle-binary-pull $PROP /usr/share/cattle/artifacts agent
3,102 changes: 728 additions & 2,374 deletions server/artifacts/mysql-dump.sql

Large diffs are not rendered by default.

0 comments on commit b808b6f

Please sign in to comment.