-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
83 lines (73 loc) · 2.53 KB
/
azure-pipelines.yml
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
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
tags:
include:
- release-*
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
containerName: wecom_tool
imageName: memoyu/wecom_tool
custAppConfig: src/WeComLoad.Open.Blazor/wwwroot/resources/custapp.settings.json
stages:
- stage: Build
displayName: build wecom tool
jobs:
- job: Build
pool:
vmImage: ubuntu-latest
steps:
- script: |
echo ready to execute command
echo '$(cust_app_config)' > $(custAppConfig)
echo "================= print file $(custAppConfig) start ===================="
cat $(custAppConfig) | while read line; do echo $line ; done
echo "================= print file $(custAppConfig) end ===================="
echo command executed
displayName: 'replace config value'
- task: Docker@2
displayName: 'build docker image and push'
inputs:
containerRegistry: 'memoyu-docker'
repository: $(imageName)
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
buildContext: $(Build.Repository.LocalPath)
tags: 'latest'
- task: SSH@0
displayName: 'run wecom tool container'
inputs:
sshEndpoint: 'HuaweiCloud'
runOptions: 'inline'
inline: |
echo "================= to del container ===================="
# 判断是否存在容器
docker ps | grep $(containerName) &> /dev/null
# 如果不存在,则Remove
if [ $? -ne 0 ]
then
echo "$(containerName) container not exist continue.. "
else
echo "remove $(containerName) container"
docker kill $(containerName)
docker rm $(containerName)
fi
echo "================= to rm image ===================="
# 判断是否存在镜像
docker images | grep $(imageName) &> /dev/null
# 如果不存在,不做操作
if [ $? -ne 0 ]
then
echo "image does not exist , continue..."
else
echo "image exists !!! remove it"
docker rmi $(imageName)
fi
echo "================= to pull image ===================="
docker pull $(imageName)
echo "================= to run container ===================="
docker run --name $(containerName) -d -p 9004:80 $(imageName)
echo "================= publish success ===================="