| |
| $ErrorActionPreference = "Stop" |
| |
| $account = 'xxx@yeah.net' |
| $password = 'xxx' |
| $server = 'registry.cn-hangzhou.aliyuncs.com' |
| $tagName = 'apiservice:latest' |
| $imageName = "$server/x/$tagName" |
| |
| function throwIfError([string]$name) { |
| if(-not $?) { throw [Exception]::new("${name}失败") } |
| } |
| |
| Write-Output "登录阿里云" |
| $password | docker login --username=$($account) $server --password-stdin |
| throwIfError "登录阿里云" |
| |
| Write-Output "开始编译" |
| docker build -t $tagName -f .\Dockerfile .. |
| throwIfError "编译" |
| |
| try |
| { |
| Write-Output "命名镜像" |
| docker tag $tagName $imageName |
| throwIfError "命名镜像" |
| |
| try |
| { |
| Write-Output "推送镜像" |
| docker push $imageName |
| throwIfError "推送镜像" |
| } |
| finally |
| { |
| Write-Output "删除重命名镜像" |
| docker rmi $imageName |
| throwIfError "删除重命名镜像" |
| } |
| |
| } |
| finally |
| { |
| Write-Output "删除镜像" |
| docker rmi $tagName |
| throwIfError "删除镜像" |
| } |
| |
| Write-Output "发布完成" |