Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 640091f

Browse files
ADO Pipeline to update a onefuzz instance with the latest release (#208)
1 parent e76064b commit 640091f

File tree

9 files changed

+467
-0
lines changed

9 files changed

+467
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,python
4+
5+
### Python ###
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
pip-wheel-metadata/
29+
share/python-wheels/
30+
*.egg-info/
31+
.installed.cfg
32+
*.egg
33+
MANIFEST
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.nox/
49+
.coverage
50+
.coverage.*
51+
.cache
52+
nosetests.xml
53+
coverage.xml
54+
*.cover
55+
*.py,cover
56+
.hypothesis/
57+
.pytest_cache/
58+
pytestdebug.log
59+
60+
# Translations
61+
*.mo
62+
*.pot
63+
64+
# Django stuff:
65+
*.log
66+
local_settings.py
67+
db.sqlite3
68+
db.sqlite3-journal
69+
70+
# Flask stuff:
71+
instance/
72+
.webassets-cache
73+
74+
# Scrapy stuff:
75+
.scrapy
76+
77+
# Sphinx documentation
78+
docs/_build/
79+
doc/_build/
80+
81+
# PyBuilder
82+
target/
83+
84+
# Jupyter Notebook
85+
.ipynb_checkpoints
86+
87+
# IPython
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv
92+
.python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
138+
# pytype static type analyzer
139+
.pytype/
140+
141+
### VisualStudioCode ###
142+
.vscode/*
143+
.vscode/settings.json
144+
!.vscode/tasks.json
145+
!.vscode/launch.json
146+
!.vscode/extensions.json
147+
*.code-workspace
148+
149+
### VisualStudioCode Patch ###
150+
# Ignore all local history of files
151+
.history
152+
153+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[MASTER]
2+
ignore=CVS .git .hg
3+
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
4+
5+
[MESSAGES CONTROL]
6+
# Pointless whinging.
7+
# W0613 = Unused argument
8+
# R0201 = Method could be a function
9+
# R0801 = Similar lines https://github.com/PyCQA/pylint/issues/214
10+
# R0901 = Too many ancestors
11+
# R0902 = Too many instance attributes
12+
# R0903 = Too few public methods
13+
# R0904 = Too many public methods
14+
# R0911 = Too many return statements
15+
# R0913 = Too many arguments
16+
# R0914 = Too many local variables
17+
#
18+
# Sometimes disabled depending on how bad a module is.
19+
# C0111 = Missing docstring
20+
# C0112 = Empty docstring
21+
22+
disable=C0111,R0201,R0801,R0901,R0902,R0903,R0904,R0911,R0913,R0914
23+
24+
[FORMAT]
25+
max-line-length=80
26+
27+
[REPORTS]
28+
output-format=colorized
29+
30+
[BASIC]
31+
good-names=i,j,k,_,logger
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
requests = "*"
10+
11+
[requires]
12+
python_version = "3.8"

contrib/deploy-onefuzz-via-azure-devops/Pipfile.lock

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# What is this for?
2+
3+
This section of code contains scripts which help to deploy latest releases of OneFuzz at demand. It uses Azure DevOps Build Pipeline.
4+
5+
The script [deploy-onefuzz.yml](deploy-onefuzz.yml) can be used saved in Azure DevOps Build Pipeline or can be stored in the repository and can be pointed to it.
6+
7+
It also contain supporting `python` scripts which helps to fetch latest version and artifacts from OneFuzz GitHub repository.
8+
9+
# How to use it?
10+
11+
This script is intended only for deploying newer updates. There are certain set of pipeline variables needs to be set as mentioned in [deploy-onefuzz.yml](deploy-onefuzz.yml) for authentication purposes to the OneFuzz instance.

contrib/deploy-onefuzz-via-azure-devops/__init__.py

Whitespace-only changes.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
# It is designed to deploy latest versions in the Azure. There are fixed set of pipeline
5+
# variables which can be used to update onefuzz instances on Azure.
6+
#
7+
# Following the OneFuzz document at
8+
# https://github.com/microsoft/onefuzz/blob/main/docs/getting-started.md#deploying-an-instance-of-onefuzz
9+
# to deploy OneFuzz on Azure.
10+
#
11+
# List of custom variables:
12+
# | Variable Name | Comments |
13+
# |----------------------|-----------------------------------------------------------|
14+
# |AZURE_CLIENT_ID | The appication ID created by you or the deployment script |
15+
# |AZURE_CLIENT_SECRET | Secret created by App registration process |
16+
# |AZURE_TENANT_ID | Tenant ID of the Azure Subscription |
17+
# |CONTACT_EMAIL_ADDRESS | Email address for communication |
18+
# |ONEFUZZ_DEPLOY_LOC | Deployment Folder location of this script location |
19+
# |ONEFUZZ_INSTANCE_NAME | Instance name of Onefuzz Deployement |
20+
# |ONEFUZZ_SERVICE_URL | OneFuzz service URL. Generally the url defined in App |
21+
# | | Registration |
22+
# |REGION | OneFuzz Region (prefer westus2) |
23+
# |RESOURCE_GROUP_NAME | Resource gorup name for OneFuzz deployment |
24+
#
25+
# Note: Make sure to provide the App owners permission to onefuzz resource group
26+
27+
---
28+
trigger: none
29+
30+
stages:
31+
- stage: Deploy
32+
jobs:
33+
- job: "deploy_oneFuzz"
34+
pool:
35+
vmImage: "ubuntu-latest"
36+
steps:
37+
- task: UsePythonVersion@0
38+
inputs:
39+
versionSpec: "3.8"
40+
41+
- task: CmdLine@2
42+
name: onefuzz_release
43+
displayName: "Downloading OneFuzz Artifacts"
44+
inputs:
45+
workingDirectory: "$(ONEFUZZ_DEPLOY_LOC)"
46+
script: |
47+
set -ex
48+
python -m pip install pipenv tox
49+
pipenv install
50+
artifact="artifact"
51+
pipenv run python get_latest_version.py -path $artifact
52+
version="$(pipenv run python get_latest_version.py -version)"
53+
echo "Onefuzz version is $version"
54+
echo "##vso[task.setvariable variable=version;isOutput=true]$version"
55+
echo "##vso[task.setvariable variable=artifact]$artifact"
56+
57+
- task: CmdLine@2
58+
displayName: "Installing Dependencies"
59+
inputs:
60+
workingDirectory: "$(ONEFUZZ_DEPLOY_LOC)/$(artifact)"
61+
script: |
62+
set -ex
63+
unzip onefuzz-deployment-$(onefuzz_release.version).zip
64+
pip install -r requirements.txt
65+
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
66+
sudo dpkg -i packages-microsoft-prod.deb
67+
sudo apt-get update
68+
sudo apt-get install azure-functions-core-tools-3
69+
70+
- task: CmdLine@2
71+
displayName: "Deploying update to OneFuzz"
72+
inputs:
73+
workingDirectory: "$(ONEFUZZ_DEPLOY_LOC)/$(artifact)"
74+
script: |
75+
set -ex
76+
az login --service-principal -u $(ONEFUZZ_SERVICE_URL) -p $(AZURE_CLIENT_SECRET) --tenant $(AZURE_TENANT_ID)
77+
python deploy.py --client_id $(AZURE_CLIENT_ID) --client_secret $(AZURE_CLIENT_SECRET) $REGION $RESOURCE_GROUP_NAME $ONEFUZZ_INSTANCE_NAME $CONTACT_EMAIL_ADDRESS
78+
echo "Deployed Onefuzz $(onefuzz_release.version)"
79+
80+
- task: CopyFiles@2
81+
displayName: "Copying cli to Staging area"
82+
inputs:
83+
SourceFolder: "$(ONEFUZZ_DEPLOY_LOC)/$(artifact)"
84+
Contents:
85+
"onefuzz-cli-$(onefuzz_release.version).exe"
86+
TargetFolder: $(Build.ArtifactStagingDirectory)
87+
flattenFolders: true
88+
89+
- task: PublishBuildArtifacts@1
90+
displayName: "Publish CLI exe"
91+
inputs:
92+
PathtoPublish: "$(Build.ArtifactStagingDirectory)"
93+
ArtifactName: "onefuzz"
94+
publishLocation: "Container"
95+
96+
- stage: "Verify"
97+
jobs:
98+
- job: "verify_onefuzz_version"
99+
pool:
100+
vmImage: "windows-latest"
101+
variables:
102+
version: $[ stageDependencies.Deploy.deploy_oneFuzz.outputs['onefuzz_release.version'] ]
103+
steps:
104+
- download: current
105+
artifact: onefuzz
106+
107+
- task: Bash@3
108+
displayName: Test OneFuzz Deployment version
109+
timeoutInMinutes: 1
110+
inputs:
111+
workingDirectory: "$(Pipeline.Workspace)/onefuzz"
112+
targetType: 'inline'
113+
script: |
114+
set -ex
115+
./onefuzz-cli-$(version).exe config --endpoint $(ONEFUZZ_SERVICE_URL) --client_id "$(AZURE_CLIENT_ID)" --client_secret "$(AZURE_CLIENT_SECRET)"
116+
./onefuzz-cli-$(version).exe --version
117+
until ./onefuzz-cli-$(version).exe versions check --exact; do echo "waiting due to version mismatch"; sleep 1; done

0 commit comments

Comments
 (0)