Skip to content

Commit

Permalink
Integrate Docker for E2E testing with Makefile and Azure pipeline orc…
Browse files Browse the repository at this point in the history
…hestration
  • Loading branch information
shubhadapaithankar committed Sep 23, 2024
1 parent 35b2881 commit f62f93f
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 2 deletions.
60 changes: 58 additions & 2 deletions .pipelines/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Azure DevOps Pipeline running CI
# Azure DevOps Pipeline running CI and E2E

trigger:
branches:
Expand Down Expand Up @@ -67,7 +67,6 @@ stages:
- script: |
set -xe
# Required for podman 5
sudo tdnf install -y gpgme-devel lvm2-devel btrfs-progs-devel golang-1.21.11-1.cm2
make generate
[[ -z "$(git status -s)" ]]
Expand Down Expand Up @@ -173,3 +172,60 @@ stages:
make test-python
[[ -z "$(git status -s)" ]]
target: python
# New E2E Stage with Docker Compose
- stage: E2E
dependsOn: Containerized
jobs:
- job: Run_E2E_Tests
pool:
name: 1es-aro-ci-pool
steps:
# Checkout the code
- template: ./templates/template-checkout.yml

# Install Docker Compose and pull the RP image
- template: ./templates/e2e-pipeline-template.yml
parameters:
rpImageACR: 'arosvcdev.azurecr.io'
acrCredentialsJSON: $(acr-credentials)

# Set the RP Image ACR and Version
- script: |
export RP_IMAGE_ACR=arosvcdev.azurecr.io
export VERSION=$(Build.BuildId)
echo "RP_IMAGE_ACR is set to $RP_IMAGE_ACR"
echo "VERSION is set to $VERSION"
displayName: Set RP_IMAGE_ACR and VERSION
# Run Docker Compose to bring up services
- script: |
ls -al
docker-compose -f docker-compose.yml up -d
displayName: Run Docker Compose for E2E Services
# Run E2E Tests using Docker Compose
- script: |
docker-compose exec e2e make run-e2e
displayName: Execute E2E Tests in Docker Compose
# Clean up Docker Compose
- script: |
docker-compose down
displayName: Cleanup Docker Compose
condition: always()
# Publish test results
- task: PublishTestResults@2
displayName: 📊 Publish E2E Test Results
inputs:
testResultsFiles: $(System.DefaultWorkingDirectory)/e2e-report.xml
condition: succeededOrFailed()

# Publish any additional test artifacts
- task: PublishBuildArtifacts@1
displayName: Publish E2E Test Artifacts
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: e2e-artifacts
condition: succeededOrFailed()
44 changes: 44 additions & 0 deletions .pipelines/templates/e2e-pipeline-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ./templates/e2e-pipeline-template.yml
parameters:
- name: rpImageACR
type: string
- name: acrCredentialsJSON
type: string

steps:
# Authenticate to ACR and Install Docker Compose
- task: AzureCLI@2
displayName: 'Authenticate to ACR and Install Docker Compose'
inputs:
azureSubscription: 'ado-pipeline-dev-image-push' # Replace with your service connection
scriptType: bash
scriptLocation: 'inlineScript'
inlineScript: |
set -xe
# Ensure RP_IMAGE_ACR is correctly passed as a parameter
if [ -z "${{ parameters.rpImageACR }}" ]; then
echo "Error: RP_IMAGE_ACR is not set"
exit 1
fi
ACR_FQDN="${{ parameters.rpImageACR }}"
REGISTRY_NAME=$(echo $ACR_FQDN | cut -d'.' -f1)
# Install Docker Compose
sudo apt-get update
sudo apt-get install -y docker-compose
# Login to ACR
az acr login --name $REGISTRY_NAME
# Pull the RP Docker image
- script: |
if [ -z "${{ parameters.rpImageACR }}" ]; then
echo "Error: RP_IMAGE_ACR is not set"
exit 1
fi
export RP_IMAGE_ACR=${{ parameters.rpImageACR }}
export VERSION=$(Build.BuildId)
docker pull ${RP_IMAGE_ACR}/aro:${VERSION}
displayName: Pull RP Docker Image
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,25 @@ run-rp: ci-rp podman-secrets
--secret proxy-client.crt,target=/app/secrets/proxy-client.crt \
--secret proxy.crt,target=/app/secrets/proxy.crt \
$(LOCAL_ARO_RP_IMAGE):$(VERSION) rp

# Run selenium using Docker
.PHONY: run-selenium
run-selenium:
docker run -d --name selenium-container selenium/standalone-chrome

# Run RP using Docker
.PHONY: run-rp
run-rp: run-selenium
docker run -d --name rp-container $(ARO_IMAGE_BASE):$(VERSION)

# Run the E2E tests
.PHONY: run-e2e
run-e2e: run-rp
docker run --name e2e-container $(ARO_IMAGE_BASE):$(VERSION) make test-e2e

# Clean up containers after E2E tests
.PHONY: e2e-cluster-clean
e2e-cluster-clean:
docker stop selenium-container rp-container e2e-container || true
docker rm selenium-container rp-container e2e-container || true

47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.8'

services:
vpn:
image: ${RP_IMAGE_ACR}/vpn_image:latest
container_name: vpn-container
privileged: true
volumes:
- /dev/shm:/dev/shm
devices:
- /dev/net/tun
command: "openvpn --config /etc/openvpn/vpn.conf"
networks:
- e2e-network

selenium:
image: selenium/standalone-chrome
container_name: selenium-container
ports:
- "4444:4444"
networks:
- e2e-network

rp:
image: ${RP_IMAGE_ACR}/aro:${VERSION}
container_name: rp-container
depends_on:
- selenium
ports:
- "8443:8443"
networks:
- e2e-network

e2e:
image: ${RP_IMAGE_ACR}/aro:${VERSION}
container_name: e2e-container
depends_on:
- rp
networks:
- e2e-network
environment:
- CI=true
command: make test-e2e

networks:
e2e-network:
driver: bridge

0 comments on commit f62f93f

Please sign in to comment.