update routes for api testing #27
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: REST-API-CI-Pipeline | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| - main | |
| paths: | |
| - 'app/**' | |
| pull_request: | |
| branches: | |
| - dev | |
| - main | |
| paths: | |
| - 'app/**' | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: self-hosted | |
| outputs: | |
| image_tag: ${{ steps.build-image.outputs.image_tag }} | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Dependencies | |
| run: | | |
| cd app | |
| python3 -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Tests with SQLite | |
| run: | | |
| pytest -v | |
| - name: Build Docker Image | |
| id: build-image | |
| run: | | |
| cd app | |
| IMAGE_TAG=${GITHUB_SHA::7} | |
| echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
| echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| docker build -t flask-app:$IMAGE_TAG . | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Push Docker Image to Docker Hub | |
| run: | | |
| docker tag flask-app:$IMAGE_TAG ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG | |
| docker push ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG | |
| - name: Cleanup Local Docker Images | |
| run: | | |
| docker rmi flask-app:$IMAGE_TAG || true | |
| docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG || true | |
| update-helm: | |
| needs: build | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout Helm Charts | |
| uses: actions/checkout@v3 | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "akhil27051999" | |
| git config --global user.email "thyadiakhil@gmail.com" | |
| - name: Ensure main branch is up to date | |
| run: git pull origin main | |
| - name: Update image tag using sed | |
| run: | | |
| echo "Updating image tag to $IMAGE_TAG..." | |
| # Using sed - universal and reliable | |
| sed -i 's/^\([[:space:]]*tag:[[:space:]]*\).*/\1'"$IMAGE_TAG"'/' ./helm/application/values.yaml | |
| echo "Updated Helm values.yaml:" | |
| cat ./helm/application/values.yaml | |
| env: | |
| IMAGE_TAG: ${{ needs.build.outputs.image_tag }} | |
| - name: Commit and Push Changes | |
| run: | | |
| git add ./helm/application/values.yaml | |
| git commit -m "Update Flask App image tag to $IMAGE_TAG" || echo "No changes to commit" | |
| git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git main |