-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromote-to-higher-env.yml
161 lines (142 loc) · 6.84 KB
/
promote-to-higher-env.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
trigger: none
parameters:
- name: sourceenvironment
displayName: Source Environment
type: string
default: test
values:
- test
- test1
- staging
- name: targetenvironment
displayName: Target Environment
type: string
default: staging
values:
- staging
- prod
- test1
- name: application
displayName: Application
type: string
default: triage
values:
- pensionwise-triage
- pensionwise-appointment
- moneyhelper-tools
- pensions-dashboard
- money-adviser-network
- name: acrName
displayName: ACR Name
type: string
values:
- pensionwise
- moneyhelper
- pensions
- money
pool:
vmImage: 'ubuntu-latest'
variables:
- template: templates/variables/${{ parameters.targetenvironment }}.yml
stages:
- stage: Build
jobs:
- job: Promote_${{ parameters.sourceenvironment }}_to_${{ parameters.targetenvironment }}
displayName: Promote ${{ parameters.sourceenvironment }} to ${{ parameters.targetenvironment }}
steps:
- checkout: self
clean: 'true'
persistCredentials: 'true'
fetchDepth: 10
displayName: Check out source code from main repository
- script: |
git fetch origin main:main
displayName: Fetch the latest history for main branch
- script: |
git checkout -B main
git fetch origin main
git reset --hard origin/main
displayName: Fetch and checkout main branch
- script: |
git fetch origin main:refs/remotes/origin/main
displayName: Fetch and checkout main branch
- script: |
git fetch --tags
git show-ref --tags
displayName: Fetch all tags from repository
- script: |
sudo apt-get install jq
displayName: Install jq packages
- script: |
az login --service-principal --username $(AKS_SPN_ID) --password $(AKS_SPN_KEY) --tenant $(TENANT_ID)
resource_group=${{ parameters.acrName }}-${{ parameters.sourceenvironment }}-uksouth-rg
name=${{ parameters.sourceenvironment }}-${{ parameters.application }}
echo "name = $name,resource_group=$resource_group"
az account set --subscription $(AZURE_SUBSCRIPTION_ID)
jsonstr=$(az webapp config appsettings list --name $name --resource-group $resource_group )
echo "jsonstr is $jsonstr"
projtag=$(echo $jsonstr | jq -r '.[] | select(.name == "projtag") | .value')
echo "projtag is $projtag"
echo "##vso[task.setvariable variable=projtag;]$projtag"
displayName: 'Get configuration'
- script: |
git checkout $projtag
git branch
displayName: Fetch and checkout the tagged RC deployed to the source environment
- template: templates/steps/install-node-js.yml
- script: |
echo "keyvaultname is $(keyvaultname)"
variablesString=""
az login --service-principal --username $(AKS_SPN_ID) --password $(AKS_SPN_KEY) --tenant $(TENANT_ID)
secrets=$(az keyvault secret list --vault-name $(keyvaultname) --query "[].name" -o tsv)
for secretName in $secrets; do
if [[ $secretName == NEXT-PUBLIC-* ]]; then
secretValue=$(az keyvault secret show --name $secretName --vault-name $(keyvaultname) --query "value" -o tsv)
secretName="${secretName//-/_}"
variablesString+="$secretName=$secretValue "
echo "param $secretName=$secretValue"
export "$secretName=$secretValue"
fi
done
appname=${{ parameters.application }}
echo "appname is $appname"
npm ci
eval "$variablesString npx nx run \"${appname}:build\""
rm -rf packages
mkdir -p packages #make directory packages
cp package.json ./packages # copy package.json to packages\
cp .dockerignore ./packages # copy .dockerignore to packages
cp package-lock.json ./packages # copy package-lock.json to packages
cp tsconfig.base.json ./packages # copy tsconfig.base.json to packages
cp $appname.dockerfile ./packages # copy dockerfile to packages
cp -rf apps/"$appname"/public ./packages # copy the app to packages
cp -rf libs ./packages/ # copy the library to packages
cp -rf dist/apps/$appname/.next ./packages/.next # copy the .next folder to packages
cd packages || exit
acr_name=${{ parameters.acrName }}
mv $appname.dockerfile dockerfile
npm ci # run npm ci
echo "projtag target is $(projtag)"
version=${{ parameters.targetenvironment }}-$(projtag)
echo "Version is $version"
az login --service-principal --username $(AKS_SPN_ID) --password $(AKS_SPN_KEY) --tenant $(TENANT_ID)
az acr login --name ${{ parameters.acrName }}
dockertagname="${acr_name}.azurecr.io/${appname}:${version}"
echo "dockertagname source is $dockertagname"
docker build -t ${acr_name}.azurecr.io/${appname}:${version} .
docker push ${acr_name}.azurecr.io/${appname}:${version}
echo "##vso[task.setvariable variable=dockertagname;]$dockertagname"
displayName: 'build and dockerise ${{ parameters.application }}'
- template: templates/jobs/update-env-vars.yml
parameters:
resource_group: ${{ parameters.acrName }}-${{ parameters.targetenvironment }}-uksouth-rg
APP_NAME: ${{ parameters.targetenvironment }}-${{ parameters.application }}
acrName: ${{ parameters.acrName }}
environment: ${{ parameters.targetenvironment }}
- script: |
echo "dockertagname target is $dockertagname projtag is $(projtag)"
az login --service-principal --username $(AKS_SPN_ID) --password $(AKS_SPN_KEY) --tenant $(TENANT_ID)
az account set --subscription $(AZURE_SUBSCRIPTION_ID)
az webapp config container set -n "${{ parameters.targetenvironment }}-${{ parameters.application }}" -g ${{ parameters.acrName }}-${{ parameters.targetenvironment }}-uksouth-rg --container-image-name "$(dockertagname)"
az webapp config appsettings set -g ${{ parameters.acrName }}-${{ parameters.targetenvironment }}-uksouth-rg -n "${{ parameters.targetenvironment }}-${{ parameters.application }}" --settings "projtag=$(projtag)"
displayName: 'deploy to ${{ parameters.targetenvironment }}'