forked from BrewBlox/brewblox-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
95 lines (82 loc) · 2.71 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
pool:
vmImage: 'Ubuntu-18.04'
trigger:
tags:
include:
- "*"
branches:
include:
- refs/heads/*
pr:
branches:
include:
- '*'
variables:
# Variables imported from brewblox group:
# DOCKER_USER
# DOCKER_PASSWORD
- group: brewblox
steps:
- task: UsePythonVersion@0
inputs:
addToPath: true
versionSpec: '3.7'
architecture: 'x64'
- bash: |
set -o allexport; source .env; set +o allexport
echo "##vso[task.setvariable variable=DOCKER_REPO]$DOCKER_REPO"
displayName: Export .env variables
- bash: |
RELEASE=$(git describe --tags | grep "^[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]$")
BRANCH=$(echo $(Build.SourceBranch) | grep -oP "^refs/heads/\K.*")
TAG=$(echo $BRANCH | tr '/' '-' | tr '[:upper:]' '[:lower:]')
echo "##vso[task.setvariable variable=RELEASE]$RELEASE"
echo "##vso[task.setvariable variable=BRANCH]$BRANCH"
echo "##vso[task.setvariable variable=TAG]$TAG"
displayName: Export build variables
- bash: |
pip install poetry
poetry install
displayName: Install dependencies
- bash: poetry run pytest
displayName: Run Pytest
- bash: |
curl -L -o ~/.docker/cli-plugins/docker-buildx --create-dirs ${BUILDX_URL}
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use
docker buildx inspect --bootstrap
displayName: Prepare buildx
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
env:
BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-amd64
- bash: |
echo $(DOCKER_PASSWORD) | docker login -u $(DOCKER_USER) --password-stdin
displayName: Docker login
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
- bash: bash ./before_build.sh
displayName: Run before_build.sh script
workingDirectory: docker
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
- bash: >-
docker buildx build
--tag $(DOCKER_REPO):$(TAG)
--tag $(DOCKER_REPO):rpi-$(TAG)
--build-arg service_info="$(git describe) @ $(date)"
--push
--platform linux/amd64,linux/arm/v7
docker
displayName: Deploy Docker images with branch tags
condition: and(succeeded(), variables['BRANCH'], not(variables['RELEASE']))
- bash: >-
docker buildx build
--tag $(DOCKER_REPO):newest-tag
--tag $(DOCKER_REPO):rpi-newest-tag
--tag $(DOCKER_REPO):$(RELEASE)
--tag $(DOCKER_REPO):rpi-$(RELEASE)
--build-arg service_info="$(git describe) @ $(date)"
--push
--platform linux/amd64,linux/arm/v7
docker
displayName: Deploy Docker images with release tags
condition: and(succeeded(), variables['RELEASE'])