-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
131 lines (104 loc) · 3.06 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Azure DevOps Pipeline
# CI: Docker Build
# CD: Ansible, Docker Compose
trigger:
branches:
include:
- master
- development
paths:
#include:
exclude:
- chart/*
- azure-pipelines.yml
- README.md
#tags:
#include:
#- v2.*
#exclude:
#- v2.0
# Don't run against PRs
pr: none
variables:
- group: FlaskApp # Variable Group Name
- name: tag
value: $(Build.SourceBranchName)-$(GitShortSha)
# Agent VM image name
- name: vmImageName
value: 'ubuntu-latest'
- name: containerRegistryServiceConnection
value: 'Docker Hub'
- name: imageRepository
value: 'diquzart/flaskapp'
- name: environment-dev
value: 'dev-XXXXX'
- name: environment-prod
value: 'prod-XXXX'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImageName: $(vmImageName)
steps:
- checkout: self
clean: true
displayName: Cleaning local repo
- script: GitShortSha=`git rev-parse --short HEAD` && echo "##vso[task.setvariable variable=GitShortSha]$GitShortSha"
displayName: Set the Git Short SHA as an environment variablie
- task: Docker@2
displayName: Build Container Image
inputs:
containerRegistry: '$(containerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'build'
Dockerfile: '**/Dockerfile'
tags: '$(tag)'
- task: Docker@2
displayName: Push Image to Container Registry
inputs:
containerRegistry: '$(containerRegistryServiceConnection)'
repository: '$(imageRepository)'
command: 'push'
tags: '$(tag)'
- task: Bash@3
displayName: Set variables to share between stages
inputs:
targetType: 'inline'
script: |
mkdir -p $(System.DefaultWorkingDirectory)
echo $(tag) > $(System.DefaultWorkingDirectory)/tag
echo "Checking VAR Library"
echo $(CONNECTSTRING)
- task: PublishPipelineArtifact@1
displayName: Publish artifacts
inputs:
targetPath: '$(System.DefaultWorkingDirectory)'
artifact: 'drop'
- stage: DeployDevelopment
displayName: Deploy Development
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/development'))
dependsOn: Build
jobs:
- deployment: Development
displayName: Deploy Development
#pool:
# name: $(vmImageName)
environment: $(environment-dev)
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: 'drop'
- script: tag=`cat $(Pipeline.Workspace)/tag` && echo "##vso[task.setvariable variable=tag]$tag"
displayName: Set the Git Short SHA as an environment variable
- task: AzureWebAppContainer@1
displayName: 'Deploy Azure Web App : {{ webapp-name }}'
inputs:
azureSubscription: $(azure-subscription)
appName: $(webapp-name)
containers: $(imageRepository):$(tag)