-
Notifications
You must be signed in to change notification settings - Fork 4
/
azure-pipelines.yml
200 lines (167 loc) · 6.83 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
trigger:
branches:
include:
- master
- develop
- release/*
paths:
exclude:
- README.md
pr:
- master
- develop
variables:
group: 'pipelines'
testsOnly: False
stages:
- stage: Deploy
condition: eq(variables['testsOnly'], False)
jobs:
- job: Platform
timeoutInMinutes: 30
pool:
name: 'GCP Ubuntu 1604'
steps:
- task: DownloadSecureFile@1
name: azureGcpJson
displayName: 'Download secure file for azure to access gcp'
inputs:
secureFile: 'azure-gcp.json'
- task: DownloadSecureFile@1
name: cicdTfvars
displayName: 'Download terraform ftvars file fo CICD platform deployment'
inputs:
secureFile: cicd.tfvars
- script: |
curl -s https://packagecloud.io/install/repositories/iofog/iofogctl/script.deb.sh | sudo bash
sudo apt-get install --allow-downgrades -y iofogctl=1.3.0-rc2
displayName: 'Install iofogctl'
- script: |
./bootstrap.sh --gcloud-service-account $(azureGcpJson.secureFilePath)
echo "##vso[task.setvariable variable=GOOGLE_APPLICATION_CREDENTIALS]$(Agent.TempDirectory)/$(azureGcpJson.secureFilePath)"
displayName: 'Setup tools and gcloud credentials'
- script: |
cp $(cicdTfvars.secureFilePath) ./infrastructure/gcp
cp $(azureGcpJson.secureFilePath) ./azure-gcp.json
displayName: 'Copy secret files'
- script: |
./deploy.sh infrastructure/gcp/cicd.tfvars
displayName: 'Deploy infrastructure'
- script: |
ls -lR
mv $(terraform output kubeconfig) cicd.kubeconfig
displayName: 'Rename kubeconfig to remove random suffix'
workingDirectory: $(System.DefaultWorkingDirectory)/infrastructure/gcp
- publish: $(System.DefaultWorkingDirectory)/ecn.yaml
artifact: ecn.yaml
- publish: $(System.DefaultWorkingDirectory)/infrastructure/gcp/cicd.kubeconfig
artifact: cicd.kubeconfig
- stage: Tests
dependsOn:
- Deploy
condition: or(eq(variables['testsOnly'], True), in(dependencies.Deploy.result, 'Succeeded', 'SucceededWithIssues'))
jobs:
- job: Deploy_ECN
timeoutInMinutes: 30
pool:
name: 'GCP Ubuntu 1604'
steps:
- download: current
- task: DownloadSecureFile@1
name: azureSshKey
displayName: 'Download secure file for ssh access for agents'
inputs:
secureFile: 'azure_ssh_key'
- script: |
cp $(azureSshKey.secureFilePath) ./azure_ssh_key
chmod 400 ./azure_ssh_key
displayName: 'Copy secret files'
- script: |
rm -rf ~/.iofog
displayName: 'Delete iofogctl state'
- script: |
cat "$(Pipeline.Workspace)/ecn.yaml/ecn.yaml" | \
docker run -i --rm mikefarah/yq yq w -d0 - 'spec.controllers[0].kube.config' $(Pipeline.Workspace)/cicd.kubeconfig/cicd.kubeconfig | \
docker run -i --rm mikefarah/yq yq w -d1 - 'spec.kube.config' $(Pipeline.Workspace)/cicd.kubeconfig/cicd.kubeconfig | \
docker run -i --rm mikefarah/yq yq w -d2 - 'spec.ssh.keyFile' "$PWD/azure_ssh_key" > ecn.yaml
cat ecn.yaml
displayName: 'Prepare ECN configuration yaml file'
- script: |
iofogctl create namespace iofog
iofogctl -n iofog deploy -v -f ecn.yaml
displayName: 'Deploy ECN'
- script: |
export KUBECONFIG="$(Pipeline.Workspace)/cicd.kubeconfig/cicd.kubeconfig"
kubectl get all -n iofog -o wide
displayName: 'Print all GKE resources deployed'
condition: always()
- script: |
set -o errexit -o pipefail
export KUBECONFIG="$(Pipeline.Workspace)/cicd.kubeconfig/cicd.kubeconfig"
CONTROLLER_IP=$(kubectl -n iofog get service controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
CONTROLLER_EMAIL=$(cat ecn.yaml | docker run -i --rm mikefarah/yq yq r -d0 - spec.iofogUser.email)
CONTROLLER_PASSWORD=$(cat ecn.yaml | docker run -i --rm mikefarah/yq yq r -d0 - spec.iofogUser.password)
AGENT_USER=$(cat ecn.yaml | docker run -i --rm mikefarah/yq yq r -d2 - spec.ssh.user)
AGENT_HOST=$(cat ecn.yaml | docker run -i --rm mikefarah/yq yq r -d2 - spec.host)
AGENT_PORT=22
echo "CONTROLLER_IP: ${CONTROLLER_IP}"
echo "CONTROLLER_EMAIL: ${CONTROLLER_EMAIL}"
echo "CONTROLLER_PASSWORD: ${CONTROLLER_PASSWORD}"
echo "AGENT_USER: ${AGENT_USER}"
echo "AGENT_HOST: ${AGENT_HOST}"
echo "AGENT_PORT: ${AGENT_PORT}"
gcloud auth configure-docker --quiet
mkdir "$(Agent.TempDirectory)/test-results"
sudo docker pull gcr.io/focal-freedom-236620/test-runner:latest
sudo docker run --rm --name test-runner \
-v "$PWD/azure_ssh_key":/root/.ssh/id_rsa \
-v "$(Agent.TempDirectory)/test-results":/root/test-results \
-e CONTROLLER="${CONTROLLER_IP}:51121" \
-e CONTROLLER_EMAIL="${CONTROLLER_EMAIL}" \
-e CONTROLLER_PASSWORD="${CONTROLLER_PASSWORD}" \
-e AGENTS="${AGENT_USER}@${AGENT_HOST}:${AGENT_PORT}" \
gcr.io/focal-freedom-236620/test-runner:latest
ls "$(Agent.TempDirectory)/test-results"
displayName: 'Run Tests'
- script: |
iofogctl -n iofog delete -v -f ecn.yaml
iofogctl delete namespace iofog
displayName: 'Delete ECN'
# Publish Test Results
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'TEST-*.xml'
searchFolder: '$(Agent.TempDirectory)/test-results'
displayName: 'Publish Test Results'
- stage: Cleanup
dependsOn:
- Deploy
- Tests
condition: eq(variables['testsOnly'], False)
jobs:
- job: Cleanup
timeoutInMinutes: 15
pool:
name: 'GCP Ubuntu 1604'
steps:
- task: DownloadSecureFile@1
name: azureGcpJson
displayName: 'Download secure file for azure to access gcp'
inputs:
secureFile: 'azure-gcp.json'
- task: DownloadSecureFile@1
displayName: 'Download terraform ftvars file fo CICD platform deployment'
inputs:
secureFile: cicd.tfvars
- script: |
cp $(cicdTfvars.secureFilePath) ./infrastructure/gcp
cp $(azureGcpJson.secureFilePath) ./azure-gcp.json
displayName: 'Copy secret files'
- script: |
./bootstrap.sh --gcloud-service-account $(azureGcpJson.secureFilePath)
echo "##vso[task.setvariable variable=GOOGLE_APPLICATION_CREDENTIALS]$(Agent.TempDirectory)/$(azureGcpJson.secureFilePath)"
displayName: 'Setup tools and gcloud credentials'
- script: |
./destroy.sh infrastructure/gcp/cicd.tfvars
displayName: 'Destroy infrastructure'