How to specify the target for multi-stage docker build through io.fabric8 docker-maven-plugin? - docker-compose

I can pass target in docker-compose.yml to make sure to execute only the stage that I want to in multi-stage docker build.
How can I achieve the same with io.fabric8 docker-maven-plugin?

Related

Run Kaniko as a sidecar with VSTS agent

I run VSTS agents as pods in Kubernetes. Now I need to build docker images via Kaniko. If I add Kaniko as a sidecar to the VSTS agent, How can I specifically mention it in the Azure pipeline, to run the image build steps in Kaniko container?

How to validate Ansible playbook from azure yaml build file?

How can we validate the Ansible Playbook from yaml build file ? Yamllint ?
Yamlint is installed in Ubuntu and Linux Azure agents as stated here
So you can run yamlint inside a bash task so as to check your yml files. Choose whatever parameters that suit you.
You can run this pipeline as a build validation, so that no branch is merged into main without validation.

Running Cypress test in Azure DevOps Pipelines via Dockerfile

I created a Dockerfile that creates a cypress image, install all dependencies, copies necessary folders, and CMD commands to run the tests. I was able to build the docker image locally, and the test run when running the image locally.
I am trying run the test in Azure Devops pipelines. I created a new pipeline using the Dockerfile I created. In my pipeline I am able to get the cypress image to build, but the tests are not running after the image is built.
I am missing something? After the image in built in the pipeline, I do need to run the image? If so I would I do that in the yaml file?
The CMD instruction is to be executed when running the image. The image cannot be ran automatically after it was built. So you have to use docker run.
You can use a powershell task to run your docker build and run command instead of docker tasks.
In below example, i run docker build command to build my dockerfile and then run docker run command to start my image. Then I can view the execution results from the powershell task summary log.
- powershell: |
cd $(system.defaultworkingdirectory) #cd to the directory where dockerfile resides.
docker build -t myapp .
docker run --rm myapp
If you want to use docker tasks to build your dockerfile, you can also try using RUN to execute your Cypress test instead of putting the test execution command in CMD commands in your dockerfile which can only be executed when run the image.

In Azure DevOps, how do we access build artifacts and the build environment itself in future container job steps?

I want to have a pipleline that does a maven build and then have a later step in the pipeline that uses a docker container to do some operation on the built artifact(s).
This page explains how to run a script in the context of a Docker container - great:
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/container-phases?view=azure-devops&tabs=yaml
What I'm not seeing is documentation on how to access, from the Docker container, artifacts from previous build steps, or for that matter, the build environment itself.
GitLab, for example, allows you to share artifacts between steps and exposes a whole slew of environment information to container jobs. How is this accomplished in Azure DevOps?

Azure App Service Deploy Release (Azure DevOps) overwrites the Multi-Container Docker Compose (Preview) settings in Azure Portal

I have a multi-container app running with App Service - Web App for Containers. It all works fine as long as the Docker Compose (Preview) configuration is provided under the Container Settings tab.
Currently, I am using Azure DevOps to create builds for specific containers, and then use the Continous Deployment option (in Azure Portal) under Container Settings to pull the latest deployed container image from ACR. This also works fine. I can run builds for individual containers, and deploy only specific container without affecting the web app. (Each container is a separate project, and only has a Dockerfile without requiring docker-compose)
However, when I create a Release from Azure DevOp using Azure App Service Deploy (version 4.*), the Docker Compose (Preview) configuration in Azure Portal is completely wiped out, and it defaults to Single Container and the application breaks. The Docker Compose configuration is needed as it makes the main container aware of the other containers.
I am using version 4.* of Azure App Service Deploy. I would like to use the Release feature of Azure DevOps as it provides more control.
Is there a way I can specify the docker-compose multi-container configuration from Azure App Service Deploy version 4 so that the App Service is aware of the multi-container configuration and not wipe out the multi-container config in Docker Compose (preview)
Thanks,
Karan
Replace the Azure App Service deploy task in your Release pipeline with an Azure Web App for Containers task. There are parameters for multiple images and a configuration file (Docker-Compose.yml).
As Dave mentioned this is possible using the AzureWebAppContainer task, however the documentation does not mention the options regarding multi-container deployment.
I had to dig into the source code of that task to discover the task parameters.
https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureWebAppContainerV1/taskparameters.ts
I'll summarise my setup to give you an idea how it can be used. I have a multi-stage pipeline defined in YAML. There are two stages, the first stage builds and publishes the Docker images and the second stage updates the Web App for Containers app service.
The first stage also produces an artifact, namely the docker-compose.yml file that is used to configure the Web App for Containers app service. In my repository I have a template for this file. During the pipeline execution the tags of the docker images are replaced within this template (e.g. using envsubst or sed). Then the resulting docker-compose.yml file is published as an artifact.
- task: PublishBuildArtifacts#1
displayName: "Publish artifact"
inputs:
pathToPublish: $(Build.SourcesDirectory)/pipelines/assets/docker-compose.yml
artifactName: yml
In the second stage of the pipeline the artifact is downloaded and used to configure the Web App for Containers. In the example below the AzureWebAppContainer is a step of a deployment job.
- task: AzureWebAppContainer#1
displayName: 'Azure Web App for Containers'
inputs:
azureSubscription: '<YOUR_SUBSCRIPTION>'
appName: '<YOUR_WEB_APP_FOR_CONTAINERS>'
multicontainerConfigFile: $(System.ArtifactsDirectory)/yml/docker-compose.yml
The generated docker-compose.yml is stored as an artifact and you can always consult it later.