Updated deploy-onefuzz-via-azure-devops (#233)

This commit is contained in:
anslutsk
2020-10-29 15:22:36 -07:00
committed by GitHub
parent ced8200d74
commit d2996656f6
2 changed files with 44 additions and 23 deletions

View File

@ -9,18 +9,20 @@
# to deploy OneFuzz on Azure.
#
# List of custom variables:
# | Variable Name | Comments |
# |----------------------|-----------------------------------------------------------|
# |AZURE_CLIENT_ID | The appication ID created by you or the deployment script |
# |AZURE_CLIENT_SECRET | Secret created by App registration process |
# |AZURE_TENANT_ID | Tenant ID of the Azure Subscription |
# |CONTACT_EMAIL_ADDRESS | Email address for communication |
# |ONEFUZZ_DEPLOY_LOC | Deployment Folder location of this script location |
# |ONEFUZZ_INSTANCE_NAME | Instance name of Onefuzz Deployement |
# |ONEFUZZ_SERVICE_URL | OneFuzz service URL. Generally the url defined in App |
# | | Registration |
# |REGION | OneFuzz Region (prefer westus2) |
# |RESOURCE_GROUP_NAME | Resource gorup name for OneFuzz deployment |
# | Variable Name | Comments | Required/Optional |
# |----------------------|-----------------------------------------------------------|-------------------|
# |AZURE_CLIENT_ID | The appication ID created by you or the deployment script | Required |
# |AZURE_CLIENT_SECRET | Secret created by App registration process | Required |
# |AZURE_TENANT_ID | Tenant ID of the Azure Subscription | Required |
# |CONTACT_EMAIL_ADDRESS | Email address for communication | Required |
# |DEPLOY_ARGS | Specify OneFuzz deploy.py arguments | Optional |
# |ONEFUZZ_DEPLOY_LOC | Deployment Folder location of this script location | Required |
# |ONEFUZZ_INSTANCE_NAME | Instance name of Onefuzz Deployement | Required |
# |ONEFUZZ_SERVICE_URL | OneFuzz service URL. Generally the url defined in App | Required |
# | | Registration | Required |
# |REGION | OneFuzz Region (prefer westus2) | Required |
# |RESOURCE_GROUP_NAME | Resource group name for OneFuzz deployment | Required |
# |VERSION | Specify OneFuzz version, defaults to latest | Optional |
#
# Note: Make sure to provide the App owners permission to onefuzz resource group
@ -48,8 +50,14 @@ stages:
python -m pip install pipenv tox
pipenv install
artifact="artifact"
pipenv run python get_latest_version.py -path $artifact
version="$(pipenv run python get_latest_version.py -version)"
if [ -z $(VERSION) ]
then
pipenv run python get_latest_version.py -path $artifact
version="$(pipenv run python get_latest_version.py -display_latest_version)"
else
pipenv run python get_latest_version.py -path $artifact -version $(VERSION)
version="$(VERSION)"
fi
echo "Onefuzz version is $version"
echo "##vso[task.setvariable variable=version;isOutput=true]$version"
echo "##vso[task.setvariable variable=artifact]$artifact"
@ -74,7 +82,7 @@ stages:
script: |
set -ex
az login --service-principal -u $(ONEFUZZ_SERVICE_URL) -p $(AZURE_CLIENT_SECRET) --tenant $(AZURE_TENANT_ID)
python deploy.py --client_id $(AZURE_CLIENT_ID) --client_secret $(AZURE_CLIENT_SECRET) $REGION $RESOURCE_GROUP_NAME $ONEFUZZ_INSTANCE_NAME $CONTACT_EMAIL_ADDRESS
python deploy.py --client_id $(AZURE_CLIENT_ID) --client_secret $(AZURE_CLIENT_SECRET) $REGION $RESOURCE_GROUP_NAME $ONEFUZZ_INSTANCE_NAME $CONTACT_EMAIL_ADDRESS $DEPLOY_ARGS
echo "Deployed Onefuzz $(onefuzz_release.version)"
- task: CopyFiles@2

View File

@ -11,9 +11,16 @@ BASE_URL = "https://api.github.com/repos/microsoft/onefuzz"
class Onefuzz:
def get_latest_version(self):
latest_releasee = requests.get(f"{BASE_URL}/releases/latest").json()
return (latest_releasee["id"], latest_releasee["name"])
def get_latest_version_name(self):
latest_release = requests.get(f"{BASE_URL}/releases/latest").json()
return latest_release["name"]
def get_release_id_by_name(self, version_name=None):
if version_name is None:
release = requests.get(f"{BASE_URL}/releases/latest").json()
else:
release = requests.get(f"{BASE_URL}/releases/tags/{version_name}").json()
return release["id"]
def list_assets(self, release_id):
assets = requests.get(f"{BASE_URL}/releases/{release_id}/assets").json()
@ -34,8 +41,8 @@ class Onefuzz:
for artifact in artifacts:
self.download_artifact(path, artifact["id"], artifact["name"])
def onefuzz_release_artifacts(self, path):
release_id, _ = self.get_latest_version()
def onefuzz_release_artifacts(self, path, version):
release_id = self.get_release_id_by_name(version)
artifacts = self.list_assets(release_id)
self.download_artifacts(path, artifacts)
@ -55,16 +62,22 @@ def main():
)
parser.add_argument(
"-version",
type=str,
default=None,
help="Get specific Onefuzz version",
)
parser.add_argument(
"-display_latest_version",
action="store_true",
help="Get Onefuzz latest version",
)
args = parser.parse_args()
if args.path:
Onefuzz().onefuzz_release_artifacts(args.path)
Onefuzz().onefuzz_release_artifacts(args.path, args.version)
if args.version:
print(Onefuzz().get_latest_version()[1])
if args.display_latest_version:
print(Onefuzz().get_latest_version_name())
if __name__ == "__main__":