-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
128 lines (126 loc) · 5.08 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
trigger:
batch: true
branches:
include:
- develop
- master
- staging
- ops/*
pr: none
resources:
- repo: self
variables:
- name: Docker.filePath
value: "**/docker/Dockerfile"
- name: Docker.repository
value: "flex-registration"
- name: buildDate
value: $[format('{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}', pipeline.startTime)]
- ${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
- group: flex-registration-prod
- name: Docker.registry
value: "unihopeukrsr"
- name: azureSubscription
value: "UNI_WEBS rs-uni-hope-ukr-sr"
- name: appName
value: "uni-hope-ukr-sr"
- ${{ elseif eq(variables['Build.SourceBranchName'], 'staging') }}:
- group: flex-registration-stg
- name: Docker.registry
value: "unihopeukrsrdev"
- name: azureSubscription
value: "UNI_WEBS rs-uni-hope-ukr-sr-dev"
- name: appName
value: "uni-hope-ukr-sr-stg"
- ${{ else }}:
- group: flex-registration-dev
- name: Docker.registry
value: "unihopeukrsrdev"
- name: azureSubscription
value: "UNI_WEBS rs-uni-hope-ukr-sr-dev"
- name: appName
value: "uni-hope-ukr-sr-dev"
stages:
- stage: build_and_push
displayName: BUILD and PUSH $(Build.SourceBranchName)
jobs:
- job: build_push_backend
pool:
vmImage: ubuntu-latest
displayName: "Build and Push"
steps:
- task: Docker@2
inputs:
containerRegistry: '$(Docker.registry)'
command: 'login'
- script: "docker pull $(Docker.registry).azurecr.io/$(Docker.repository):latest"
displayName: Pull latest for layer caching
continueOnError: true # for first build, no cache
- script: |
commitHash=${sourceVersion:0:7}
echo "##vso[task.setvariable variable=commitHash]$commitHash" ## Set variable for using in other tasks.
env: { sourceVersion: $(Build.SourceVersion) }
displayName: Git Hash 7-digit
continueOnError: true # for first build, no cache
- task: Docker@2
displayName: Build
inputs:
command: build
dockerfile: $(Docker.filePath)
repository: $(Docker.repository)
buildContext: "**/.."
# arguments: '--build-arg VERSION=$(Build.SourceVersion) --build-arg BUILD_DATE="$(buildDate)" --cache-from=$(Docker.registry).azurecr.io/$(Docker.repository):latest'
arguments: '--build-arg VERSION="$(commitHash)" --build-arg BUILD_DATE="$(buildDate)" --cache-from=$(Docker.registry).azurecr.io/$(Docker.repository):latest'
tags: |
$(Build.BuildId)
$(Build.SourceVersion)
latest
- task: Docker@2
displayName: Push
inputs:
command: Push
buildContext: "**/.."
dockerfile: $(Docker.filePath)
repository: $(Docker.repository)
containerRegistry: $(Docker.registry)
tags: |
$(Build.BuildId)
$(Build.SourceVersion)
latest
- stage: deploy
displayName: Deploy
jobs:
- job: deploy_backend
pool:
vmImage: ubuntu-latest
displayName: "Deploy app"
steps:
- task: AzureWebAppContainer@1
displayName: Azure Web App on Container Deploy
inputs:
appName: $(appName)
azureSubscription: $(azureSubscription)
imageName: $(Docker.registry).azurecr.io/$(Docker.repository):$(Build.SourceVersion)
appSettings: "-DJANGO_ADMIN_URL $(DJANGO_ADMIN_URL)
-DJANGO_ADMIN_TITLE $(DJANGO_ADMIN_TITLE)
-CACHE_DEFAULT $(CACHE_DEFAULT)
-CONSTANCE_DATABASE_CACHE_BACKEND $(CONSTANCE_DATABASE_CACHE_BACKEND)
-ALLOWED_HOSTS $(ALLOWED_HOSTS)
-SECRET_KEY $(SECRET_KEY)
-DEBUG $(DEBUG)
-BUILD_VERSION $(Build.SourceVersion)
-LANGUAGE_CODE $(LANGUAGE_CODE)
-USE_X_FORWARDED_HOST $(USE_X_FORWARDED_HOST)
-ROOT_TOKEN $(ROOT_TOKEN)
-ADMIN_EMAIL $(ADMIN_EMAIL)
-ADMIN_PASSWORD $(ADMIN_PASSWORD)
-EMAIL_HOST_USER $(EMAIL_HOST_USER)
-MAILJET_API_KEY $(MAILJET_API_KEY)
-MAILJET_SECRET_KEY $(MAILJET_SECRET_KEY)
-AZURE_CLIENT_ID $(KEY_VALUT_AZURE_CLIENT_ID)
-AZURE_CLIENT_KEY $(KEY_VALUT_AZURE_CLIENT_ID)
-AZURE_CLIENT_SECRET $(KEY_VALUT_AZURE_CLIENT_SECRET)
-AZURE_TENANT_ID $(KEY_VALUT_AZURE_TENANT_KEY)
-SENTRY_DSN $(SENTRY_DSN)
-SENTRY_ENVIRONMENT $(SENTRY_ENVIRONMENT)
-MATOMO_ID $(MATOMO_ID)"