Skip to content

Commit d42e2bb

Browse files
author
SergeRadinovich
committed
Add parallel pipeline for multiple distributions
1 parent dc6dfae commit d42e2bb

File tree

8 files changed

+240
-55
lines changed

8 files changed

+240
-55
lines changed

azure-pipelines.yml

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,31 @@ schedules:
1313
- master
1414
- develop
1515

16-
pool:
17-
vmImage: 'ubuntu-16.04'
18-
19-
steps:
20-
21-
- task: DockerInstaller@0
22-
displayName: Docker Installer
23-
inputs:
24-
dockerVersion: 19.03.2
25-
releaseType: stable
26-
27-
- script: |
28-
# curl -s https://packagecloud.io/install/repositories/iofog/iofogctl/script.deb.sh | sudo bash
29-
# Using dev version of iofogctl until 1.3.0 release
30-
curl -s https://8c90601638aff0b3fb520971175089bbaba2cf7f29be9528:@packagecloud.io/install/repositories/iofog/iofogctl-snapshots/script.deb.sh | sudo bash
31-
sudo apt install iofogctl=1.3.0-dev
32-
displayName: 'Install iofogctl'
33-
34-
- script: |
35-
echo $(gcp.svcacc) | docker login -u _json_key --password-stdin https://gcr.io
36-
displayName: 'Docker connect to Registry'
37-
38-
- script: |
39-
./start.sh tutorial
40-
# Use dev version of agent and controller until 1.3.0 release
41-
# ./start.sh -ct gcr.io/focal-freedom-236620/controller:develop -a gcr.io/focal-freedom-236620/agent:develop -cn gcr.io/focal-freedom-236620/connector:develop
42-
displayName: 'Start Connector, Controller, Agent, and tutorial microservices'
43-
44-
- script: |
45-
./test.sh
46-
displayName: 'Run Tests'
47-
48-
- script: |
49-
./stop.sh
50-
displayName: 'Stop Connector, Controller, and Agent'
51-
52-
- script: |
53-
tar -c --transform 's,^\.,demo,' --exclude-from=.artifactignore -v --bzip2 -f $BUILD_ARTIFACTSTAGINGDIRECTORY/demo.tar.bz2 .
54-
55-
- task: PublishBuildArtifacts@1
56-
inputs:
57-
pathtoPublish: '$(Build.ArtifactStagingDirectory)/demo.tar.bz2'
58-
artifactName: 'demo.$(Build.BuildId).tar.bz2'
59-
60-
- script: |
61-
echo "===== IOFOG AGENT LOG ====="
62-
docker exec iofog-agent cat /var/log/agent.out.log
63-
displayName: 'Print logs'
64-
condition: failed()
16+
variables:
17+
jobuuid: $(Build.BuildId)$(Agent.Id)
18+
agent: ''
19+
key: '/tmp/id_rsa'
20+
cssh: 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $(key)'
21+
dir: '/tmp/demo'
22+
23+
jobs:
24+
25+
- template: templates/job.yaml
26+
parameters:
27+
name: bionic
28+
distro: $(gcp.vm.distro.bionic)
29+
30+
- template: templates/job.yaml
31+
parameters:
32+
name: xenial
33+
distro: $(gcp.vm.distro.xenial)
34+
35+
- template: templates/job.yaml
36+
parameters:
37+
name: buster
38+
distro: $(gcp.vm.distro.buster)
39+
40+
- template: templates/job.yaml
41+
parameters:
42+
name: stretch
43+
distro: $(gcp.vm.distro.stretch)

bootstrap.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
detect_os(){
6+
OS=$(uname)
7+
if [ ! "$OS" = "Linux" ]; then
8+
echo "Operating System $OS is not supported"
9+
exit 1
10+
fi
11+
if [ -f /etc/os-release ]; then
12+
. /etc/os-release
13+
DIST=$NAME
14+
VER=$VERSION_ID
15+
elif type lsb_release >/dev/null 2>&1; then
16+
DIST=$(lsb_release -si)
17+
VER=$(lsb_release -sr)
18+
elif [ -f /etc/lsb-release ]; then
19+
# For some versions of Debian/Ubuntu without lsb_release command
20+
. /etc/lsb-release
21+
DIST=$DISTRIB_ID
22+
VER=$DISTRIB_RELEASE
23+
elif [ -f /etc/debian_version ]; then
24+
# Older Debian/Ubuntu/etc.
25+
DIST=Debian
26+
VER=$(cat /etc/debian_version)
27+
elif [ -f /etc/SuSe-release ]; then
28+
# Older SuSE/etc.
29+
...
30+
elif [ -f /etc/redhat-release ]; then
31+
# Older Red Hat, CentOS, etc.
32+
...
33+
else
34+
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
35+
DIST=$(uname -s)
36+
VER=$(uname -r)
37+
fi
38+
DIST=$(echo "$DIST" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/")
39+
}
40+
41+
install_docker(){
42+
if [ -z "$(command -v docker)" ]; then
43+
curl -fsSL https://get.docker.com/ | sh
44+
fi
45+
sudo usermod -aG docker $USER
46+
if [ -z "$(command -v docker)" ]; then
47+
echo "Failed to install Docker"
48+
echo "Visit https://docs.docker.com/install/ for instructions on manual installation of Docker"
49+
fi
50+
}
51+
52+
install_iofogctl(){
53+
case "$DIST" in
54+
*ubuntu*|*debian*|*raspbian*)
55+
curl https://packagecloud.io/install/repositories/iofog/iofogctl/script.deb.sh | sudo bash
56+
sudo apt-get install iofogctl=1.3.0-rc2
57+
;;
58+
*fedora*|*centos*)
59+
curl https://packagecloud.io/install/repositories/iofog/iofogctl/script.rpm.sh | sudo bash
60+
sudo yum install iofogctl-1.3.0-rc2-1.x86_64
61+
;;
62+
*)
63+
echo "Failed to install iofogctl"
64+
echo "Linux distribution $DIST is not supported"
65+
exit 1
66+
;;
67+
esac
68+
}
69+
70+
detect_os
71+
install_docker
72+
install_iofogctl

start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
" >| init/iofog/local-stack.yaml
7373

7474
echoInfo "Deploying containers for ioFog stack..."
75-
iofogctl deploy -f init/iofog/local-stack.yaml
75+
iofogctl deploy -f init/iofog/local-stack.yaml -v
7676
}
7777

7878
checkProvisioning() {
@@ -88,7 +88,7 @@ startEnvironment() {
8888
local ENVIRONMENT="$1"
8989

9090
echoInfo "Deploying ${ENVIRONMENT} application..."
91-
iofogctl deploy application -f "init/${ENVIRONMENT}/config.yaml"
91+
iofogctl deploy application -f "init/${ENVIRONMENT}/config.yaml" -v
9292
echoInfo "It may take a while before ioFog stack creates all ${ENVIRONMENT} microservices."
9393
echo ""
9494
}

stop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ prettyHeader "Stopping ioFog Demo..."
3939
# Stop ioFog stack
4040
echoInfo "Stopping all containers..."
4141

42-
iofogctl delete all || iofogctl disconnect
42+
iofogctl delete all -v || iofogctl disconnect
4343

4444
# Remove generated files
4545
find test/conf -type f -not -name ".gitignore" -exec rm -f {} \;

templates/job.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
parameters:
2+
name: ''
3+
distro: ''
4+
5+
jobs:
6+
- job: ${{ parameters.name }}
7+
pool:
8+
vmImage: 'ubuntu-16.04'
9+
10+
steps:
11+
12+
- task: InstallSSHKey@0
13+
inputs:
14+
knownHostsEntry: $(ssh.knownhost)
15+
sshPublicKey: $(ssh.pub)
16+
sshKeySecureFile: id_rsa
17+
18+
- task: DownloadSecureFile@1
19+
displayName: 'Download SSH keys to'
20+
inputs:
21+
secureFile: 'id_rsa'
22+
23+
- script: |
24+
cat $(Agent.TempDirectory)/id_rsa > $(key)
25+
chmod 600 $(key)
26+
displayName: 'Prepare SSH key'
27+
28+
- template: vm-up.yaml
29+
parameters:
30+
distro: ${{ parameters.distro }}
31+
32+
- script: |
33+
echo "key: $(key)"
34+
echo "agent: $(agent)"
35+
echo "dir: $(dir)"
36+
$(cssh) $(agent) -- sudo apt -y install rsync
37+
rsync -Pavr -e "ssh -i $(key) -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" . $(agent):$(dir)
38+
$(cssh) $(agent) -- ls $(dir)
39+
displayName: 'Prepare VM'
40+
41+
- script: |
42+
echo "agent: $(agent)"
43+
echo "dir: $(dir)"
44+
$(cssh) $(agent) -- sh $(dir)/bootstrap.sh
45+
$(cssh) $(agent) -- docker ps
46+
$(cssh) $(agent) -- iofogctl version
47+
displayName: 'Bootstrap'
48+
49+
- script: |
50+
echo $(gcp.svcacc) > /tmp/svcacc.json
51+
rsync -Pavr -e "ssh -i $(key) -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" /tmp/svcacc.json $(agent):/tmp/
52+
$(cssh) $(agent) -- cat /tmp/svcacc.json | docker login -u _json_key --password-stdin https://gcr.io
53+
displayName: 'Docker connect to Registry'
54+
55+
# - script: |
56+
# docker pull gcr.io/focal-freedom-236620/controller:develop
57+
# docker pull gcr.io/focal-freedom-236620/connector:develop
58+
# docker pull gcr.io/focal-freedom-236620/agent:develop
59+
# displayName: 'Pull latest images'
60+
61+
- script: |
62+
$(cssh) $(agent) -- bash $(dir)/start.sh tutorial
63+
# Use dev version of agent and controller until 1.3.0 release
64+
# ./start.sh -ct gcr.io/focal-freedom-236620/controller:develop -a gcr.io/focal-freedom-236620/agent:develop -cn gcr.io/focal-freedom-236620/connector:develop
65+
displayName: 'Start Connector, Controller, Agent, and tutorial microservices'
66+
67+
- script: |
68+
$(cssh) $(agent) -- bash $(dir)/test.sh
69+
displayName: 'Run Tests'
70+
71+
- script: |
72+
$(cssh) $(agent) -- bash $(dir)/stop.sh
73+
displayName: 'Stop Connector, Controller, and Agent'
74+
75+
- script: |
76+
echo "===== IOFOG AGENT LOG ====="
77+
docker exec iofog-agent cat /var/log/agent.out.log
78+
displayName: 'Print logs'
79+
condition: failed()
80+
81+
- template: vm-down.yaml

templates/vm-down.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
steps:
2+
- script: |
3+
gcloud compute --project=$(gcp.project.name) instances delete demo-ci-$(jobuuid) --zone=$(gcp.vm.zone) --delete-disks=all -q
4+
displayName: 'Teardown VMs'
5+
condition: always()

templates/vm-up.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
parameters:
2+
distro: ''
3+
4+
steps:
5+
- task: DownloadSecureFile@1
6+
displayName: 'Download secure file'
7+
inputs:
8+
secureFile: 'azure-gcp.json'
9+
- bash: |
10+
echo "gcp.project.name: $(gcp.project.name)"
11+
CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
12+
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
13+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
14+
sudo apt-get update && sudo apt-get install google-cloud-sdk
15+
gcloud --quiet auth activate-service-account --key-file=$(Agent.TempDirectory)/azure-gcp.json
16+
gcloud --quiet config set project $(gcp.project.name)
17+
displayName: 'set up gcloud'
18+
- script: |
19+
distro=${{ parameters.distro }}
20+
repo=$([[ $distro == *"debian"* ]] && echo "debian-cloud" || echo "ubuntu-os-cloud")
21+
echo "distro: $distro"
22+
echo "repo: $repo"
23+
echo "gcp.project.name: $(gcp.project.name)"
24+
echo "gcp.vm.zone: $(gcp.vm.zone)"
25+
echo "gcp.svcacc.name: $(gcp.svcacc.name)"
26+
echo "jobuuid: $(jobuuid)"
27+
gcloud compute --project=$(gcp.project.name) instances create demo-ci-$(jobuuid) --zone=$(gcp.vm.zone) --machine-type=n1-standard-1 --subnet=default --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=$(gcp.svcacc.name) --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --image=$distro --image-project=$repo --boot-disk-size=200GB --boot-disk-type=pd-standard --boot-disk-device-name=demo-ci-$(jobuuid)
28+
vm_host=$(gcloud compute instances list | grep demo-ci-$(jobuuid) | awk '{print $5}')
29+
echo "vm_host: $vm_host"
30+
echo "##vso[task.setvariable variable=agent]$(gcp.vm.user)@$vm_host"
31+
displayName: 'Deploy Test VM'
32+
- script: |
33+
echo "agent: $(agent)"
34+
seconds=0
35+
until $(cssh) $(agent) -- echo "SSH success"; do
36+
if [ $seconds -gt 60 ]; then
37+
echo "Timed out waiting for $(agent)"
38+
exit 1
39+
fi
40+
seconds=$((seconds+1))
41+
sleep 1
42+
done
43+
displayName: 'Wait for SSH access'

test.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ if [[ -f "${CONFIGURE_SSH_LOG_FILE}" ]]; then
5353
fi
5454
echo '' > "${CONFIGURE_SSH_LOG_FILE}"
5555
{
56-
echo 'Removing /var/lib/apt/lists/lock' >> "${CONFIGURE_SSH_LOG_FILE}"
57-
docker exec iofog-agent sudo rm /var/lib/apt/lists/lock >> "${CONFIGURE_SSH_LOG_FILE}" 2>&1
5856
echo 'Updating apt-get' >> "${CONFIGURE_SSH_LOG_FILE}"
59-
docker exec iofog-agent apt-get update -y >> "${CONFIGURE_SSH_LOG_FILE}" 2>&1
57+
SECONDS=1
58+
until docker exec iofog-agent apt-get update -y >> "${CONFIGURE_SSH_LOG_FILE}" 2>&1; do
59+
if [ $SECONDS -gt 60 ]; then
60+
exit 1
61+
fi
62+
sleep 1
63+
SECONDS=$((SECONDS+1))
64+
done
6065
echo 'Installing Openssh-server' >> "${CONFIGURE_SSH_LOG_FILE}"
6166
docker exec iofog-agent apt-get install -y --fix-missing openssh-server >> "${CONFIGURE_SSH_LOG_FILE}" 2>&1
6267
echo 'Running apt-get install -fy' >> "${CONFIGURE_SSH_LOG_FILE}"

0 commit comments

Comments
 (0)