forked from Azure/azure-iot-pcs-device-simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildAndPush.cmd
More file actions
148 lines (123 loc) · 4.37 KB
/
buildAndPush.cmd
File metadata and controls
148 lines (123 loc) · 4.37 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
:: Copyright (c) Microsoft Corporation.
:: Licensed under the MIT license.
@echo off
setlocal enableDelayedExpansion
SET MICROSERVICES_DIRECTORY=microservices
SET MICROSERVICES_DOTNET=device-simulation-dotnet pcs-storage-adapter-dotnet pcs-diagnostics-dotnet pcs-config-dotnet
SET SERVICENAME_APIGATEWAY=api-gateway
SET SERVICENAME_WEBUI=pcs-simulation-webui
SET ALLCOMPONENTS=%MICROSERVICES_DOTNET% %SERVICENAME_APIGATEWAY% %SERVICENAME_WEBUI%
:: This script is used to build and push the docker images for IoT Device Simulation to a container repository
IF "%1"=="" (
ECHO.
ECHO This script builds all of the components ^(Web UI, .Net microservices, and the API gateway^) that are
ECHO used by IoT Device Simulation deployments. It builds Docker containers for each and pushes them
ECHO to the Docker container repository for the currently logged in user. A deployed IoT Device Simulation
ECHO solution includes an Azure VM image that references these containers at startup.
ECHO.
ECHO Usage:
ECHO --prefix: the Docker repository to push to
ECHO --service: [optional] a specific microservices or component to build. Available options include:
ECHO %ALLCOMPONENTS%
ECHO --tag: [optional] the Docker tag to use for each Docker image build. The default value is 'latest'
ECHO.
ECHO Examples:
ECHO .\buildAndPush --prefix examplereponame
ECHO .\buildAndPush --prefix examplereponame --service device-simulation-dotnet
GOTO :EOF
)
:: 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
:: Process parameters
:: https://stackoverflow.com/questions/3973824/windows-bat-file-optional-argument-parsing/8162578#8162578
SET prefix=
SET service=all
SET tag=latest
:ArgumentLoop
IF /i NOT "%1"=="" (
IF "%1"=="--service" (
SET service=%~2
SHIFT
)
IF "%1"=="--prefix" (
SET prefix=%~2
SHIFT
)
IF "%1"=="--tag" (
SET tag=%~2
SHIFT
)
SHIFT
goto :ArgumentLoop
)
IF "%prefix%" EQU "" ECHO ERROR: Docker image prefix must be specified. & GOTO :EOF
:: verify that the requested service/component is valid
IF [%service%] NEQ [all] (
FOR %%a IN (%ALLCOMPONENTS%) DO (
IF "%service%"=="%%a" GOTO :PreBuildReport
)
ECHO Invalid service/component name. Supported values are:
FOR %%a IN (%ALLCOMPONENTS%) DO ECHO %%a
GOTO :EOF
)
:PreBuildReport
ECHO.
ECHO The following values will be used:
ECHO Image repository: %prefix%
ECHO Service(s) to build: %service%
ECHO Image tag to use: %tag%
ECHO.
SET /P inputValidated=Is this correct (Y/N)?
IF /i "%inputValidated%"=="Y" GOTO :beginBuild
IF /i "%inputValidated%" NEQ "Y" GOTO :EOF
:beginBuild
SET "var=%cd%"
cd %~dp0
:: Build and push .Net microservices
:: (two IF statements to substiture for a logical 'OR' operator)
FOR %%a IN (%ALLCOMPONENTS%) DO (
IF %service%==%%a CALL :BuildAndPush %%a & GOTO :EOF
IF %service%==all CALL :BuildAndPush %%a
)
GOTO :EOF
:: Build Docker images and push
:BuildAndPush
SETLOCAL
SET component=%1
IF "%1"=="%SERVICENAME_APIGATEWAY%" (
SET dockerfilePath=.
) ELSE (
SET dockerfilePath=scripts/docker
)
ECHO.
ECHO.
ECHO ###############################################################
ECHO # Building and pushing Docker image for %component%
ECHO ###############################################################
ECHO.
ECHO.
:: change directory to the folder of the component that we're building
SET microservicePath=%~dp0%MICROSERVICES_DIRECTORY%\%component%\
CD %microservicePath%
SET imageName=%prefix%/%component%:%tag%
CALL %dockerfilePath%\build.cmd %imageName% || ECHO ERROR building %component% && EXIT /B 1
ECHO Pushing %imageName% to container repository
docker push %imageName% || ECHO ERROR pushing %imageName% && EXIT /B 1
ECHO.
ECHO ## Successfully pushed image %imageName%
ECHO.
EXIT /B 0
GOTO :EOF
: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
GOTO :EOF
: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/
GOTO :EOF