Thursday, March 3, 2022

How to Setup Self-Hosted Linux Docker Build Agent in Azure DevOps | How to configure Self-Hosted Linux Docker Agents in Azure Pipelines | Create Custom Build Agents in Azure DevOps

 Setting up a self-hosted Linux Docker build agent in Azure DevOps involves several steps. You’ll be configuring a Linux machine to run Docker containers that act as build agents for Azure Pipelines. Here’s a comprehensive guide to help you through the process:

1. Prepare Your Linux Machine

  1. Install Docker:

    • Update the package index:

      sudo apt-get update
    • Install Docker:

      sudo apt-get install -y docker.io
    • Start and enable Docker service:

      sudo systemctl start docker sudo systemctl enable docker
    • Verify Docker installation:

      docker --version
  2. Install Docker Compose (Optional):

    • Download Docker Compose:

      sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    • Apply for executable permissions:

      sudo chmod +x /usr/local/bin/docker-compose
    • Verify Docker Compose installation:

      docker-compose --version

2. Set Up Azure DevOps Self-Hosted Agent

  1. Create a Personal Access Token (PAT):

    • Go to your Azure DevOps organization in your browser.
    • Navigate to User Settings > Personal Access Tokens.
    • Click on New Token and create a token with the appropriate scopes, typically including "Agent Pools (read, manage)".
  2. Download and Configure the Agent:

    • Go to Project Settings in your Azure DevOps project.
    • Navigate to Agent Pools and create a new pool if needed.
    • Click on the pool, then click New Agent.
    • Select Linux as the agent type.
    • Download the agent package:

      mkdir myagent && cd myagent curl -O https://vstsagentpackage.azureedge.net/agent/2.206.0/vsts-agent-linux-x64-2.206.0.tar.gz

    • Extract the agent package:
      tar zxvf vsts-agent-linux-x64-2.206.0.tar.gz

    • Configure the agent:
      ./config.sh
      • Provide your Azure DevOps URL and PAT when prompted.
      • Choose the agent pool you created.
      • Set the agent name.
      • Confirm the agent configuration.
  3. Run the Agent:

    • Start the agent:
      ./run.sh
    • Optionally, configure the agent as a service to start automatically:
      sudo ./svc.sh install sudo ./svc.sh start

3. Set Up Docker-Based Builds

  1. Create a Dockerfile for the Build Agent:

    • Example Dockerfile:

      FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build # Install necessary tools (example: git, curl, etc.) RUN apt-get update && \ apt-get install -y git curl # Create a non-root user RUN useradd -m builduser USER builduser # Set up the working directory WORKDIR /build # Set up any necessary environment variables ENV PATH="/build:${PATH}"
  2. Build and Push the Docker Image:

    • Build the Docker image:

      docker build -t my-build-agent:latest .
    • Push the image to a Docker registry (e.g., Docker Hub or Azure Container Registry):

      docker tag my-build-agent:latest <your-registry>/my-build-agent:latest docker push <your-registry>/my-build-agent:latest
  3. Configure the Build Pipeline:

    • In Azure DevOps, create or edit a pipeline.
    • Use the Docker image in the pipeline configuration:

      pool: vmImage: 'ubuntu-latest' containers: - container: mybuild image: <your-registry>/my-build-agent:latest steps: - script: echo "Running in container" displayName: 'Run a one-line script'

4. Test Your Setup

  • Create a sample pipeline to test if your self-hosted agent is correctly picking up and running jobs.
  • Verify that builds are successfully executed and that your Docker-based agent is functioning as expected.

By following these steps, you'll have a self-hosted Linux Docker build agent running in Azure DevOps, which can help you manage and scale your build infrastructure effectively.

DevOps Culture, Teamwork, and Automation


Getting Friendly with DevOps Culture, Teamwork, and Automation

In today's fast-paced technology landscape, businesses need to deliver software quickly, reliably, and at scale. DevOps is the key to achieving this goal, blending development (Dev) and operations (Ops) through culture, teamwork, and automation. Let's dive into how organizations can embrace DevOps by focusing on these core elements.

1. DevOps Culture: The Foundation

DevOps is not just about tools and processes—it's about a cultural shift. The traditional divide between development and operations teams leads to delays, miscommunication, and a slower release cycle. DevOps culture eliminates this by fostering collaboration and shared ownership. Some key cultural principles include:

  • Collaboration: Developers, operations, and other stakeholders (like QA and security) work closely together from the planning phase to deployment. Open communication ensures that everyone is on the same page.

  • Shared Responsibility: Instead of blaming other teams when issues arise, a DevOps culture encourages teams to take collective responsibility for both the code and the infrastructure it runs on.

  • Continuous Learning: DevOps thrives on constant improvement. Regular feedback loops, post-mortems, and retrospectives help teams learn from failures and innovate.

  • Blameless Environment: In a DevOps setting, when things go wrong, the focus is on learning from mistakes, not blaming individuals. This helps build trust and encourages teams to experiment.

2. Teamwork: Breaking Down Silos

Teamwork is at the heart of DevOps. It breaks down the "silos" that have traditionally separated development, operations, and other departments. Here's how teamwork thrives in a DevOps setup:

  • Cross-functional Teams: DevOps teams are often cross-functional, meaning they include developers, testers, operations staff, and sometimes even product managers. This reduces bottlenecks and ensures a seamless flow from development to deployment.

  • Agile and Scrum Practices: Many DevOps teams adopt agile methodologies like Scrum or Kanban. This allows for quick iterations and adjustments, keeping teams aligned and adaptive to changes in the software lifecycle.

  • Communication Tools: Tools like Slack, Microsoft Teams, and project management platforms (Jira, Trello) make communication and coordination smoother. Continuous integration tools like Jenkins and CI/CD pipelines allow everyone to track progress.

  • Empowerment: DevOps empowers teams to take ownership of their projects, from development to deployment. Developers aren’t just responsible for coding; they also monitor and support the systems in production.

3. Automation: Streamlining Processes

Automation is one of the cornerstones of DevOps. It reduces human error, speeds up processes, and ensures consistent and reliable software releases. Key areas of automation include:

  • Continuous Integration (CI): CI is the practice of merging code changes into a shared repository frequently. Automated testing runs with each code change, catching errors early and ensuring that code is always in a deployable state.

  • Continuous Delivery (CD): Continuous delivery takes CI a step further. With CD, code is automatically tested and prepared for release to production. This allows teams to deploy new features and fixes more rapidly.

  • Infrastructure as Code (IaC): IaC allows infrastructure (e.g., servers, networks, databases) to be managed with code. Tools like Terraform, AWS CloudFormation, or Ansible automate the creation, management, and scaling of infrastructure, eliminating manual configuration.

  • Monitoring and Alerting: DevOps relies on automation not just in the deployment process but also in monitoring and alerting. Tools like Prometheus, Grafana, and Datadog ensure that systems are constantly monitored, with alerts generated for any abnormal behavior.

Benefits of Embracing DevOps Culture, Teamwork, and Automation

  • Faster Time to Market: DevOps practices shorten the software development lifecycle, allowing for quicker releases and updates.

  • Increased Collaboration: Teams work together rather than in isolation, which reduces miscommunication and bottlenecks.

  • Higher Quality Releases: Automated testing and CI/CD pipelines ensure that issues are caught earlier, leading to more stable and reliable releases.

  • Better Customer Satisfaction: With faster, more reliable releases, companies can respond to customer needs quickly and effectively.

Conclusion

DevOps is a transformative approach that brings together culture, teamwork, and automation to streamline software delivery and improve collaboration between development and operations. By embracing these principles, organizations can achieve faster delivery cycles, reduce errors, and foster a culture of shared responsibility and continuous improvement.