-
Notifications
You must be signed in to change notification settings - Fork 12
/
azure-pipelines.yml
92 lines (85 loc) · 3.35 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
84
85
86
87
88
89
90
91
92
# 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: mbillapi
imageName: memoyu/mbill-service
appsettings: src/Mbill/appsettings.Production.json
stages:
- stage: Build
displayName: build
jobs:
- job: Build
displayName: build image
pool:
vmImage: ubuntu-latest
steps:
- script: |
echo ready to execute command
ls
sed -i 's/{MySqlConStr}/$(MySqlConStr)/g' $(appsettings)
sed -i 's/{RedisConStr}/$(RedisConStr)/g' $(appsettings)
sed -i 's/{MongoDBConStr}/$(MongoDBConStr)/g' $(appsettings)
sed -i 's/{QiniuAk}/$(QiniuAk)/g' $(appsettings)
sed -i 's/{QiniuSk}/$(QiniuSk)/g' $(appsettings)
sed -i 's/{JwtSecurityKey}/$(JwtSecurityKey)/g' $(appsettings)
sed -i 's/{MiniProAppId}/$(MiniProAppId)/g' $(appsettings)
sed -i 's/{MiniProAppSecret}/$(MiniProAppSecret)/g' $(appsettings)
echo "================= print file $(appsettings) start ===================="
cat $(appsettings) | while read line; do echo $line ; done
echo "================= print file $(appsettings) end ===================="
echo command executed
- task: Docker@2
displayName: 'build docker image and push'
inputs:
containerRegistry: 'aliyun-docker'
repository: $(imageName)
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
buildContext: $(Build.Repository.LocalPath)
tags: 'latest'
- task: SSH@0
displayName: 'run mbill api container'
inputs:
sshEndpoint: 'cloud_service'
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 registry.cn-shenzhen.aliyuncs.com/$(imageName) &> /dev/null
# 如果不存在,不做操作
if [ $? -ne 0 ]
then
echo "image does not exist , continue..."
else
echo "image exists !!! remove it"
docker rmi registry.cn-shenzhen.aliyuncs.com/$(imageName)
fi
echo "================= to pull image ===================="
docker pull registry.cn-shenzhen.aliyuncs.com/$(imageName)
echo "================= to run container ===================="
docker run --restart=always --name $(containerName) -d -p 9600:8080 registry.cn-shenzhen.aliyuncs.com/$(imageName)
# 进行时区同步
# docker cp /usr/share/zoneinfo/Asia/Shanghai $(containerName):/etc/localtime
# echo 'Asia/Shanghai' >/etc/timezone && docker cp /etc/timezone $(containerName):/etc/timezone
echo "================= publish success ===================="
readyTimeout: '20000'