2019-07-26 21:26:54 +03:00
|
|
|
resources:
|
|
|
|
containers:
|
2019-07-26 23:50:33 +03:00
|
|
|
- container: golang
|
2019-07-26 21:26:54 +03:00
|
|
|
image: devcrewsacr.azurecr.io/operator-sdk-builder:latest
|
2019-07-26 21:41:41 +03:00
|
|
|
endpoint: AzureCR
|
2019-07-26 23:58:55 +03:00
|
|
|
|
|
|
|
- container: docker
|
2019-07-27 03:04:20 +03:00
|
|
|
image: devcrewsacr.azurecr.io/docker-builder:latest
|
2019-07-26 23:58:55 +03:00
|
|
|
endpoint: AzureCR
|
2019-07-26 21:26:54 +03:00
|
|
|
options: '-v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock'
|
|
|
|
|
2019-07-27 01:01:25 +03:00
|
|
|
# trigger:
|
|
|
|
# paths:
|
|
|
|
# exclude:
|
|
|
|
# - assets/*
|
|
|
|
# - deploy/*
|
2019-07-26 21:26:54 +03:00
|
|
|
|
|
|
|
name: $(Date:yyyyMMdd)$(Rev:r)
|
2019-07-26 23:58:55 +03:00
|
|
|
|
2019-07-26 21:26:54 +03:00
|
|
|
jobs:
|
|
|
|
######################################################################
|
|
|
|
# Build
|
|
|
|
######################################################################
|
|
|
|
- job: Build
|
2019-07-26 23:50:33 +03:00
|
|
|
container: golang
|
2019-07-26 21:26:54 +03:00
|
|
|
displayName: Build Operator
|
|
|
|
steps:
|
2019-07-27 03:54:42 +03:00
|
|
|
- task: CacheBeta@0
|
|
|
|
inputs:
|
|
|
|
key: |
|
|
|
|
vendor
|
|
|
|
$(Agent.OS)
|
|
|
|
$(Build.SourcesDirectory)/go.sum
|
|
|
|
path: $(Build.SourcesDirectory)/vendor
|
|
|
|
displayName: Cache Vendor Directory
|
2019-07-27 03:56:52 +03:00
|
|
|
|
2019-07-27 03:37:08 +03:00
|
|
|
- bash: |
|
|
|
|
if [ -f vendor ]; then
|
|
|
|
echo "##vso[task.setVariable variable=VENDOREXISTS]true"
|
2019-07-27 03:46:31 +03:00
|
|
|
else
|
2019-07-27 03:45:34 +03:00
|
|
|
echo "##vso[task.setVariable variable=VENDOREXISTS]false"
|
2019-07-27 03:37:08 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
- script: go mod vendor
|
2019-07-27 03:45:34 +03:00
|
|
|
condition: eq(variables.VENDOREXISTS, 'false')
|
2019-07-27 03:37:08 +03:00
|
|
|
|
2019-07-27 03:38:00 +03:00
|
|
|
- script: go build cmd/manager/main.go
|
2019-07-27 03:56:52 +03:00
|
|
|
|
|
|
|
- publish: $(Build.SourcesDirectory)/build
|
|
|
|
artifact: build
|
2019-07-27 03:37:08 +03:00
|
|
|
|
2019-07-26 21:26:54 +03:00
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Tests
|
|
|
|
######################################################################
|
|
|
|
- job: UnitTests
|
2019-07-26 23:50:33 +03:00
|
|
|
container: golang
|
2019-07-26 21:26:54 +03:00
|
|
|
displayName: Run unit tests
|
|
|
|
dependsOn: Build
|
|
|
|
steps:
|
2019-07-27 03:54:42 +03:00
|
|
|
- task: CacheBeta@0
|
|
|
|
inputs:
|
|
|
|
key: |
|
|
|
|
vendor
|
|
|
|
$(Agent.OS)
|
|
|
|
$(Build.SourcesDirectory)/go.sum
|
|
|
|
path: $(Build.SourcesDirectory)/vendor
|
|
|
|
displayName: Cache Vendor Directory
|
|
|
|
|
2019-07-27 03:37:08 +03:00
|
|
|
- bash: |
|
|
|
|
if [ -f vendor ]; then
|
|
|
|
echo "##vso[task.setVariable variable=VENDOREXISTS]true"
|
2019-07-27 03:46:31 +03:00
|
|
|
else
|
2019-07-27 03:45:34 +03:00
|
|
|
echo "##vso[task.setVariable variable=VENDOREXISTS]false"
|
2019-07-27 03:37:08 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
- script: go mod vendor
|
2019-07-27 03:45:34 +03:00
|
|
|
condition: eq(variables.VENDOREXISTS, 'false')
|
2019-07-27 03:37:08 +03:00
|
|
|
|
2019-07-27 03:38:00 +03:00
|
|
|
- script: go test -cover $(go list ./...)
|
2019-07-26 21:26:54 +03:00
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Container Creation
|
|
|
|
######################################################################
|
|
|
|
- job: Containerize
|
|
|
|
displayName: Build and push container
|
|
|
|
dependsOn: UnitTests
|
2019-07-27 03:17:24 +03:00
|
|
|
variables:
|
|
|
|
OperatorImage: devcrewsacr.azurecr.io/public/k8s/bedrock/ring-operator
|
|
|
|
MyBuildId: $(Date:yyyyMMdd)$(Rev:r)
|
2019-07-26 21:26:54 +03:00
|
|
|
steps:
|
2019-07-27 03:10:31 +03:00
|
|
|
# - script: |
|
|
|
|
# set -ex
|
|
|
|
# sudo groupadd -o -g $(stat --format='%g' /var/run/docker.sock) docker
|
|
|
|
# sudo usermod -a -G docker $(whoami)
|
|
|
|
# displayName: Allow current user to access the docker socket
|
2019-07-27 03:45:34 +03:00
|
|
|
# - checkout: none
|
|
|
|
# - download:
|
|
|
|
# artifact:
|
2019-07-27 03:56:52 +03:00
|
|
|
- download: current
|
|
|
|
artifact: build
|
2019-07-26 21:26:54 +03:00
|
|
|
|
|
|
|
- task: Docker@2
|
|
|
|
displayName: Login to Azure Container Registry
|
|
|
|
inputs:
|
|
|
|
command: login
|
2019-07-26 21:41:41 +03:00
|
|
|
azureSubscriptionEndpoint: AzureRM
|
|
|
|
containerRegistry: AzureCR
|
2019-07-26 21:26:54 +03:00
|
|
|
|
2019-07-27 03:45:34 +03:00
|
|
|
- task: Docker@2
|
|
|
|
displayName: Build and Push
|
|
|
|
inputs:
|
|
|
|
command: buildAndPush
|
|
|
|
containerRegistry: AzureCR
|
|
|
|
repository: $(OperatorImage)
|
|
|
|
tags: |
|
|
|
|
# tag1
|
|
|
|
latest
|