build.cmd 3.98 KB
Newer Older
1 2 3 4 5 6 7
@echo off

@set JAVA_ARGS=-Xms500m -Xmx1g
@set CAS_DIR=\etc\cas
@set CONFIG_DIR=\etc\cas\config
@set SHELL_DIR=build\libs
@set BUILD_DIR=build\libs
hdeadman's avatar
hdeadman committed
8
@set DOCKER_ORG=org.apereo.cas
9 10 11 12 13 14 15 16 17 18
@if "%PROFILES%" == "" @set PROFILES=standalone

@rem Call this script with DNAME and CERT_SUBJ_ALT_NAMES already set to override
@if "%DNAME%" == "" set DNAME=CN=cas.example.org,OU=Example,OU=Org,C=US
@rem List other host names or ip addresses you want in your certificate, may help with host name verification, 
@rem   if client apps make https connection for ticket validation and compare name in cert (include sub. alt. names) 
@rem   to name used to access CAS
@if "%CERT_SUBJ_ALT_NAMES%" == "" set CERT_SUBJ_ALT_NAMES=dns:example.org,dns:localhost,dns:%COMPUTERNAME%,ip:127.0.0.1

@rem Check for gradle in path, use it if found, otherwise use gradle wrapper
19
@set GRADLE_CMD=gradle
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
@where /q gradle
@if %ERRORLEVEL% neq 0 set GRADLE_CMD=.\gradlew.bat

@if "%1" == "" call:help
@if "%1" == "clean" (
    call:clean
    shift
)
@if "%1" == "copy" call:copy
@if "%1" == "package" call:package %2 %3 %4
@if "%1" == "debug" call:debug %2 %3 %4
@if "%1" == "run" call:run %2 %3 %4 & goto :EOF
@if "%1" == "refresh" call:refresh %2 %3 %4
@if "%1" == "help" call:help
@if "%1" == "gencert" call:gencert
@if "%1" == "cli" call:cli
@if "%1" == "debugcli" call:debugcli
@if "%1" == "dependencies" call:dependencies
38 39
@if "%1" == "dockerimage" call:dockerimage
@if "%1" == "dockerrun" call:dockerrun
hdeadman's avatar
hdeadman committed
40 41
@if "%1" == "dockerrunsh" call:dockerrunsh
@if "%1" == "dockerexecsh" call:dockerexecsh
42 43 44 45 46 47 48 49 50 51 52 53 54

@rem function section starts here
@goto :EOF

:copy
    @echo "Creating configuration directory under %CONFIG_DIR%"
    if not exist %CONFIG_DIR% mkdir %CONFIG_DIR%

    @echo "Copying configuration files from etc/cas to /etc/cas"
    xcopy /S /Y etc\cas\* \etc\cas
@goto :EOF

:help
hdeadman's avatar
hdeadman committed
55
    @echo "Usage: build.cmd [copy|clean|package|refresh|run|debug|gencert|dockerimage|dockerrunsh|dockerexecsh] [optional extra args for gradle]"
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    @echo "To get started on a clean system, run 'build.cmd gencert && build.cmd copy && build.cmd run'"
    @echo "Note that using the copy or gencert arguments will create and/or overwrite the %CAS_DIR% which is outside this project"
@goto :EOF

:clean
    call %GRADLE_CMD% clean %1 %2 %3
    exit /B %ERRORLEVEL%
@goto :EOF

:package
    call %GRADLE_CMD% build %1 %2 %3
    exit /B %ERRORLEVEL%
@goto :EOF

:debug
    call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n -jar %BUILD_DIR%\cas.war --spring.profiles.active=%PROFILES%
@goto :EOF

:run
    call:package %1 %2 %3 & java %JAVA_ARGS% -jar %BUILD_DIR%\cas.war --spring.profiles.active=%PROFILES%
@goto :EOF

:refresh
    call:package --refresh-dependencies %1 %2
@goto :EOF

82 83 84 85 86 87 88
:dockerimage
    call %GRADLE_CMD% clean build jibDockerBuild
@goto :EOF

:dockerrun
    docker stop cas
    docker rm cas
hdeadman's avatar
hdeadman committed
89
    docker run --name cas %DOCKER_ORG%/cas:latest
90 91
@goto :EOF

hdeadman's avatar
hdeadman committed
92 93 94 95 96 97 98 99 100 101 102
:dockerrunsh
    @rem run image to look around, delete container on exit
    docker run --rm -it --entrypoint /bin/sh %DOCKER_ORG%/cas:latest
@goto :EOF

:dockerexecsh
    @rem exec into runing container to look around, run jstack, check config, etc
    docker exec -it cas /bin/sh
@goto :EOF


103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
:gencert
    where /q keytool
    if ERRORLEVEL 1 (
        @echo Java keytool.exe not found in path. 
        exit /b 1
    ) else (
        if not exist %CAS_DIR% mkdir %CAS_DIR%
        @echo on
        @echo Generating self-signed SSL cert for %DNAME% in %CAS_DIR%\thekeystore
        keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore %CAS_DIR%\thekeystore -dname %DNAME% -ext SAN=%CERT_SUBJ_ALT_NAMES%
        @echo Exporting cert for use in trust store (used by cas clients)
        keytool -exportcert -alias cas -storepass changeit -keystore %CAS_DIR%\thekeystore -file %CAS_DIR%\cas.cer
    )
@goto :EOF

:cli 
call %GRADLE_CMD% runShell
@goto :EOF

:debugcli 
call %GRADLE_CMD% debugShell
@goto :EOF

:dependencies
call %GRADLE_CMD% allDependencies
@goto :EOF