-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines-chainlit.yml
189 lines (166 loc) · 7.63 KB
/
azure-pipelines-chainlit.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
branches:
include:
- main
paths:
include:
- chainlit/*
- azure-pipelines-chainlit.yml
resources:
- repo: self
variables:
- group: 'AI Chat Secrets'
- name: tag
value: '$(Build.BuildId)'
- name: imageName
value: 'ai-chatbot-chainlit'
- name: awsRegion
value: 'eu-central-1'
stages:
- stage: CI
displayName: Build and push the image to the ECR
jobs:
- job: CalculateVersion
displayName: Tagging release version
steps:
# Checkout with persist credentials
- checkout: self
persistCredentials: true
# Unshallow the repository to ensure GitVersion can access the full history
- script: |
git fetch --unshallow
displayName: 'Unshallow Repository'
# Install GitVersion
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: "5.x"
# Determine the semantic version
- task: gitversion/execute@0
displayName: Calculating version
inputs:
useConfigFile: True
configFilePath: "GitVersion.yml"
# Update Build.BuildNumber to use SemVer, as by default it uses FullSemVer
- pwsh: |
Write-Host "##vso[build.updatebuildnumber]$(GitVersion.SemVer)"
displayName: Update Build.BuildNumber
# Update the 'tag' variable with the calculated semantic version
- pwsh: |
echo "##vso[task.setvariable variable=tag;isOutput=true]$(GitVersion.SemVer)"
name: setTagVariable
displayName: Set Tag Variable
# Example step showing the updated 'tag' variable usage
- script: |
echo "New tag value: $(tag)"
displayName: Show Updated Tag Value
- task: PowerShell@2
displayName: Adding git release tag
name: AddGitTag
inputs:
targetType: inline
script: |
Write-Host "Configuring git author info.." -ForegroundColor Cyan
git config user.email "Azure DevOps pipeline"
git config user.name "[email protected]"
# Fetch tags from the remote to ensure we have the latest state
git fetch --tags
$tag = "v$(GitVersion.SemVer)"
Write-Host "Checking if tag $tag already exists in local or remote.." -ForegroundColor Cyan
$localTagExists = git tag -l $tag
$remoteTagExists = git ls-remote --tags origin refs/tags/$tag
if (-not $localTagExists -and -not $remoteTagExists) {
Write-Host "Adding git tag for release $tag.." -ForegroundColor Cyan
git tag -a $tag -m "Release $tag"
git push origin $tag
Write-Host "##vso[task.setvariable variable=generateReleaseNotes;isOutput=true]true"
} else {
Write-Host "Tag $tag already exists in local or remote. Skipping tag push.." -ForegroundColor Cyan
}
Write-Host "Done." -ForegroundColor Cyan
- job: Build
displayName: Build and push to the ECR
dependsOn: CalculateVersion # This makes the Build job wait for CalculateVersion job to complete
pool:
vmImage: ubuntu-latest
variables:
updatedTag: $[ dependencies.CalculateVersion.outputs['setTagVariable.tag'] ]
steps:
- task: Docker@2
displayName: 'Build docker image'
inputs:
command: 'build'
Dockerfile: '$(Build.SourcesDirectory)/chainlit/Dockerfile'
arguments: '--tag $(imageName)'
addPipelineData: false
- task: ECRPushImage@1
displayName: 'Push image to AWS'
inputs:
awsCredentials: 'aws-hackathon-capability'
regionName: $(awsRegion)
imageSource: 'imagename'
sourceImageName: $(imageName)
repositoryName: $(imageName)
pushTag: $(updatedTag)
autoCreateRepository: true
- task: AWSShellScript@1
displayName: 'Set repository pull permissions'
inputs:
awsCredentials: 'aws-hackathon-capability'
regionName: $(awsRegion)
scriptType: inline
inlineScript: |
aws ecr set-repository-policy \
--repository-name $(imageName) \
--region $(awsRegion) \
--policy-text '{"Version":"2008-10-17","Statement":[{"Sid":"Allow pull","Effect":"Allow","Principal":{"AWS":["arn:aws:iam::738063116313:root","arn:aws:iam::738063116313:role/eks-hellman-node"]},"Action":["ecr:BatchCheckLayerAvailability","ecr:BatchGetImage","ecr:GetDownloadUrlForLayer"]}]}'
continueOnError: false
- task: PublishBuildArtifacts@1
displayName: "Publish Artifact: k8s"
inputs:
PathtoPublish: "./chainlit/k8s"
ArtifactName: k8s
## Job to create release notes file and publish it to the wiki
- job: CreateReleaseNotes
dependsOn: Build
displayName: Creating release notes
variables:
shouldCreateReleaseNotes: $[ dependencies.CalculateVersion.outputs['AddGitTag.generateReleaseNotes'] ]
condition: eq(variables['shouldCreateReleaseNotes'], 'true')
steps:
# Generates a release notes file using the latest version (v4) of the task
- task: XplatGenerateReleaseNotes@4
displayName: "Generate release notes"
inputs:
outputfile: '$(System.DefaultWorkingDirectory)/Release-Notes.md'
templateLocation: 'File'
templatefile: '.azuredevops/release-notes-template.md'
dumpPayloadToConsole: false
dumpPayloadToFile: false
replaceFile: true
getParentsAndChildren: false
getAllParents: false
getIndirectPullRequests: false
stopOnError: true
considerPartiallySuccessfulReleases: false
# Publishes the release notes in the project wiki
- task: WikiUpdaterTask@2
displayName: "Publish to the wiki"
inputs:
repo: "https://dev.azure.com/template/project/_git/project.wiki" # Ensure the repo URL is correct and follows any new guidelines from version 2 notes.
filename: "Release-Notes.md" # Maintaining the filename convention.
replaceFile: false # Keeping the original behavior.
appendToFile: true # Keeping the original behavior.
dataIsFile: true # Indicating that the source of the update is a file.
sourceFile: '$(System.DefaultWorkingDirectory)/Release-Notes.md' # Providing the path to the source file correctly.
message: "Update from Pipeline" # Custom commit message.
gitname: $(Release.RequestedFor) # Using release variable for Git username.
gitemail: $(Release.RequestedForEmail) # Using release variable for Git email.
useAgentToken: false # Utilizing the agent's OAuth token for authentication.
localpath: '$(System.DefaultWorkingDirectory)/repo' # Specifying the local clone path.
RetryMode: 'Pull'
user: 'template'
password: '$(ADO_PAT)'