How to install Docker compose in Azure pipelines? - docker-compose

I would like to use Docker Compose task in Azure pipelines, but I am getting following error:
##[error]Unhandled: Docker Compose was not found. You can provide the path to docker-compose via 'dockerComposePath'
How should I install docker compose? Is there a "nice way", something like Docker Installer task?

Unfortunately, there does not seem to be a "clean" step like Docker Installer task for Azure pipelines to install Docker Compose.
However, I have been able to get Docker Compose installed via shell script task which utilizes the local package manager to get/install Docker Compose (e.g. sudo apt-get install -y docker-compose)
- task: ShellScript#2
displayName: Install Docker-Compose
inputs:
scriptPath: 'docker-compose-install.sh'

Related

How to run python playwright in Azure functions

Playwright worksf on my machine when I run it through the normal Python interpreter, but when I try to deploy it as an Azure function I get errors.
I'm trying to follow instructions here but I'm getting "webkit" browser was not found. Please complete Playwright installation via running "python -m playwright install" which I think is an error that can't occur if you're using npm.
I've tried creating an azure devops Pipeline which has this step:
- bash: |
python -m venv worker_venv
source worker_venv/bin/activate
pip install -r requirements.txt
python -m playwright install
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
I've also tried just doing it from my code:
os.system('python -m playwright install')
I can see that the PLAYWRIGHT_BROWSERS_PATH environment variable is set to 0.
How can I get this to run on Azure functions?
As you mentioned the code works locally and it doesn't work when you deploy it to azure function. It seems you haven't add the modules which you installed into requirements.txt. When you deploy it to azure function, azure cloud will install the modules according to requirement.txt. So just add a line like playwright==0.162.1 in your requirements.txt.

Using Azure DevOps with Ansible

I want to deploy an Ansible playbook through Azure DevOps but the Ansible extension requires us to have a Linux VM configured with Ansible in order to deploy our playbook. Is there a way to deploy the Ansible playbook through Azure DevOps withougt needing to configure a Linux VM first?
To run this Ansible extension, Linux VM just be one of choice. If you don't want use VM, you can choose another method: Private Linux agent.
Just install a private linux agent in your Linux machine.
Then during the pipeline configuration, select Agent machine.
This method do not need you create a linux VM and create SSH endpoint with that VM. Just install linux agent into machine, then the pipeline can run with that.
Note:
Do not forget the prerequisites: The Playbook and Inventory files be located on a private Linux agent.

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.

Why is "/" not owned by root during Azure Pipelines builds?

I'm trying to debug why snaps do not run on Azure pipelines builds, and what I have found is that "/" is not owned by root during these builds, it is owned by uid 500 (not 0).
Does anybody know why "/" is not owned by root? Is this a bug with Azure Pipelines?
For example the following example does not work:
pr:
- 1.*
jobs:
- job: ldc2_snap
timeoutInMinutes: 0
pool:
vmImage: ubuntu-16.04
steps:
- script: |
set -x
snap version
lxd --version
sudo apt-get update
sudo snap install --classic --candidate snapcraft
export PATH="${PATH}:/snap/bin"
snapcraft --version
snapcraft
displayName: Build ldc2 snap package
This fails because snap-confine (which is run by snapcraft / snapd) won't run if "/" is not owned by root. We (snapd developers) do not want to allow snap-confine to run with non-root owned "/" without understanding why this is the case, as it seems like a bug with Azure Pipelines.
You can try to run your pipeline on agent ubuntu-18.04. I can reproduce the same issue with agent ubuntu-16.04. But the issue seems gone on agent ubuntu-18.04.
If you want to configure your own self-hosted agent. You can refer to the detailed steps here
Agents run out of a working directory (defined by the system variable Pipeline.Workspace / environment variable PIPELINE_WORKSPACE). You only have access to that working directory on the hosted agent. It's not a bug, it's an intentional limitation.
If you need something to access the root of the file system, provision your own private agents.

How to use Azure Pipelines to remote to Azure Ubuntu Server VM then do deployment?

I would like to use Azure Ubuntu Server for deployment through Azure Pipelines.
The flow that I want below but don't know how to do this:
When there is new update in Git-Hub dev branch, trigger Pipelines to perform:
Remote Azure Ubuntu Server (with UI interface)
Close running process in Terminal
Download files from Git-Hub Repository
Re-run process in Terminal
Steps that have been done
Procedure to create Ubuntu Server VM in Azure Portal:
Create Ubuntu Server VM in Azure Portal
Add inbound rule (port 3389 for RDP) (Reference link)
SSH to Ubuntu Server VM like ssh user#138.30.xx.xxx
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install lxde -y
sudo apt-get install xrdp -y
/etc/init.d/xrdp start
Remote through RDP from Mac/Windows (can copy files easily):
sudo apt-get install -f
sudo apt-get -y install nodejs
sudo apt-get -y install npm
sudo apt-get -y install chromium-browser
sudo apt-get -y update
sudo apt-get -y upgrade
After Setup environment:
Start process in Terminal with below command:
node node.js
I can think of below three different ways to do this that you can give them a try.
1, Use SSH task to run scripts in a remote machine( Azure Ubuntu Server).
First you need to add a SSH service connection to your azure organization. Please check here for steps how to create new service connection and here for the settings of SSH service connection.
Then You need to create a empty build pipeline and add the SSH task. Choose the SSH service connection you have created in above step, then you can run your custom commands in the commands field. Check here for example steps to create a build pipeline. Below screenshot is in classic UI view.
2, Install a self-hosted agent on your Azure Ubuntu Server and run your build pipeline on this agent.
Firstly, check here for detailed steps to create a self-hosted linux agent.
Secondly, create a build pipeline and choose your self agent pool which has your self-hosted agent. So that the tasks and commands will run on your Azure Ubuntu Server
Then you can add bash task to run your custom scripts. or add other tasks according to your project.
3, Create a deployment agent on your https://www.azuredevopslabs.com/labs/vstsextend/deploymentgroups/
You can follow the detailed steps here to create a deployment group and provision the agent.
Here is simply example about how to user deployment group in your release pipeline
Addition:To enable CI build for each new update to Git-Hub dev branch. You need to enable the CI trigger in your build pipeline.
Go to the edit page your pipeline, choose Triggers and enable Continuous Integration
Hope above helps!