| page_type | languages | products | extensions | name | description | urlFragment | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
|
Performance Testing with K6 and ACI |
Automate performace tests using K6 and Azure Container Instance. |
k6-aci |
This sample code briefly describes how to use K6 performance testing tool to execute tests in Azure Container Instance(ACI).
You should have the following tools installed:
You should have the following Azure resources:
- Azure DevOps Project
- Azure Container Registry (ACR) with Admin user enabled
Log in to Azure through Azure CLI:
az loginNOTE: Make sure you are using the correct subscription. You can use
az account showto display what is the current selected one andaz account setto change it.
Configure Azure DevOps CLI with your organization/project settings:
ORGANIZATION_URL=https://dev.azure.com/your-organization
PROJECT_NAME=YourProject
az devops configure --defaults organization=$ORGANIZATION_URL project=$PROJECT_NAMEImport this repository on your Azure DevOps project:
REPOSITORY_NAME=k6-load-test-with-aci
REPOSITORY_URL=https://github.com/Azure-Samples/k6-load-test-with-aci
az repos create --name $REPOSITORY_NAME
az repos import create --git-source-url $REPOSITORY_URL --repository $REPOSITORY_NAMECreate an Azure service principal:
SERVICE_PRINCIPAL_NAME=AzureServicePrincipal
SERVICE_PRINCIPAL=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME)Run the following commands to fill the credentials variables:
CLIENT_ID=$(echo $SERVICE_PRINCIPAL | jq -r .appId)
CLIENT_SECRET=$(echo $SERVICE_PRINCIPAL | jq -r .password)
TENANT_ID=$(echo $SERVICE_PRINCIPAL | jq -r .tenant)
SUBSCRIPTION_ID=$(az account show | jq -r .id)
SUBSCRIPTION_NAME=$(az account show | jq -r .name)Create an Azure service connection on Azure DevOps:
SERVICE_CONNECTION_NAME=AzureServiceConnection
export AZURE_DEVOPS_EXT_AZURE_RM_SERVICE_PRINCIPAL_KEY=$CLIENT_SECRET
SERVICE_ENDPOINT_ID=$(az devops service-endpoint azurerm create --azure-rm-service-principal-id $CLIENT_ID \
--azure-rm-subscription-id $SUBSCRIPTION_ID --azure-rm-subscription-name $SUBSCRIPTION_NAME \
--azure-rm-tenant-id $TENANT_ID --name $SERVICE_CONNECTION_NAME | jq -r .id)
az devops service-endpoint update --id $SERVICE_ENDPOINT_ID --enable-for-all truePIPELINE_NAME_DOCKER=sample-app-build
az pipelines create --name $PIPELINE_NAME_DOCKER --repository $REPOSITORY_NAME \
--repository-type tfsgit --branch main \
--yml-path pipelines/azure-pipelines.docker.ymlPIPELINE_NAME_K6=k6-load-test
az pipelines create --name $PIPELINE_NAME_K6 --repository $REPOSITORY_NAME \
--repository-type tfsgit --branch main --skip-first-run \
--yml-path pipelines/azure-pipelines.load-test.yml