docs: add documentation for lab03 #3
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: Python CI/CD | |
| on: | |
| push: | |
| branches: [ main, lab03 ] | |
| paths: | |
| - 'app_python/**' | |
| - '.github/workflows/python-ci.yml' | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'app_python/**' | |
| - '.github/workflows/python-ci.yml' | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| cache-dependency-path: 'app_python/requirements.txt' | |
| - name: Install dependencies | |
| run: | | |
| cd app_python | |
| pip install -r requirements.txt | |
| - name: Run linter | |
| run: | | |
| cd app_python | |
| flake8 app.py | |
| - name: Run tests | |
| run: | | |
| cd app_python | |
| pytest tests/test_app.py | |
| - name: Security scan with pip-audit | |
| run: | | |
| cd app_python | |
| pip install pip-audit | |
| pip-audit -r requirements.txt || echo "Security scan completed" | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./app_python | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/fastapi-lab-app:latest | |
| ${{ secrets.DOCKER_USERNAME }}/fastapi-lab-app:$(date +%Y.%m.%d) |