Test your custom registry ports using vcpkg with Azure DevOps
Artikkel
Once you have set up a custom registry of vcpkg ports, you may want to add
continous integration to validate that all your dependencies can be built
successfully.
The main vcpkg registry at
Microsoft/vcpkg is tested by the vcpkg
team using a continuous integration (CI) pipeline with Azure DevOps. This
ensures that adding new packages or updating existing ones does not break consumers.
In this article, we show you how to set up a CI environment to test the vcpkg
ports in your own registry.
In this article, you'll learn to:
Set up a binary cache and asset cache for your Azure DevOps pipeline
Set up a binary cache and asset cache for your Azure DevOps pipelines
Building a large collection of ports is an expensive task both in terms of
time and computing power. We strongly recommend that before engaging CI for
your ports, you invest in setting up a binary cache and an asset cache for your
Azure DevOps pipelines.
A binary cache provides the most benefit for CI scenarios by ensuring that
unmodified packages aren't rebuilt on every CI run. An asset cache mirrors
artifacts downloaded for your packages during a run and uses the cached
artifacts in subsequent runs. It can also help mitigate issues where the
upstream repository is unreliable: for example, a broken download URL.
This example shows how to set up a binary cache and asset cache in an Azure
DevOps pipeline. You should adapt this snippet to use on your own pipeline's
YAML file.
Breaking down this snippet:
X_VCPKG_ASSET_SOURCES is the environment variable used to configure asset caches
in vcpkg. In this example, it is set to
x-azurl,https://my.domain.com/container,$(VcpkgAssetCache),readwrite.
The x-azurl backend instructs vcpkg to use an Azure Storage container as the
storage provider. The x-azurl is followed by three parameters separated by
commas (,).
https://my.domain.com/container is a storage container URL.
$(VcpkgAssetCache) is a pipeline secret variable that contains a SAS token to
authenticate to the storage container.
readwrite sets read and write permissions for the asset cache. This means
that this asset cache is used to store artifacts as well as to restore
artifacts from it.
VCPKG_BINARY_SOURCES is the environment variable used to configure binary
caches in vcpkg. In this example, it is set to
clear;nuget,https://my.domain.com/vcpkgBinaryCache/nuget/v3/index.json,readwrite.
This enables the NuGet backend for the binary cache using the NuGet feed at
https://my.domain.com/vcpkgBinaryCache/nuget/v3/index.json. Some additional
steps may be required to authenticate to your NuGet feed, read the
tutorial
for instructions to set up NuGet authentication with ADO.
The following task should be added as-is in your pipeline in order to
authenticate to your Azure Artifacts NuGet feeds. This task should also run
before any task involving vcpkg.
- task: NuGetAuthenticate@1
If you're using a different host for your NuGet feeds read the documentation on
how to authenticate
NuGet.
Learn more about how all of these work by reading the documentation on the
asset cache and binary
cache features.
Set up a pipeline to test your registry's ports
After you have set up a binary cache and asset cache for your CI environment,
the next step is to set up a pipeline to test all your registry's ports. You can
decide whether this pipeline runs on a schedule or if it is triggered by new
commits or pull requests.
The main vcpkg registry uses the vcpkg ci command, which has been tailored to
the vcpkg project's needs and is not intended to remain stable or be used by
consumers of vcpkg. As such, it is not suited to use for testing your own vcpkg
registries. We recommend to follow the steps outlined in this article instead.
Use a manifest file to include all your ports
Instead of using the vcpkg ci command, we suggest using a manifest file to
create a build that depends on all the packages in your registry.
The following example, creates a manifest file to test all the ports in a
hypothetical vcpkg registry. Replace the list of dependencies to include all the
ports in your registry and place it in the root of your repository.
vcpkg.json
{
"dependencies": [
"beicode",
"beison"
]
}
Your own ports may have dependencies on the main vcpkg registry or other
third-party registries, in which case, you need to add those registries in a
vcpkg-configuration.json file. While vcpkg can resolve packages from the main
registry without additional configuration, we strongly recommend that you explicitly
add it to the registries list for version control purposes.
This ensures that you have control of the set of underlying port
versions. Check out the vcpkg x-update-baseline
command to help managing the baseline of your
registries.
In order to clone the vcpkg repository you need to define a repository
resource for your pipeline. The snippet below shows how to add the vcpkg
repository as a resource, you will need to set up a Service
Connection
to connect your pipeline to GitHub.
After checking out the vcpkg repository either as a submodule or by cloning it
from GitHub, you need to run vcpkg's bootstrap script.
steps:
- script: vcpkg/bootstrap-vcpkg.sh
Once these steps are completed you should have a vcpkg executable to work with.
Run vcpkg install to build your ports
The last step is to tell vcpkg to build all your ports. You may have noticed
that your own registry is absent from the vcpkg-configuration.json created a
couple of steps above. The reason is that you want to test the version of the
ports currently in the working directory as opposed to the versions published in
your repository.
To that goal, you need to add your registry's ports as overlay
ports by setting the VCPKG_OVERLAY_PORTS
environment variable to your registry's ports directory.
The snippet below shows how to set up your registry's ports as overlay ports and
runs vcpkg install in manifest mode to install all of your custom ports.
In this example we assume that the vcpkg.json file is created in the root of
your registry's repository and that the vcpkg repository is added as a submodule.
Putting it all together your pipelines's YAML file should look similar to this:
You may also want to add steps to automate the generation of the vcpkg.json
file or a step that verifies that ports newly added to your registry are not
left out of the tests.
Next steps
The following articles may be useful to you when setting up a CI environment.
Du finner kilden for dette innholdet på GitHub. Der du også kan opprette og se gjennom problemer og pull-forespørsler. Hvis du vil ha mer informasjon, kan du se vår bidragsyterveiledning.
vcpkg-tilbakemelding
vcpkg er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding:
Opprett automatiserte datasamlebånd som kontinuerlig bygger, tester og distribuerer programmene dine, og klargjør for eksamen AZ-400: Utforming og implementering av Microsoft DevOps Solutions.
Denne sertifiseringen måler din evne til å utføre følgende tekniske oppgaver: Utforme og implementere prosesser og kommunikasjon, utforme og implementere en strategi for kildekontroll, utforme og implementere bygg- og utgivelsessamlebånd, utvikle en sikkerhets- og samsvarsplan og implementere en instrumenteringsstrategi.