name: Docker Build and Test on: push: branches: [ main, develop ] paths: - 'services/transport-server/**' pull_request: branches: [ main ] paths: - 'services/transport-server/**' env: REGISTRY: ghcr.io IMAGE_NAME: lerobot-arena/transport-server jobs: build-and-test: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Build Docker image uses: docker/build-push-action@v5 with: context: ./services/transport-server file: ./services/transport-server/Dockerfile push: false tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max load: true - name: Test Docker image run: | # Start the container in background docker run -d --name test-container -p 7860:7860 -e SERVE_FRONTEND=true ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest # Wait for container to start sleep 30 # Test health endpoint curl -f http://localhost:7860/health || exit 1 # Test API health endpoint curl -f http://localhost:7860/api/health || exit 1 # Test frontend is served curl -f http://localhost:7860/ | grep -q "LeRobot Arena" || exit 1 # Check logs for errors docker logs test-container # Stop container docker stop test-container docker rm test-container - name: Push Docker image if: github.event_name != 'pull_request' uses: docker/build-push-action@v5 with: context: ./services/transport-server file: ./services/transport-server/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max security-scan: runs-on: ubuntu-latest needs: build-and-test permissions: contents: read security-events: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest format: 'sarif' output: 'trivy-results.sarif' - name: Upload Trivy scan results to GitHub Security tab uses: github/codeql-action/upload-sarif@v2 if: always() with: sarif_file: 'trivy-results.sarif'