forked from Azure/device-simulation-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cmd
85 lines (66 loc) · 2.56 KB
/
build.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
82
83
84
85
@ECHO off & setlocal enableextensions enabledelayedexpansion
:: Note: use lowercase names for the Docker images
SET DOCKER_IMAGE=azureiotpcs/device-simulation-dotnet
:: "testing" is the latest dev build, usually matching the code in the "master" branch
SET DOCKER_TAG=%DOCKER_IMAGE%:testing
:: Debug|Release
SET CONFIGURATION=Release
:: strlen("\scripts\docker\") => 16
SET APP_HOME=%~dp0
SET APP_HOME=%APP_HOME:~0,-16%
cd %APP_HOME%
:: Check dependencies
dotnet --version > NUL 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO MISSING_DOTNET
docker version > NUL 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO MISSING_DOCKER
git version > NUL 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO MISSING_GIT
:: Restore packages and build the application
call dotnet restore
IF %ERRORLEVEL% NEQ 0 GOTO FAIL
call dotnet build --configuration %CONFIGURATION%
IF %ERRORLEVEL% NEQ 0 GOTO FAIL
:: Build the container image
git log --pretty=format:%%H -n 1 > tmpfile.tmp
SET /P COMMIT=<tmpfile.tmp
DEL tmpfile.tmp
SET DOCKER_LABEL2=Commit=%COMMIT%
rmdir /s /q out\docker
rmdir /s /q WebService\bin\Docker
rmdir /s /q SimulationAgent\bin\Docker
mkdir out\docker\webservice
mkdir out\docker\simulationagent
dotnet publish WebService --configuration %CONFIGURATION% --output bin\Docker
dotnet publish SimulationAgent --configuration %CONFIGURATION% --output bin\Docker
xcopy /s WebService\bin\Docker\* out\docker\webservice\
xcopy /s SimulationAgent\bin\Docker\* out\docker\simulationagent\
copy scripts\docker\.dockerignore out\docker\
copy scripts\docker\Dockerfile out\docker\
copy scripts\docker\content\run.sh out\docker\
cd out\docker\
docker build --squash --compress --tag %DOCKER_TAG% --label "%DOCKER_LABEL2%" .
IF %ERRORLEVEL% NEQ 0 GOTO FAIL
:: - - - - - - - - - - - - - -
goto :END
:MISSING_DOTNET
echo ERROR: 'dotnet' command not found.
echo Install .NET Core 2 and make sure the 'dotnet' command is in the PATH.
echo Nuget installation: https://dotnet.github.io/
exit /B 1
:MISSING_DOCKER
echo ERROR: 'docker' command not found.
echo Install Docker and make sure the 'docker' command is in the PATH.
echo Docker installation: https://www.docker.com/community-edition#/download
exit /B 1
:MISSING_GIT
echo ERROR: 'git' command not found.
echo Install Git and make sure the 'git' command is in the PATH.
echo Git installation: https://git-scm.com
exit /B 1
:FAIL
echo Command failed
endlocal
exit /B 1
:END
endlocal