This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
build.cmd
107 lines (83 loc) · 3.32 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
:: Copyright (c) Microsoft. All rights reserved.
@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
echo.
echo ##############################################
echo ######### Running dotnet build... ############
echo ##############################################
echo.
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
mkdir out\docker\webservice
echo.
echo ##############################################
echo ######### Running dotnet publish... ##########
echo ##############################################
echo.
:: Note that .Net 3 and .Net 2 handle relative paths differently (when using the --output flag)
:: See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish if the output files
:: are missing.
dotnet publish WebService --configuration %CONFIGURATION% --output WebService\bin\Docker
echo.
echo #####################################################################################
echo ####### Copying files from WebService\bin\Docker to out\docker\webservice... ########
echo #####################################################################################
echo.
xcopy /s WebService\bin\Docker\* out\docker\webservice\
echo Copying .dockerignore...
copy scripts\docker\.dockerignore out\docker\
copy scripts\docker\Dockerfile out\docker\
copy scripts\docker\content\run.sh out\docker\
cd out\docker\
echo Running docker build...
docker build --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