官术网_书友最值得收藏!

Automatic builds for Azure Container Registry

Azure Container Registry offers similar functionality to Docker Hub for the automation of Docker image builds on code push. The pipeline is highly customizable and can support building multiple container images at once, but in this example, we will focus on automating a single image build on the GitHub repository code push.

For more advanced multi-step and multi-container scenarios, check out the official documentation: https://docs.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-multistep-task.

Integrating ACR and GitHub can be performed as follows:

  1. Create a new GitHub repository and push the Docker image source code. In this example, we will use source code from https://github.com/PacktPublishing/Hands-On-Kubernetes-on-Windows/tree/master/Chapter03/04_iis-demo-index, which will be pushed to a new GitHub repository, that is, https://github.com/hands-on-kubernetes-on-windows/iis-demo-index.
  2. Generate a GitHub Personal Access Token (PAT) in order to access the repository in ACR. Navigate to https://github.com/settings/tokens/new.
  3. Enter a PAT description and choose the repo:status and public_repo scopes (for private repositories, you need to use a full repo scope):

  1. Click the Generate token button.
  2. You will be provided with a PAT value. Copy the token to a secure location as you will need it to set up integration.
  3. Now, let's create an ACR task called iis-demo-index-task. This will be triggered automatically when code is pushed to https://github.com/hands-on-kubernetes-on-windows/iis-demo-index. The required parameters are similar to the build configuration for Docker Hub:
az acr task create `
--registry handsonkubernetesonwinregistry `
--name iis-demo-index-task `
--platform windows `
--image "iis-demo-index:{{.Run.ID}}" `
--context https://github.com/hands-on-kubernetes-on-windows/iis-demo-index `
--branch master `
--file Dockerfile `
--git-access-token <gitHubPersonalAccessTokenValue>
If you run into an  az acr task create: 'utputformat' is not a valid value for '--output'. See 'az acr task create --help'. error being returned by the Azure CLI, ensure that you are escaping/quoting curly brackets for PowerShell properly.
  1. Test your ACR task definition using the az acr task run command:
az acr task run `
--registry
handsonkubernetesonwinregistry `
--name
iis-demo-index-task
  1. In the source code for your Docker image, introduce a change and commit and push it to the GitHub repository. For example, modify the static text so that it reads as follows:
Hello World from IIS container! The image is provided by Azure Container Registry and automatically built by Azure Container Registry task.
  1. Retrieve the ACR task logs to verify that the task was indeed triggered:
az acr task logs --registry handsonkubernetesonwinregistry

You should see an output similar to the following, which indicates that a new task instance was triggered by the push:

  1. When the task is finished, pull the image tagged with Run ID (in this case, this is cb5). You can also use the latest tag, but this requires removing a locally cached image using the docker rmi command:
docker pull handsonkubernetesonwinregistry.azurecr.io/iis-demo-index:cb5
  1. Create a new container using the handsonkubernetesonwinregistry.azurecr.io/iis-demo-index:cb5 image:
docker run -it --rm `
-p 8080:80 `
handsonkubernetesonwinregistry.azurecr.io/iis-demo-index:cb5
  1. Navigate to http://localhost:8080 in a web browser and verify that the container is running as expected. Also, verify that the static HTML page contains changes that were introduced in the code push:

Other cloud service providers have similar offerings for setting up Docker image registries and build pipelines. If you are interested in Google Cloud Platform services, please check out GCP Cloud Build:  https://cloud.google.com/cloud-build/docs/quickstart-docker.

You have successfully set up your Docker image build pipeline using GitHub and Azure Container Registry  congratulations! Now, we will take a quick look at best practices for image tagging and versioning.

主站蜘蛛池模板: 江源县| 个旧市| 富宁县| 卫辉市| 凤山县| 澄江县| 靖远县| 同仁县| 固原市| 本溪| 上犹县| 永善县| 双柏县| 东丰县| 辽宁省| 平泉县| 日照市| 河曲县| 阳西县| 安庆市| 金昌市| 望奎县| 彭州市| 厦门市| 仁怀市| 克山县| 华阴市| 湘阴县| 铜山县| 四川省| 探索| 和田县| 泾源县| 云和县| 普兰县| 手机| 邢台市| 广汉市| 乌鲁木齐市| 青田县| 石嘴山市|