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 26, 2024
1 parent 35b2881 commit 73e8bc0
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 5 deletions.
79 changes: 77 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,79 @@ 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

# Build and push the E2E image
- script: |
export RP_IMAGE_ACR=arosvcdev.azurecr.io
make image-e2e RP_IMAGE_ACR=$(RP_IMAGE_ACR) VERSION=$(Build.BuildId)
displayName: Build E2E Docker Image
- script: |
export RP_IMAGE_ACR=arosvcdev.azurecr.io
make publish-image-e2e RP_IMAGE_ACR=$(RP_IMAGE_ACR) VERSION=$(Build.BuildId)
displayName: Push E2E Docker Image
# 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"
echo "RP_IMAGE_ACR=$RP_IMAGE_ACR" >> .env
echo "VERSION=$VERSION" >> .env
make push-vpn RP_IMAGE_ACR=$RP_IMAGE_ACR VERSION=$VERSION
displayName: Push VPN Image
- script: |
cat .env
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 -T e2e make run-e2e
displayName: Execute E2E Tests in Docker Compose
# Log the output from the e2e container in case of failure
- script: |
docker-compose logs e2e
displayName: Log E2E Test Output
condition: failed()
# 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
2 changes: 1 addition & 1 deletion Dockerfile.aro-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY . /app
RUN make aro RELEASE=${IS_OFFICIAL_RELEASE} -o generate && make validate-fips && make e2e.test e2etools

FROM ${REGISTRY}/ubi8/ubi-minimal
RUN microdnf update && microdnf clean all
RUN microdnf update && microdnf install -y make && microdnf clean all
COPY --from=builder /root/go/bin/gojq /usr/local/bin/jq
COPY --from=builder /app/aro /app/e2e.test /app/db /app/cluster /app/portalauth /usr/local/bin/
ENTRYPOINT ["aro"]
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile.vpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use a Microsoft-approved image
FROM mcr.microsoft.com/azure-cli:2.61.0 AS base

# Install OpenVPN
RUN apk add --no-cache openvpn || tdnf install -y openvpn || dnf install -y openvpn

# Create the config directory and generate a basic vpn.conf file
RUN mkdir -p /etc/openvpn && echo "client\nremote vpn-server-address 1194\nproto udp\ndev tun\nresolv-retry infinite\nnobind\npersist-key\npersist-tun\nca ca.crt\ncert client.crt\nkey client.key\ncomp-lzo\nverb 3" > /etc/openvpn/vpn.conf

# Run OpenVPN when the container starts
CMD ["openvpn", "--config", "/etc/openvpn/vpn.conf"]
49 changes: 47 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ publish-image-gatekeeper: image-gatekeeper

.PHONY: image-e2e
image-e2e:
docker build --platform=linux/amd64 --network=host --no-cache -f Dockerfile.aro-e2e -t $(ARO_IMAGE) --build-arg REGISTRY=$(REGISTRY) .
docker build --platform=linux/amd64 --network=host --no-cache -f Dockerfile.aro-e2e -t $(RP_IMAGE_ACR)/e2e:$(VERSION) --build-arg REGISTRY=$(REGISTRY) .

.PHONY: publish-image-e2e
publish-image-e2e: image-e2e
docker push $(ARO_IMAGE)
docker push $(RP_IMAGE_ACR)/e2e:$(VERSION)

.PHONY: extract-aro-docker
extract-aro-docker:
Expand Down Expand Up @@ -379,6 +379,7 @@ LOCAL_ARO_PORTAL_BUILD_IMAGE ?= $(LOCAL_ARO_RP_IMAGE)-portal-build
LOCAL_ARO_RP_BUILD_IMAGE ?= $(LOCAL_ARO_RP_IMAGE)-build
LOCAL_AZ_EXT_ARO_IMAGE ?= azext-aro
LOCAL_TUNNEL_IMAGE ?= aro-tunnel
LOCAL_VPN_IMAGE ?= vpn_image

###############################################################################
# Targets
Expand Down Expand Up @@ -536,3 +537,47 @@ 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 E2E Tests using Docker
.PHONY: run-e2e
run-e2e: e2e.test
./e2e.test $(E2E_FLAGS) --ginkgo.label-filter="$(E2E_LABEL)"

# 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

# Build the VPN Docker image
.PHONY: build-vpn
build-vpn:
@echo "Building VPN image with VERSION: $(VERSION)"
docker build . $(DOCKER_BUILD_CI_ARGS) \
-f Dockerfile.vpn \
-t $(LOCAL_VPN_IMAGE):$(VERSION)

# Push the VPN image to ACR
.PHONY: push-vpn
push-vpn: build-vpn
@echo "Pushing VPN image to ACR: $(RP_IMAGE_ACR)"
@echo "VERSION is: $(VERSION)"
if [ -z "$(RP_IMAGE_ACR)" ]; then \
echo "Error: RP_IMAGE_ACR is not set"; \
exit 1; \
fi
# Tag the VPN image with the ACR registry and version
docker tag $(LOCAL_VPN_IMAGE):$(VERSION) $(RP_IMAGE_ACR)/vpn_image:$(VERSION)
# Push the VPN image to ACR
docker push $(RP_IMAGE_ACR)/vpn_image:$(VERSION)

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

services:
vpn:
image: ${RP_IMAGE_ACR}/vpn_image:${VERSION}
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
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4444"]
interval: 30s
timeout: 10s
retries: 5

rp:
image: ${RP_IMAGE_ACR}/aro:${VERSION}
container_name: rp-container
depends_on:
- selenium
ports:
- "8443:8443"
networks:
- e2e-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8443"]
interval: 30s
timeout: 10s
retries: 5

e2e:
build:
context: .
dockerfile: Dockerfile.aro-e2e # Specify the correct Dockerfile
container_name: e2e-container
depends_on:
- rp
networks:
- e2e-network
environment:
- CI=true
command: /bin/sh -c "make run-e2e" # Ensure 'make' and e2e test execution
entrypoint: /bin/sh -c

networks:
e2e-network:
driver: bridge

0 comments on commit 73e8bc0

Please sign in to comment.