Skip to content

Commit

Permalink
squash: Dev Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
turboBasic committed Dec 25, 2023
1 parent 90b851b commit d6d7690
Showing 1 changed file with 62 additions and 49 deletions.
111 changes: 62 additions & 49 deletions runDevEnvironment.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,67 @@
#!/bin/sh

main() {
cd "$(dirname "$0")" || exit
setDefaults
IMAGE_NAME=turbobasic/jenkins-library:latest
USER_NAME=appuser

END_OF_OPTIONS=
while [ -z "$END_OF_OPTIONS" ] && [ -n "$1" ]; do
case "$1" in
--no-build)
NO_BUILD=true
shift;;
--no-run)
NO_RUN=true
shift;;
*)
END_OF_OPTIONS=true
esac
done

if [ -z "$NO_BUILD" ]; then
docker build --rm --tag $IMAGE_NAME \
--build-arg UID="$(id -u)" --build-arg GID="$(id -g)" \
--build-arg VCS_REF="$VCS_REF" \
--build-arg USER_NAME="$USER_NAME" \
--build-arg BUILD_DATE="$(date -u "+%Y-%m-%d %H:%M")" \
.
fi

if [ -z "$NO_RUN" ]; then
# shellcheck disable=SC2086
docker run --rm $DOCKER_OPTIONS \
--volume "$PWD:/app" \
--volume "$GRADLE_HOME_DIR:/home/$USER_NAME/.gradle" \
"$IMAGE_NAME" "$@"
if [ "$CI" != true ] && [ $# = 0 ]; then
echo "Tests execution report: file://$PWD/build/reports/tests/test/index.html"
fi
fi
}

setDefaults() {
NO_BUILD=
NO_RUN=
DOCKER_OPTIONS=
GRADLE_HOME_DIR="$PWD/.gradle"

VCS_REF="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)/$(git rev-parse --short HEAD 2>/dev/null)"
if [ "$VCS_REF" = "/" ]; then
VCS_REF="not-in-version-control"
fi

if [ "$CI" != true ]; then
DOCKER_OPTIONS="--interactive --tty"
GRADLE_HOME_DIR="$HOME/.gradle"
true
fi
}


# Start body of script
set -o errexit
[ "$CI" = "true" ] && set -o xtrace

cd "$(dirname "$0")" || exit

IMAGE_NAME=turbobasic/jenkins-library:latest
USER_NAME=appuser
NO_BUILD=
NO_RUN=
DOCKER_OPTIONS=
GRADLE_HOME_DIR="$PWD/.gradle"
END_OF_OPTIONS=
while [ -z "$END_OF_OPTIONS" ] && [ -n "$1" ]; do
case "$1" in
--no-build)
NO_BUILD=true
shift;;
--no-run)
NO_RUN=true
shift;;
*)
END_OF_OPTIONS=true
esac
done

VCS_REF="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)/$(git rev-parse --short HEAD 2>/dev/null)"
if [ "$VCS_REF" = "/" ]; then
VCS_REF="not-in-version-control"
fi

if [ -z "$NO_BUILD" ]; then
docker build --rm --tag $IMAGE_NAME \
--build-arg UID="$(id -u)" --build-arg GID="$(id -g)" \
--build-arg VCS_REF="$VCS_REF" \
--build-arg USER_NAME="$USER_NAME" \
--build-arg BUILD_DATE="$(date -u "+%Y-%m-%d %H:%M")" \
.
fi

if [ "$CI" != "true" ]; then
DOCKER_OPTIONS="--interactive --tty"
GRADLE_HOME_DIR="$HOME/.gradle"
true
fi
if [ -z "$NO_RUN" ]; then
# shellcheck disable=SC2086
docker run --rm $DOCKER_OPTIONS \
--volume "$PWD:/app" \
--volume "$GRADLE_HOME_DIR:/home/$USER_NAME/.gradle" \
"$IMAGE_NAME" "$@"
echo "Tests execution report: file://$PWD/build/reports/tests/test/index.html"
fi
main "$@"

0 comments on commit d6d7690

Please sign in to comment.