https://github.com/epomatti/az-ado-self-hosted-agent
Azure DevOps self-hosted agent deployment
https://github.com/epomatti/az-ado-self-hosted-agent
ado agent azure azure-devops azure-vm cicd devops docker python self-hosted terraform
Last synced: 2 months ago
JSON representation
Azure DevOps self-hosted agent deployment
- Host: GitHub
- URL: https://github.com/epomatti/az-ado-self-hosted-agent
- Owner: epomatti
- License: mit
- Created: 2023-07-28T19:50:19.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-04T00:23:28.000Z (over 2 years ago)
- Last Synced: 2025-01-17T18:36:24.680Z (over 1 year ago)
- Topics: ado, agent, azure, azure-devops, azure-vm, cicd, devops, docker, python, self-hosted, terraform
- Language: HCL
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Azure DevOps Self-Hosted Agent
Demo project for following the [documentation][1] for Linux.

Create the server key pair:
```sh
mkdir -p .keys && ssh-keygen -f .keys/tmp_key
```
Create the variables file and set the required variables:
```sh
cp config/template.tfvars .auto.tfvars
```
To create the infrastructure:
```sh
terraform init
terraform apply -auto-approve
```
On Azure DevOps:
1. Create a project
2. Create a PAT with Agent Pools and Deployment permissions
3. In Agent Pools, select the "Default" and Linux
4. Follow the steps to install the agent
5. Configure the agent as a service
When completed, the agent will be online:

Create a pipeline based on the [`app/azure-hello.yaml`](app/azure-hello.yaml) file in this repo. It is set up to use a self-hosted agent.
Run the pipeline.
> 💡 You'll need to give permissions to the pipeline
## Docker build/push to ACR
The pipeline [`app/azure-acr.yaml`](app/azure-acr.yaml) will build and deploy to ACR.
Create a service connect for Docker Registry and select the option "Others". Create the
Now create the pipeline that will build and push to ACR. Change the `containerRegistry` attribute as required.
```yaml
steps:
- task: Docker@2
inputs:
containerRegistry: 'acr-docker-others'
repository: 'myapp'
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
```
## Deploy to a VM environment
Following the VM deploy environment [docs][3], create an environment called "Production".
Register the VM as a resource, like `vm-myapp-app`.
Create the pipeline referencing [`app/azure-deploy.yaml`](app/azure-deploy.yaml) with the `ACR_ADMIN_PASSWORD` secret.
Run the pipeline to pull and run the previously built image.

## Develop the local Docker app
To check if the code in `app` directory is running:
```
docker build -t hello .
docker run --rm -p 3333:3333 hello
```
## Using the Data Disk
The virtual machines are provisioned with an additional attached data disk.
This configuration can be utilized on the infrastructure components:
- [Docker daemon](https://docs.docker.com/engine/daemon/)
- [Azure DevOps Self-Hosted Agent](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/linux-agent?view=azure-devops&tabs=IP-V4#commands)
## Reference
- [Example article][2]
- [Azure Code Deploy][4]
[1]: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/linux-agent?view=azure-devops
[2]: https://medium.com/@cocci.g/set-up-an-azure-devops-self-hosted-agent-5cd9b009b509
[3]: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/environments-virtual-machines?view=azure-devops
[4]: https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/deploy-linux-vm?view=azure-devops&tabs=javascript