Update git and docker scripts
This commit is contained in:
Родитель
ec41f9c5aa
Коммит
a069258f5a
|
@ -1,6 +1,13 @@
|
|||
# Bash scripts
|
||||
# Auto-detect text files, ensure they use LF.
|
||||
* text=auto eol=lf
|
||||
|
||||
# Bash scripts
|
||||
*.sh text eol=lf
|
||||
|
||||
scripts/build text eol=lf
|
||||
|
||||
scripts/docker/build text eol=lf
|
||||
scripts/docker/publish text eol=lf
|
||||
scripts/docker/run text eol=lf
|
||||
|
||||
scripts/git/setup text eol=lf
|
||||
|
|
|
@ -13,6 +13,18 @@ error() {
|
|||
echo -e "${COL_ERR}$1 ${COL_NO}"
|
||||
}
|
||||
|
||||
check_dependency_npm() {
|
||||
set +e
|
||||
TEST=$(which npm)
|
||||
if [[ -z "$TEST" ]]; then
|
||||
echo "ERROR: 'npm' command not found."
|
||||
echo "Install Node.js and npm and make sure the 'npm' command is in the PATH."
|
||||
echo "Node.js and npm installation: https://www.npmjs.com/get-npm"
|
||||
exit 1
|
||||
fi
|
||||
set -e
|
||||
}
|
||||
|
||||
check_dependency_docker() {
|
||||
if ! which docker >/dev/null 2>&1 ; then
|
||||
echo "ERROR: 'docker' command not found."
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash -e
|
||||
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
|
||||
source "$APP_HOME/scripts/.functions.sh"
|
||||
|
||||
check_dependency_npm
|
||||
|
||||
export CI=true
|
||||
|
||||
## broken
|
||||
# npm test
|
||||
|
||||
## broken
|
||||
# npm flow
|
|
@ -1,14 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env bash -e
|
||||
|
||||
# Usage:
|
||||
# ./scripts/docker/run : Starts the stable version
|
||||
# ./scripts/docker/run testing : Starts the testing version
|
||||
|
||||
# Note: use lowercase names for the Docker images
|
||||
DOCKER_IMAGE="azureiotpcs/pcs-remote-monitoring-webui"
|
||||
STABLE_VERSION="1.0.0-preview"
|
||||
|
||||
set -e
|
||||
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
|
||||
|
||||
# The version is stored in a file, to avoid hardcoding it in multiple places
|
||||
APP_VERSION=$(cat "$APP_HOME/version")
|
||||
|
||||
echo "Starting Remote Monitoring Web UI ..."
|
||||
docker run -it -p 10080:80 -p 10443:443 $DOCKER_IMAGE:$APP_VERSION
|
||||
if [ "$1" == "testing" ]; then
|
||||
echo "Starting Remote Monitoring Web UI [testing version] ..."
|
||||
docker run -it -p 10080:80 -p 10443:443 $DOCKER_IMAGE:testing
|
||||
else
|
||||
echo "Starting Remote Monitoring Web UI [$STABLE_VERSION] ..."
|
||||
docker run -it -p 10080:80 -p 10443:443 $DOCKER_IMAGE:$STABLE_VERSION
|
||||
fi
|
|
@ -1,16 +1,27 @@
|
|||
@ECHO off & setlocal enableextensions enabledelayedexpansion
|
||||
|
||||
:: Usage:
|
||||
:: scripts\docker\run : Starts the stable version
|
||||
:: scripts\docker\run testing : Starts the testing version
|
||||
|
||||
:: Note: use lowercase names for the Docker images
|
||||
SET DOCKER_IMAGE="azureiotpcs/pcs-remote-monitoring-webui"
|
||||
SET DOCKER_IMAGE=azureiotpcs/pcs-remote-monitoring-webui
|
||||
SET STABLE_VERSION=1.0.0-preview
|
||||
|
||||
:: strlen("\scripts\docker\") => 16
|
||||
SET APP_HOME=%~dp0
|
||||
SET APP_HOME=%APP_HOME:~0,-16%
|
||||
IF "%1"=="" goto :STABLE
|
||||
IF "%1"=="testing" goto :TESTING
|
||||
|
||||
:: The version is stored in a file, to avoid hardcoding it in multiple places
|
||||
set /P APP_VERSION=<%APP_HOME%/version
|
||||
:STABLE
|
||||
echo Starting Remote Monitoring Web UI [%STABLE_VERSION%] ...
|
||||
docker run -it -p 10080:80 -p 10443:443 %DOCKER_IMAGE%:%STABLE_VERSION%
|
||||
goto :END
|
||||
|
||||
echo Starting Remote Monitoring Web UI ...
|
||||
docker run -it -p 10080:80 -p 10443:443 %DOCKER_IMAGE%:%APP_VERSION%
|
||||
:TESTING
|
||||
echo Starting Remote Monitoring Web UI [testing version] ...
|
||||
docker run -it -p 10080:80 -p 10443:443 %DOCKER_IMAGE%:testing
|
||||
goto :END
|
||||
|
||||
|
||||
:END
|
||||
|
||||
endlocal
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
header() {
|
||||
echo -e "\n### $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "$1"
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash -e
|
||||
|
||||
# Sometimes when creating bash scripts in Windows, bash scripts will not have
|
||||
# the +x flag carried over to Linux/MacOS. This script should help setting the
|
||||
# permission flags right.
|
||||
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
|
||||
cd $APP_HOME
|
||||
|
||||
set +e
|
||||
|
||||
chmod ugo+x ./scripts/build 2> /dev/null
|
||||
chmod ugo+x ./scripts/docker/build 2> /dev/null
|
||||
chmod ugo+x ./scripts/docker/run 2> /dev/null
|
||||
chmod ugo+x ./scripts/docker/publish 2> /dev/null
|
||||
chmod ugo+x ./scripts/docker/content/*.sh 2> /dev/null
|
||||
chmod ugo+x ./scripts/git/setup 2> /dev/null
|
||||
chmod ugo+x ./scripts/git/*.sh 2> /dev/null
|
||||
|
||||
if [ -d ./scripts/iothub ]; then
|
||||
chmod ugo+x ./scripts/iothub/*.sh 2> /dev/null
|
||||
fi
|
||||
|
||||
git update-index --chmod=+x ./scripts/build
|
||||
git update-index --chmod=+x ./scripts/docker/build
|
||||
git update-index --chmod=+x ./scripts/docker/run
|
||||
git update-index --chmod=+x ./scripts/docker/publish
|
||||
git update-index --chmod=+x ./scripts/docker/content/*.sh
|
||||
git update-index --chmod=+x ./scripts/git/setup
|
||||
git update-index --chmod=+x ./scripts/git/*.sh
|
||||
|
||||
if [ -d ./scripts/iothub ]; then
|
||||
git update-index --chmod=+x ./scripts/iothub/*.sh
|
||||
fi
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash -e
|
||||
|
||||
# Path relative to .git/hooks/
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
|
||||
cd $APP_HOME
|
||||
|
||||
./scripts/git/pre-commit.sh
|
||||
|
||||
set +e
|
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env bash -e
|
||||
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
|
||||
source "$APP_HOME/scripts/git/.functions.sh"
|
||||
|
||||
cd $APP_HOME
|
||||
echo "Current folder: `pwd`"
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
check_filenames() {
|
||||
header "Checking filenames..."
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
set +e
|
||||
if test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 ; then
|
||||
error "Attempt to add a non-ASCII file name. This can cause problems on other platforms."
|
||||
exit 1
|
||||
fi
|
||||
set -e
|
||||
}
|
||||
|
||||
check_whitespaces() {
|
||||
header "Checking white spaces and line separators..."
|
||||
git diff-index --check --cached $against --
|
||||
}
|
||||
|
||||
check_do_not_commit() {
|
||||
PATTERN1="DONOT"
|
||||
PATTERN1="${PATTERN1}COMMIT"
|
||||
PATTERN2="DO NOT"
|
||||
PATTERN2="${PATTERN2} COMMIT"
|
||||
PATTERN3="DONT"
|
||||
PATTERN3="${PATTERN3}COMMIT"
|
||||
PATTERN4="DONT"
|
||||
PATTERN4="${PATTERN4} COMMIT"
|
||||
PATTERN5="DON'T"
|
||||
PATTERN5="${PATTERN5} COMMIT"
|
||||
|
||||
header "Checking diff for comments containing '${PATTERN1}'..."
|
||||
|
||||
set +e
|
||||
|
||||
PATT="^\+.*${PATTERN1}.*$"
|
||||
diffstr=`git diff --cached $against | grep -ie "$PATT"`
|
||||
if [[ -n "$diffstr" ]]; then
|
||||
error "You have left '${PATTERN1}' in your changes, you can't commit until it has been removed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATT="^\+.*${PATTERN2}.*$"
|
||||
diffstr=`git diff --cached $against | grep -ie "$PATT"`
|
||||
if [[ -n "$diffstr" ]]; then
|
||||
error "You have left '${PATTERN2}' in your changes, you can't commit until it has been removed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATT="^\+.*${PATTERN3}.*$"
|
||||
diffstr=`git diff --cached $against | grep -ie "$PATT"`
|
||||
if [[ -n "$diffstr" ]]; then
|
||||
error "You have left '${PATTERN3}' in your changes, you can't commit until it has been removed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATT="^\+.*${PATTERN4}.*$"
|
||||
diffstr=`git diff --cached $against | grep -ie "$PATT"`
|
||||
if [[ -n "$diffstr" ]]; then
|
||||
error "You have left '${PATTERN4}' in your changes, you can't commit until it has been removed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATT="^\+.*${PATTERN5}.*$"
|
||||
diffstr=`git diff --cached $against | grep -ie "$PATT"`
|
||||
if [[ -n "$diffstr" ]]; then
|
||||
error "You have left '${PATTERN5}' in your changes, you can't commit until it has been removed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -e
|
||||
}
|
||||
|
||||
verify_build() {
|
||||
header "Verifying build..."
|
||||
|
||||
cd $APP_HOME/scripts
|
||||
./build
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
error "Some tests failed."
|
||||
exit 1
|
||||
else
|
||||
header "All tests passed"
|
||||
fi
|
||||
}
|
||||
|
||||
check_filenames
|
||||
check_whitespaces
|
||||
check_do_not_commit
|
||||
verify_build
|
||||
|
||||
set +e
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash -e
|
||||
|
||||
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && cd .. && pwd )/"
|
||||
|
||||
failed() {
|
||||
echo "Git hooks setup failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
install_precommit_hook() {
|
||||
echo "Adding pre-commit hook..."
|
||||
|
||||
cd $APP_HOME/.git || failed
|
||||
mkdir -p hooks || failed
|
||||
cd hooks || failed
|
||||
rm -f pre-commit
|
||||
|
||||
cp -p $APP_HOME/scripts/git/pre-commit-runner.sh ./pre-commit || failed
|
||||
|
||||
chmod 755 ./pre-commit
|
||||
echo "Done."
|
||||
}
|
||||
|
||||
git_setup() {
|
||||
git config --local core.whitespace trailing-space,space-before-tab
|
||||
git config --local core.autocrlf false
|
||||
git config --local core.eol lf
|
||||
git config --local apply.whitespace fix
|
||||
|
||||
git config --local alias.st status
|
||||
git config --local alias.co checkout
|
||||
git config --local alias.ci commit
|
||||
|
||||
git config --local alias.branches 'branch -v -a'
|
||||
git config --local alias.lg 'log --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --date=relative'
|
||||
git config --local alias.lgx 'log --stat'
|
||||
git config --local alias.lgt 'log --graph --pretty=oneline --oneline --all'
|
||||
git config --local alias.lg1 'log --reverse --pretty=oneline'
|
||||
git config --local alias.stashdiff 'stash show --patience'
|
||||
}
|
||||
|
||||
install_precommit_hook
|
||||
git_setup
|
||||
|
||||
set +e
|
|
@ -0,0 +1,59 @@
|
|||
@ECHO off & setlocal enableextensions enabledelayedexpansion
|
||||
|
||||
:: strlen("\scripts\git\") => 13
|
||||
SET APP_HOME=%~dp0
|
||||
SET APP_HOME=%APP_HOME:~0,-13%
|
||||
|
||||
cd %APP_HOME%
|
||||
|
||||
:: Install git hook
|
||||
echo Adding pre-commit hook...
|
||||
mkdir .git\hooks\ > NUL 2>&1
|
||||
del /F .git\hooks\pre-commit > NUL 2>&1
|
||||
copy scripts\git\pre-commit-runner.sh .git\hooks\pre-commit
|
||||
IF %ERRORLEVEL% NEQ 0 GOTO FAIL
|
||||
echo Done.
|
||||
goto :GIT_SETUP
|
||||
|
||||
:: Git setup
|
||||
git config --local core.whitespace trailing-space,space-before-tab
|
||||
git config --local core.autocrlf false
|
||||
git config --local core.eol lf
|
||||
git config --local apply.whitespace fix
|
||||
|
||||
git config --local alias.st status
|
||||
git config --local alias.co checkout
|
||||
git config --local alias.ci commit
|
||||
|
||||
git config --local alias.branches "branch -v -a"
|
||||
git config --local alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
|
||||
git config --local alias.lgx "log --stat"
|
||||
git config --local alias.lgt "log --graph --pretty=oneline --oneline --all"
|
||||
git config --local alias.lg1 "log --reverse --pretty=oneline"
|
||||
git config --local alias.stashdiff "stash show --patience"
|
||||
|
||||
goto :END
|
||||
|
||||
|
||||
:USAGE
|
||||
echo ERROR: sandboxing mode not specified.
|
||||
echo.
|
||||
echo The pre-commit hook can run in two different modes:
|
||||
echo Without sandbox: the build process runs using .NET Core and other dependencies from your workstation
|
||||
echo With sandbox: the build process runs inside a Docker container so you don't need to install .NET Core and other dependencies
|
||||
echo.
|
||||
echo Usage:
|
||||
echo .\scripts\git\setup
|
||||
echo .\scripts\git\setup --no-sandbox
|
||||
echo .\scripts\git\setup --with-sandbox
|
||||
exit /B 1
|
||||
|
||||
|
||||
:FAIL
|
||||
echo Command failed
|
||||
endlocal
|
||||
exit /B 1
|
||||
|
||||
|
||||
:END
|
||||
endlocal
|
Загрузка…
Ссылка в новой задаче