-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.yml
More file actions
69 lines (56 loc) · 1.38 KB
/
Copy pathpipeline.yml
File metadata and controls
69 lines (56 loc) · 1.38 KB
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
trigger:
- main
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
imageName: nodeapp
stages:
- stage: AppBuild
displayName: "Build, Test, and Package App"
jobs:
- job: BuildAndTest
pool:
name: agents
steps:
- script: |
npm ci
displayName: "Install dependencies"
- script: |
npm pack
mv *.tgz app.tgz
displayName: "Package Node.js app"
- stage: DockerBuild
displayName: "Build Docker Image"
dependsOn: AppBuild
jobs:
- job: DockerImage
pool:
name: agents
steps:
- download: current
artifact: app-package
displayName: "Download app artifact"
- task: Docker@2
displayName: "Build Docker Image"
inputs:
command: build
repository: $(imageName)
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
buildContext: '$(Pipeline.Workspace)/app-package'
tags: |
$(tag)
- stage: Deploy
displayName: "Run Container on VM"
dependsOn: DockerBuild
jobs:
- job: RunContainer
pool:
name: agents # same VM where agent is installed
steps:
- script: |
echo "Stopping old container if running..."
docker rm -f nodeapp || true
echo "Starting new container..."
docker run -d -p 80:3000 --name nodeapp $(imageName):$(tag)
displayName: "Deploy container on same VM"