This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
142 lines (127 loc) · 4.09 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
# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# versioning
Major: 1
Minor: 0
# go setup
GO111MODULE: on
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOROOT: '/usr/local/go1.11' # Go installation path
GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)' # Path to the module's code
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'goslalom'
imageRepository: 'go-slalom'
containerRegistry: 'goslalom.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Major).$(Minor).$(Build.BuildID)'
# Kubernetes Namespace
k8sNamespace: 'go-slalom'
imagePullSecret: 'goslalom77be-auth'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: PullRequest
displayName: Pull Request stage
# only run for feature branches
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
jobs:
- job: UnitTest
displayName: 'Run Unit Tests'
pool:
vmImage: $(vmImageName)
steps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'
- script: go test -v ./...
workingDirectory: '$(modulePath)'
displayName: 'Run tests'
- stage: Build
displayName: Build stage
# only run for master
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
jobs:
- job: Build
displayName: Build job
pool:
vmImage: $(vmImageName)
steps:
# tag and create pre-release
- task: GitHubRelease@0
displayName: 'Tag Pre-Release'
inputs:
gitHubConnection: 'go-slalom token'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'manual'
isPreRelease: true
tag: $(tag)
# login to registry
- task: Docker@2
displayName: Login to Registry
inputs:
command: login
containerRegistry: $(dockerRegistryServiceConnection)
# run docker-azure-build.sh
- task: Bash@3
inputs:
targetType: 'filePath'
filePath: 'ci/docker-azure-build.sh'
arguments: |
$(tag)
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'manifests'
targetPath: 'deploy/azure'
- stage: DeployDev
displayName: Deploy Dev
dependsOn: Build
# only run for master
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
jobs:
- deployment: Deploy
displayName: Deploy job
pool:
vmImage: $(vmImageName)
environment: 'dev.go-slalom'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@1
inputs:
artifactName: 'manifests'
downloadPath: '$(System.ArtifactsDirectory)/manifests'
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
namespace: $(k8sNamespace)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
namespace: $(k8sNamespace)
manifests: |
$(System.ArtifactsDirectory)/manifests/deployment.yml
$(System.ArtifactsDirectory)/manifests/service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)