-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathazure-pipelines.yml
174 lines (165 loc) · 5.47 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
trigger:
batch: true
branches:
include:
- main
- feature/*
- fix/*
exclude:
- releases/*
variables:
- name: dockerRegistryServiceConnection
value: '$(registryConnection)'
- name: dockerfilePath
value: '$(Build.SourcesDirectory)/Dockerfile'
- name: tag
value: '$(Build.BuildId)'
- name: buildNumber
value: '$(Build.BuildNumber)'
- name: isMain
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
- name: 'System.Debug'
value: false
- name: slot
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
value: 'dev'
${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}:
value: 'build'
- name: vmImageName
value: 'ubuntu-latest'
pool:
vmImage: $(vmImageName)
stages:
- stage: BuildTest
displayName: Build and test project
jobs:
- job: "LabGenerative"
displayName: "Build Tech Lab Generative"
strategy:
matrix:
# Python310:
# python.version: '3.10'
Python311:
python.version: "3.11"
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "$(python.version)"
displayName: "Use Python $(python.version)"
- script: |
echo "Source branch is $(Build.SourceBranch)"
echo "Current branch is $(git branch --show-current)"
- script: |
pipx install poetry
poetry install --with=dev,test
poetry show --outdated --with=dev,test
displayName: "Install dependencies"
- script: |
poetry run ruff check lab_gen
displayName: "pylint"
- script: |
poetry run pre-commit run --all-files
displayName: "Check All Files"
- script: |
cp example.env .env
mkdir secrets
poetry run pytest -vv
displayName: "pytest"
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'
- stage: Package
displayName: Build and package docker image
dependsOn: BuildTest
jobs:
- job: Build
displayName: Build
steps:
- task: Docker@2
displayName: Build and push an image to Azure container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- deployment: DeployToStagingEnvironment
displayName: Publish
dependsOn: Build
environment: '$(slot)'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
displayName: Deploy the docker image to the Web App
inputs:
ConnectionType: "AzureRM"
appType: "webAppContainer"
deployToSlotOrASE: true
azureSubscription: $(azureSubscription)
WebAppName: $(webAppName)
ResourceGroupName: $(resourceGroupName)
SlotName: '$(slot)'
DockerNamespace: $(containerNamespace)
DockerRepository: $(imageRepository)
DockerImageTag: $(tag)
AppSettings: '-LAB_GEN_VERSION "$(buildNumber) $(tag)"'
- stage: ProdDeploy
displayName: Deploy docker image to production
dependsOn: Package
condition: and(succeeded(), eq(variables.isMain, true))
jobs:
- deployment: DeployToProduction
displayName: Production
environment: production
strategy:
runOnce:
deploy:
steps:
- checkout: self
persistCredentials: true
displayName: "Checking out git repository"
- script: |
echo "Current branch is $(git branch --show-current)"
git fetch --all --unshallow
git fetch --tags
echo "Switching branch to $(basename $(Build.SourceBranch))"
git switch $(basename $(Build.SourceBranch))
echo "Git branch is $(git rev-parse --abbrev-ref HEAD)"
displayName: "Checking out branch"
- task: UsePythonVersion@0
inputs:
versionSpec: "3.12"
displayName: "Use Python 3.12"
- script: |
pipx install poetry
poetry install --with=dev
displayName: "Install dependencies"
- script: |
echo "Last released: $(poetry run semantic-release version --print-last-released)"
echo "Next release : $(poetry run semantic-release version --print-tag)"
echo "Mergebase is $(git merge-base v0.1.1 main)"
echo "rev-list is $(git rev-list v0.1.1... --)"
poetry run semantic-release --noop version --no-vcs-release
displayName: "Git test commands"
- script: |
poetry run semantic-release version --no-vcs-release
displayName: "Create release"
- task: AzureRmWebAppDeployment@4
displayName: Deploy the docker image to the production Web App
inputs:
ConnectionType: "AzureRM"
appType: "webAppContainer"
deployToSlotOrASE: true
azureSubscription: $(azureSubscription)
WebAppName: $(webAppName)
ResourceGroupName: $(resourceGroupName)
SlotName: production
DockerNamespace: $(containerNamespace)
DockerRepository: $(imageRepository)
DockerImageTag: $(tag)
AppSettings: '-LAB_GEN_VERSION "$(buildNumber) $(tag)"'