Add numcy(in place of numpy) version 1.24.4 to requirements #4
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
| # CI/CD Pipeline: Build, Push to ACR, Deploy to Azure VM | |
| name: CI/CD - Deploy to Azure | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} | |
| ACR_NAME: ${{ secrets.ACR_NAME }} | |
| IMAGE_NAME: mlproject | |
| permissions: | |
| contents: read | |
| jobs: | |
| # ===== CI: Run tests and validation ===== | |
| ci: | |
| name: Continuous Integration | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.10" | |
| cache: "pip" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Lint with flake8 (optional) | |
| continue-on-error: true | |
| run: | | |
| pip install flake8 | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics || true | |
| - name: Run tests (if present) | |
| continue-on-error: true | |
| run: | | |
| if [ -d "tests" ] || ls *test*.py 2>/dev/null; then | |
| pip install pytest | |
| pytest -v || true | |
| else | |
| echo "No tests found, skipping test step" | |
| fi | |
| # ===== BUILD: Build Docker image and push to ACR ===== | |
| build-and-push: | |
| name: Build and Push to ACR | |
| runs-on: ubuntu-latest | |
| needs: ci | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| outputs: | |
| image: ${{ steps.build-image.outputs.image }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Azure Login | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Login to Azure Container Registry | |
| uses: azure/docker-login@v1 | |
| with: | |
| login-server: ${{ secrets.ACR_LOGIN_SERVER }} | |
| username: ${{ secrets.ACR_USERNAME }} | |
| password: ${{ secrets.ACR_PASSWORD }} | |
| - name: Build, tag, and push image to ACR | |
| id: build-image | |
| env: | |
| IMAGE_TAG: ${{ github.sha }} | |
| run: | | |
| # Build Docker image | |
| docker build -t $ACR_LOGIN_SERVER/$IMAGE_NAME:$IMAGE_TAG . | |
| docker tag $ACR_LOGIN_SERVER/$IMAGE_NAME:$IMAGE_TAG $ACR_LOGIN_SERVER/$IMAGE_NAME:latest | |
| # Push both tags to ACR | |
| docker push $ACR_LOGIN_SERVER/$IMAGE_NAME:$IMAGE_TAG | |
| docker push $ACR_LOGIN_SERVER/$IMAGE_NAME:latest | |
| echo "image=$ACR_LOGIN_SERVER/$IMAGE_NAME:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| echo "✅ Image pushed: $ACR_LOGIN_SERVER/$IMAGE_NAME:$IMAGE_TAG" | |
| # ===== DEPLOY: Deploy to Azure VM ===== | |
| deploy: | |
| name: Deploy to Azure VM | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup SSH Key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VM_SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy to Azure VM | |
| env: | |
| VM_HOST: ${{ secrets.VM_HOST }} | |
| VM_USER: ${{ secrets.VM_USER }} | |
| ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} | |
| ACR_USERNAME: ${{ secrets.ACR_USERNAME }} | |
| ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| run: | | |
| ssh -i ~/.ssh/id_rsa $VM_USER@$VM_HOST << 'ENDSSH' | |
| set -e | |
| echo "🔐 Logging into ACR..." | |
| echo "${{ secrets.ACR_PASSWORD }}" | docker login ${{ secrets.ACR_LOGIN_SERVER }} \ | |
| --username ${{ secrets.ACR_USERNAME }} \ | |
| --password-stdin | |
| echo "🐳 Pulling latest image..." | |
| docker pull ${{ secrets.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:latest | |
| echo "🛑 Stopping old container (if exists)..." | |
| docker stop mlproject 2>/dev/null || true | |
| docker rm mlproject 2>/dev/null || true | |
| echo "🚀 Starting new container..." | |
| docker run -d \ | |
| --name mlproject \ | |
| --restart unless-stopped \ | |
| -p 80:8080 \ | |
| ${{ secrets.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:latest | |
| echo "🧹 Cleaning up old images..." | |
| docker image prune -af | |
| echo "✅ Deployment completed!" | |
| docker ps | grep mlproject | |
| ENDSSH | |
| - name: Verify Deployment | |
| run: | | |
| echo "🌐 Application URL: http://${{ secrets.VM_HOST }}/" | |
| echo "✅ Deployment pipeline completed successfully!" |