-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathazure-pipelines.yaml
78 lines (75 loc) · 2.87 KB
/
azure-pipelines.yaml
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
name: $(date:yyyyMMdd)$(rev:.r)
trigger:
- master
variables:
registry: cr.theresa.wiki
repository: theresa-wiki/theresa-frontend
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Bash@3
displayName: Get git hash
inputs:
targetType: inline
script: |
GIT_HASH=`git rev-parse --short=7 HEAD`
echo "##vso[task.setvariable variable=GIT_HASH]$GIT_HASH"
- task: Cache@2
displayName: Get docker cache
inputs:
key: docker | "$(Agent.OS)" | "$(repository)" | $(Build.SourceBranchName)-$(GIT_HASH)
path: $(Pipeline.Workspace)/.docker
cacheHitVar: DOCKER_CACHE_RESTORED
restoreKeys: docker | "$(Agent.OS)" | "$(repository)"
- task: Docker@2
displayName: Docker login
inputs:
command: login
containerRegistry: cr.theresa.wiki
- task: Bash@3
displayName: Build and Push image
inputs:
targetType: inline
script: |
docker version
docker buildx version
docker buildx create --driver=docker-container --use
docker buildx install
docker buildx build \
--cache-from=type=local,src=$(Pipeline.Workspace)/.docker \
--cache-to=type=local,dest=$(Pipeline.Workspace)/.docker_new,mode=max \
--platform linux/amd64,linux/arm64 \
--tag $(registry)/$(repository):$(Build.SourceBranchName)-$(GIT_HASH) \
--tag $(registry)/$(repository):latest \
--file $(Build.SourcesDirectory)/Dockerfile \
$(Build.SourcesDirectory) \
--output=type=image \
--push
- task: Bash@3
displayName: Docker cache
inputs:
targetType: inline
script: |
rm -rf $(Pipeline.Workspace)/.docker
mv $(Pipeline.Workspace)/.docker_new $(Pipeline.Workspace)/.docker
condition: and(not(canceled()), ne(variables.DOCKER_CACHE_RESTORED, 'true'))
- task: Bash@3
displayName: Write version to artifact
inputs:
targetType: inline
script: |
cd $(Build.ArtifactStagingDirectory)
echo '$(Build.SourceBranchName)-$(GIT_HASH)' > version.txt
condition: not(canceled())
- task: PublishBuildArtifacts@1
displayName: Publish Artifact
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: version
condition: not(canceled())