-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
82 lines (72 loc) · 2.33 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
# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
tags:
include:
- v*
variables:
containerName: blogadmin
imageName: memoyu/memo-blog-admin
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '22.x'
displayName: 'install Node.js'
- script: |
cd src
yarn
yarn build
displayName: 'yarn install and build'
- script: |
cd src/build
ls -lah
displayName: 'output'
- task: Docker@2
displayName: 'build docker image and push'
inputs:
containerRegistry: 'aliyun-docker'
repository: $(imageName)
command: 'buildAndPush'
Dockerfile: 'docker/Dockerfile'
buildContext: $(Build.Repository.LocalPath)
tags: 'latest'
- task: SSH@0
displayName: 'run docker 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 ===================="
# 设置时区: 设置环境变量 -e "TZ=Asia/Shanghai"
docker run --restart=always --name $(containerName) -d -p 11011:80 -e "TZ=Asia/Shanghai" registry.cn-shenzhen.aliyuncs.com/$(imageName)
echo "================= publish success ===================="
readyTimeout: '20000'