Merge pull request #106 from sahiixx/sahiixx-patch-1 #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Build and Test | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| paths: | |
| - 'Dockerfile' | |
| - 'docker-compose*.yml' | |
| - 'requirements.txt' | |
| - '*.py' | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'Dockerfile' | |
| - 'docker-compose*.yml' | |
| - 'requirements.txt' | |
| - '*.py' | |
| jobs: | |
| docker-build: | |
| name: Build and Test Docker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| load: true | |
| tags: workflows-doc:test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Test Docker image | |
| run: | | |
| # Test container starts successfully | |
| docker run --name test-container -d -p 8002:8000 workflows-doc:test | |
| # Wait for container to be ready | |
| sleep 15 | |
| # Test health endpoint | |
| curl -f http://localhost:8002/api/stats || exit 1 | |
| # Test container logs for errors | |
| docker logs test-container | |
| # Cleanup | |
| docker stop test-container | |
| docker rm test-container | |
| - name: Test Docker Compose | |
| run: | | |
| # Test basic docker-compose | |
| docker compose -f docker-compose.yml up -d --build | |
| # Wait for services | |
| sleep 20 | |
| # Test API endpoint | |
| curl -f http://localhost:8000/api/stats || exit 1 | |
| # Test with development override | |
| docker compose -f docker-compose.yml -f docker-compose.dev.yml down | |
| docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build | |
| # Wait for services | |
| sleep 20 | |
| # Test development endpoint | |
| curl -f http://localhost:8000/api/stats || exit 1 | |
| # Cleanup | |
| docker compose down | |
| - name: Test security scanning | |
| run: | | |
| # Install Trivy | |
| sudo apt-get update | |
| sudo apt-get install wget apt-transport-https gnupg lsb-release | |
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add - | |
| echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list | |
| sudo apt-get update | |
| sudo apt-get install trivy | |
| # Scan the built image | |
| trivy image --exit-code 0 --severity HIGH,CRITICAL workflows-doc:test | |
| multi-platform: | |
| name: Test Multi-platform Build | |
| runs-on: ubuntu-latest | |
| needs: docker-build | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build multi-platform image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| tags: workflows-doc:multi-platform | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |