PowerShell和Bash的定义与使用


当前第2页 返回上一页

下面是在eShopOnContainers上的一个例子,分别用ps和bash实现了程序的部署

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

#!/bin/bash

declare -a projectList=('../src/Services/Catalog/Catalog.API''../src/Services/Basket/Basket.API''../src/Services/Ordering/Ordering.API''../src/Services/Identity/Identity.API''../src/Web/WebMVC''../src/Web/WebSPA''../src/Web/WebStatus')

 

# Build SPA app

# pushd $(pwd)../src/Web/WebSPA

# npm run build:prodfor project in "${projectList[@]}"doecho -e "\e[33mWorking on $(pwd)/$project"echo -e "\e[33m\tRemoving old publish output"pushd $(pwd)/$project

    rm -rf obj/Docker/publish

    echo -e "\e[33m\tRestoring project"dotnet restore

    echo -e "\e[33m\tBuilding and publishing projects"dotnet publish -o obj/Docker/publish

    popd

done

 

# remove old docker images:

images=$(docker images --filter=reference="eshop/*" -q)if [ -n "$images" ]; then

    docker rm $(docker ps -a -q) -f

    echo "Deleting eShop images in local Docker repo"echo $images

    docker rmi $(docker images --filter=reference="eshop/*" -q) -f

fi

 

# No need to build the images, docker build or docker compose will

# do that using the images and containers defined in the docker-compose.yml file.

powershell代码如下

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

Param([string] $rootPath)

$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path

 

Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellowif ([string]::IsNullOrEmpty($rootPath)) {

    $rootPath = "$scriptPath\.."}

Write-Host "Root path used is $rootPath" -ForegroundColor Yellow

 

$projectPaths =

    @{Path="$rootPath\src\Web\WebMVC";Prj="WebMVC.csproj"},

    @{Path="$rootPath\src\Web\WebSPA";Prj="WebSPA.csproj"},

    @{Path="$rootPath\src\Services\Identity\Identity.API";Prj="Identity.API.csproj"},

    @{Path="$rootPath\src\Services\Catalog\Catalog.API";Prj="Catalog.API.csproj"},

    @{Path="$rootPath\src\Services\Ordering\Ordering.API";Prj="Ordering.API.csproj"},

    @{Path="$rootPath\src\Services\Basket\Basket.API";Prj="Basket.API.csproj"}

    @{Path="$rootPath\src\Web\WebStatus";Prj="WebStatus.csproj"}

 

$projectPaths | foreach {

    $projectPath = $_.Path

    $projectFile = $_.Prj

    $outPath = $_.Path + "\obj\Docker\publish"$projectPathAndFile = "$projectPath\$projectFile"Write-Host "Deleting old publish files in $outPath" -ForegroundColor Yellow

    remove-item -path $outPath -Force -Recurse -ErrorAction SilentlyContinue

    Write-Host "Publishing $projectPathAndFile to $outPath" -ForegroundColor Yellow

    dotnet restore $projectPathAndFile

    dotnet build $projectPathAndFile

    dotnet publish $projectPathAndFile -o $outPath

}

 

 

########################################################################################

# Delete old eShop Docker images

########################################################################################

 

$imagesToDelete = docker images --filter=reference="eshop/*" -q

 

If (-Not $imagesToDelete) {Write-Host "Not deleting eShop images as there are no eShop images in the current local Docker repo."}

Else

{

    # Delete all containers

    Write-Host "Deleting all containers in local Docker Host"docker rm $(docker ps -a -q) -f

     

    # Delete all eshop images

    Write-Host "Deleting eShop images in local Docker repo"Write-Host $imagesToDelete

    docker rmi $(docker images --filter=reference="eshop/*" -q) -f

}

 

# WE DON'T NEED DOCKER BUILD AS WE CAN RUN "DOCKER-COMPOSE BUILD" OR "DOCKER-COMPOSE UP" AND IT WILL BUILD ALL THE IMAGES IN THE .YML FOR US

自己感觉,这两个东西在以后的程序部署上都会发挥各自强大的力量!

以上就是PowerShell和Bash的定义与使用的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

bash shell:测试文件或目录是否存在

freeworld.posterous.com linux bash shell cheat sheet----autho:raphael

总结bash中常用特殊字符

在bash shell脚本中使用while循环

在bash shell脚本中使用for循环

关于实时同步的详细介绍

linux安装命令介绍

linux中用户和用户组的详细介绍

linux下vsftpd的安装及配置介绍

linux bash是什么?

更多相关阅读请进入《PowerShell》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...