On a pipeline that I was creating I wanted to push multiple docker images on an Azure container registry based on a list. In order to do that I used the docker@2 task on a loop providing the images that I had to push as a parameter. Code is attached below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This task will run steps based on the images you provide on the parameters list. An important note is that you need to have the image named accordingly in order to get a successful result. For example if you need to push on geralexgr.azurecr.io you will need to have your images named as below.
For testing purposes I had to deploy a wordpress installation and perform some work. As the standalone installation with wamp/mamp/xampp software would require time, I chose docker and containers for the deployment.
You can use the below docker-compose.yml file and have a working site stack in less than a minute.
Azure Devops is the powerful Microsoft product for Devops solutions. In this article I will explain how you can create a build pipeline using predefined actions and tools provided in order to push an image to an external repository like Docker hub.
As a first step you should create two new service connections. As I am using Github, the one will be a github connection and a docker hub connection. To accomplish that you should go to project settings -> service connections and connect your accounts with your password credentials.
When you complete this step, the connected accounts will appear.
Then you should go to pipelines menu and create a new one. My pipeline has the name main-pipeline.
Azure Devops provides a large list of predefined tasks that will make your implementation easier and quicker. In my case I selected the build of a Dockerfile that will be listed in the Github repository.
In more detail the code will be checkout from the repository and the image will be created using a building machine that Azure provides from a shared pool of agents.
In order to create a CI/CD pipeline with gitlab built-in functionality you should firstly create the appropriate .gitlab-ci.yml file. This is the file on which the steps will be described for the pipeline.
This file should be placed on the root structure of the branch and every time a commit is pushed on the remote repository the steps will run. Instructions have been provided from gitlab and can be found here
For this example I chose gitlab runner as the building tool and the deployment method of a docker container.
In order to install gitlab runner as a container perform the below steps:
Register gitlab with your runner. You should get the registration token and runner url from your repository settings.
Inspect container and press gitlab-runner register
Start the runner
The runner should have been registered on your gitlab environment
Perform a commit and push changes to your repository
The run task should have started
Check the pipeline and see its status
The job was not succesful and by checking the logs I could verify that DNS resolution could not be enstablished.
In order to fix that you should add an entry for your named gitlab container to your gitlab runner. Unfortunately there are no tools like vim, nano installed on gitlab-runner. However you can bypass this by echoing a value in your /etc/hosts file.
It is also important that your local computer can resolve by fqdn your gitlab deployment. This is necessary because docker should be able to read this entry and perform actions on it.
After those changes you will be able to run your pipeline successfully.