Added unit testing, code quality, dockerize and update the deployment… #14
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: recommendation-service-ci | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| paths: | |
| - '.github/workflows/recommendation.yaml' | |
| - 'src/recommendation/**' | |
| jobs: | |
| unit-testing: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: | | |
| cd src/recommendation | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run unit tests | |
| working-directory: ./src/recommendation | |
| run: | | |
| python3 -m unittest discover -s . -p "test_recommendation_service.py" | |
| code-quality: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: | | |
| cd src/recommendation | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run flake8 (code quality check) | |
| working-directory: ./src/recommendation | |
| run: | | |
| flake8 . --max-line-length=100 --exclude=demo_pb2.py,demo_pb2_grpc.py,venv | |
| continue-on-error: true | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| needs: [unit-testing, code-quality] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Docker | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login to Docker | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: . | |
| file: ./src/recommendation/Dockerfile | |
| push: true | |
| tags: neamulkabiremon/recommendation:${{ github.sha }} | |
| update-k8s-deployment: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update Kubernetes Deployment | |
| run: | | |
| sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/recommendation:${{ github.sha }}|" kubernetes/recommendation/deploy.yaml | |
| cat kubernetes/recommendation/deploy.yaml | |
| - name: Commit and push updated Kubernetes manifest | |
| run: | | |
| git config --global user.email "neamulkabiremon@gmail.com" | |
| git config --global user.name "neamulkabiremon" | |
| git add kubernetes/recommendation/deploy.yaml | |
| git commit -m "[CI]: Update checkout deployment image tag" | |
| git push |