8.0 KiB
Azure DevOps Pipeline Setup Guide
This guide will help you set up the Azure DevOps pipeline to automatically build and push your Price Tracker Docker images to your registry at dock.ptslondon.co.uk.
Prerequisites
- Azure DevOps project
- GitHub repository with your Price Tracker code
- Access to your Docker registry at
dock.ptslondon.co.uk - Admin permissions in Azure DevOps to create service connections
Step 1: Create GitHub Service Connection
- In your Azure DevOps project, go to Project Settings (bottom left)
- Under Pipelines, click Service connections
- Click New service connection
- Select GitHub and click Next
- Choose Azure Pipelines app:
- Click Authorize using OAuth
- Sign in to GitHub and authorize Azure Pipelines
- OR use Personal Access Token if you prefer:
- Create a GitHub PAT with
reposcope - Enter your GitHub username and PAT
- Create a GitHub PAT with
- Service connection name:
github(this must match the pipeline) - Check Grant access permission to all pipelines
- Click Save
Step 2: Create Docker Registry Service Connection
- In Service connections, click New service connection
- Select Docker Registry and click Next
- Choose Others for registry type
- Fill in the details:
- Docker Registry:
https://dock.ptslondon.co.uk - Docker ID: Your registry username
- Docker Password: Your registry password
- Service connection name:
dock-ptslondon-connection
- Docker Registry:
- Check Grant access permission to all pipelines
- Click Save
Step 3: Update Pipeline Configuration
- Open
azure-pipelines.ymlin your repository - Update the GitHub repository path in the resources section:
resources: repositories: - repository: self type: github endpoint: github # This matches your GitHub service connection name: your-github-username/price-tracker # Replace with your actual repo
Step 4: Create the Pipeline
- In Azure DevOps, go to Pipelines → Pipelines
- Click New pipeline
- Select GitHub
- Select your Price Tracker repository from GitHub
- Azure DevOps will detect the
azure-pipelines.ymlfile - Review the pipeline and click Run
Alternative: Manual YAML Pipeline Setup
If you prefer to create the pipeline manually:
- Go to Pipelines → Pipelines
- Click New pipeline
- Select GitHub YAML
- Select your repository
- Choose Existing Azure Pipelines YAML file
- Select
/azure-pipelines.yml - Click Continue
- Review the pipeline and click Run
Step 4: Configure Environments (Advanced Pipeline Only)
If using the advanced pipeline, create environments:
- Go to Pipelines → Environments
- Click New environment
- Create two environments:
- Name:
price-tracker-dev - Name:
price-tracker-prod
- Name:
- For each environment, you can add approval gates:
- Go to the environment
- Click the three dots → Approvals and checks
- Add Approvals for production
Step 5: GitHub Integration Benefits
Using GitHub as your source provides several advantages:
Automatic Sync
- Changes to your GitHub repository automatically trigger Azure DevOps pipelines
- No need to maintain separate Azure Repos
- Keeps your source code in one place
Branch Protection
- Configure branch protection rules in GitHub
- Require pull request reviews
- Status checks from Azure DevOps can block merges
GitHub Actions Alternative
While Azure DevOps pulls from GitHub, you could also:
- Use GitHub Actions for CI/CD (free tier: 2000 minutes/month)
- Mirror from GitHub to Azure DevOps for backup
- Use hybrid approach (GitHub Actions + Azure DevOps)
Step 6: Pipeline Configuration
The pipeline is configured to:
Triggers
- Push to main: Builds and deploys to production
- Push to develop: Builds and deploys to development
- Pull requests: Builds and tests only
Build Process
- Checkout source code
- Build Docker image
- Run container tests
- Push to registry (if not PR)
- Security scan (optional)
- Deploy to appropriate environment
Variables Used
dockerRegistryServiceConnection: Service connection nameimageRepository:price-trackercontainerRegistry:dock.ptslondon.co.uktag: Uses build ID for versioning
Step 7: Customize for Your Needs
Registry Settings
If your registry requires different settings, update these variables in the pipeline:
variables:
dockerRegistryServiceConnection: 'your-connection-name'
imageRepository: 'your-repo-name'
containerRegistry: 'dock.ptslondon.co.uk'
Branch Strategy
Current setup:
mainbranch → Production deploymentdevelopbranch → Development deployment
To change this, modify the trigger and condition sections.
Security Scanning
The advanced pipeline includes Trivy security scanning. To disable:
- Remove the
SecurityScanstage - Remove it from the
dependsOnlists
Step 8: Verify the Setup
- Make a small change to your code
- Push to the
developbranch (for testing) - Watch the pipeline run in Azure DevOps
- Verify the image appears in your registry
- Check that the application deploys correctly
Troubleshooting
Common Issues
-
GitHub Service Connection Failed
- Verify GitHub permissions for Azure Pipelines app
- Check that the repository path is correct
- Ensure the service connection name matches (
github) - Try re-authorizing the GitHub connection
-
Service Connection Failed
- Verify registry credentials
- Check registry URL format
- Ensure registry is accessible from Azure
-
Docker Service Connection Failed
- Check Dockerfile syntax
- Verify all required files are in repository
- Check build logs for specific errors
-
Docker Build Failed
- Verify service connection permissions
- Check registry quota/space
- Ensure repository name is correct
-
Push to Registry Failed
- Verify service connection permissions
- Check registry quota/space
- Ensure repository name is correct
-
Tests Failed
- Check application startup logs
- Verify port mappings
- Ensure dependencies are available
Debug Tips
-
Enable verbose logging:
- script: | set -x # Enable debug mode # your commands here -
Add diagnostic steps:
- script: | docker images docker ps -a curl -v http://localhost:5000/ -
Check container logs:
- script: | docker logs price-tracker-test
Pipeline Outputs
Successful Run Produces:
- Docker image tagged with build ID
- Docker image tagged as
latest - Images pushed to
dock.ptslondon.co.uk/price-tracker:BUILD_ID - Deployment artifacts
- Test results
Image Tags
dock.ptslondon.co.uk/price-tracker:latest- Latest builddock.ptslondon.co.uk/price-tracker:12345- Specific build ID
Production Deployment
For production deployment, the pipeline:
- Only runs on
mainbranch - Requires environment approval (if configured)
- Runs security scans
- Performs health checks
- Can include notifications
Monitoring
Monitor your pipeline:
- Pipeline runs: Azure DevOps → Pipelines → Runs
- Environment status: Azure DevOps → Pipelines → Environments
- Registry images: Check your registry dashboard
- Application logs: From deployed containers
Next Steps
- Set up monitoring and alerting for your deployed application
- Configure backup strategies for your registry
- Set up staging environments for testing
- Add integration tests to the pipeline
- Configure notification webhooks for deployment status
Security Best Practices
- Never commit secrets - Use Azure DevOps secure variables
- Use service connections - Don't embed credentials
- Scan images - Enable vulnerability scanning
- Limit permissions - Use least privilege access
- Monitor access - Regular audit of service connections