This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
azure-pipelines.yaml
116 lines (96 loc) · 4.12 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
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
trigger:
branches:
include:
- master
pool:
vmImage: 'Ubuntu 16.04'
variables:
IMAGE_NAME: 'candidate/k8s/azure-databricks/operator:$(Build.SourceVersion)'
# ACR_NAME: - set this value in Azure Devops variables
# AZURE_SUBSCRIPTION: - set this value in Azure Devops variables
# DATABRICKS_HOST: - set this value in Azure Devops variables
# DATABRICKS_TOKEN: - set this value in Azure Devops variables
jobs:
- job: Build
steps:
# Cache the docker image file
- task: Cache@2
inputs:
key: go-cache | go.sum
path: ".gocache"
restoreKeys: go-cache
displayName: Cache go mod cache
# Cache the docker image file
- task: Cache@2
inputs:
key: docker-image | .devcontainer/**
path: ".dockercache"
restoreKeys: docker-image
cacheHitVar: DOCKER_CACHE_HIT
displayName: Cache docker layers
- script: |
docker info
docker load -i ./.dockercache/devcontainer.tar
condition: eq(variables.DOCKER_CACHE_HIT, 'true')
displayName: Load cached devcontainer image
- script: |
set -e
# Create dockercache directory
mkdir -p ./.dockercache/
echo "-------> Building devcontainer"
docker build --cache-from devcontainer:latest -t devcontainer -f ./.devcontainer/Dockerfile .
displayName: Build devcontainer image
- script: |
echo "-------> Saving docker image"
docker image save -o ./.dockercache/devcontainer.tar devcontainer
condition: and(succeeded(), ne(variables.DOCKER_CACHE_HIT, 'true'))
displayName: Save devcontainer image
- script: |
set -e
# Create a directory for go mod cache
mkdir -p $(System.DefaultWorkingDirectory)/.gocache
echo "-------> Building code and running tests"
# Commands to execute in the devcontainer
COMMANDS="source ~/.bashrc && make test-local"
# Run the dev container
docker run -v $(System.DefaultWorkingDirectory)/.gocache:/go/pkg/ -v /var/run/docker.sock:/var/run/docker.sock -v $(System.DefaultWorkingDirectory):/src --workdir /src --entrypoint /bin/bash --network="host" devcontainer -c "$COMMANDS"
sudo chown -R $USER $(System.DefaultWorkingDirectory)
condition: succeeded()
displayName: Unit and load tests
- script: |
set -e
echo "-------> Run integration tests"
# Run `make` to build and test the code
docker run -v $(System.DefaultWorkingDirectory)/.gocache:/go/pkg/ -v /var/run/docker.sock:/var/run/docker.sock -v $(System.DefaultWorkingDirectory):/src --workdir /src --entrypoint /bin/bash --network="host" --env DATABRICKS_HOST=$(DATABRICKS_HOST) --env DATABRICKS_TOKEN=$(DATABRICKS_TOKEN) devcontainer -c "make test"
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Integration tests
- script: |
docker stop `docker ps -qa`
docker system prune -f --volumes -a
displayName: Clean up docker
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/cover.xml
reportDirectory: $(System.DefaultWorkingDirectory)/**/cover
- task: AzureCLI@1
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Push to Azure Container Registry
inputs:
azureSubscription: $(AZURE_SUBSCRIPTION)
scriptLocation: inlineScript
failOnStandardError: false
inlineScript: az acr build --registry $(ACR_NAME) --image $(IMAGE_NAME) .
- script: |
./bin/kustomize build config/default > $(Build.ArtifactStagingDirectory)/setup.yaml
set -x
echo $(IMAGE_NAME) > $(Build.ArtifactStagingDirectory)/azure-databricks-operator.txt
ls $(Build.ArtifactStagingDirectory)
continueOnError: 'false'
displayName: 'Prepare manifests for publish'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
- task: PublishBuildArtifacts@1
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop