1
0
mirror of https://github.com/rancher/docs.git synced 2026-02-06 03:45:54 +01:00
Files
docs/scripts/dev

126 lines
2.5 KiB
Plaintext
Raw Permalink Normal View History

2018-04-12 13:59:16 -07:00
#!/bin/bash
2018-05-08 11:53:24 -07:00
set -e
2018-04-12 13:59:16 -07:00
2018-04-12 21:48:52 -07:00
PORT=9001
2018-05-08 11:53:24 -07:00
IMAGE=rancher/docs
TAG=dev
2018-04-12 13:59:16 -07:00
THEME=
2018-07-02 15:07:32 -07:00
BUILD_BUILD=
BUILD_DEV=
2019-02-13 16:28:48 -07:00
SKIP_PULL=
2018-07-02 15:07:32 -07:00
UPLOAD=
2018-04-12 13:59:16 -07:00
# cd to app root
CWD=$(dirname $0)
if [[ `basename $(pwd)` = 'scripts' ]]; then
cd ../
else
cd `dirname $CWD`
fi
print_help()
{
cat 1>&2 <<EOF
Usage:
2019-02-13 16:28:48 -07:00
[-b | -d] [-p PORT] [-s] [-t DIR] [-u]
2018-04-12 13:59:16 -07:00
2018-07-02 15:07:32 -07:00
-b - Build the build & dev images instead of pulling from the registry
-d - Build the dev image instead of pulling from the registry
2018-04-12 13:59:16 -07:00
-p PORT - Port to listen on
2019-02-13 16:28:48 -07:00
-s - Skip pulling build/dev images
2018-04-12 13:59:16 -07:00
-t DIR - Use DIR to for the theme, to devlop the theme at the same time
2019-02-13 16:28:48 -07:00
-u - Upload/push the build image after building
2018-04-12 13:59:16 -07:00
EOF
}
echoerr()
{
printf "%s\n" "$*" >&2;
}
absolute() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
2019-02-13 16:28:48 -07:00
while getopts ":bdp:st:u" opt;do
2018-04-12 13:59:16 -07:00
case $opt in
2018-05-08 11:53:24 -07:00
b)
2018-07-02 15:07:32 -07:00
BUILD_BUILD="true"
BUILD_DEV="true"
;;
d)
BUILD_DEV="true"
2018-05-08 11:53:24 -07:00
;;
2018-04-12 13:59:16 -07:00
p)
PORT="${OPTARG}"
;;
2019-02-13 16:28:48 -07:00
s)
SKIP_PULL="true"
;;
2018-04-12 13:59:16 -07:00
t)
THEME="${OPTARG}"
;;
2018-07-02 15:07:32 -07:00
u)
UPLOAD="true"
;;
2018-04-12 13:59:16 -07:00
\?)
2018-10-12 07:08:55 +02:00
echoerr "Invalid arguments"
2018-04-12 13:59:16 -07:00
print_help
exit 1
;;
:)
echoerr "Option -${OPTARG} requires an argument."
print_help
exit 1
;;
esac
done
THEMEVOLUME=""
if [[ "$THEME" ]]; then
echo "Using theme from ${THEME}"
ABSOLUTE=$(absolute $THEME)
THEMEVOLUME="-v ${ABSOLUTE}:/run/node_modules/rancher-website-theme"
fi
2019-02-13 16:28:48 -07:00
if [[ "$BUILD_BUILD" ]]; then
2018-07-02 15:07:32 -07:00
echo "Building ${IMAGE}:build"
2019-02-13 16:28:48 -07:00
docker build --no-cache -f Dockerfile.build --build-arg TWITTER_CONSUMER=${TWITTER_CONSUMER} --build-arg TWITTER_SECRET=${TWITTER_SECRET} -t ${IMAGE}:build .
2018-07-02 15:07:32 -07:00
if [[ "$UPLOAD" ]]; then
docker push ${IMAGE}:build
fi
2019-02-13 16:28:48 -07:00
elif [[ "$SKIP_PULL" ]]; then
echo "Skipping pull of ${IMAGE}:build"
else
echo "Pulling ${IMAGE}:build"
docker pull ${IMAGE}:build
2018-07-02 15:07:32 -07:00
fi
2019-02-13 16:28:48 -07:00
if [[ "$BUILD_DEV" ]]; then
2018-05-08 11:53:24 -07:00
TAG=local
2018-07-02 15:07:32 -07:00
echo "Building ${IMAGE}:${TAG}"
2018-05-08 11:53:24 -07:00
docker build -f Dockerfile.dev -t ${IMAGE}:${TAG} .
2019-02-13 16:28:48 -07:00
elif [[ "$SKIP_PULL" ]]; then
echo "Skipping pull of ${IMAGE}:${TAG}"
else
echo "Pulling ${IMAGE}:${TAG}"
docker pull ${IMAGE}:${TAG}
2018-05-08 11:53:24 -07:00
fi
echo "Starting server on http://localhost:${PORT}"
2019-02-13 16:28:48 -07:00
docker run --rm -p ${PORT}:${PORT} -it \
-v $(pwd)/archetypes:/run/archetypes \
-v $(pwd)/assets:/run/assets \
-v $(pwd)/content:/run/content \
-v $(pwd)/data:/run/data \
-v $(pwd)/layouts:/run/layouts \
-v $(pwd)/scripts:/run/scripts \
-v $(pwd)/static:/run/static \
-v $(pwd)/.git:/run/.git \
-v $(pwd)/config.toml:/run/config.toml \
${THEMEVOLUME} ${IMAGE}:${TAG} --port=${PORT}