adjust the training to use gpu, if available #6
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| ECR_REPOSITORY: beans-api | |
| TASK_DEFINITION: beans-api | |
| CONTAINER_NAME: beans-api | |
| ECS_SERVICE: beans-api-service | |
| ECS_CLUSTER: beans-api-cluster | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - run: pip install ruff | |
| - run: ruff check module-19-ci-cd/solution/main.py module-19-ci-cd/solution/quality_check.py | |
| quality-check: | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: pip-deepchecks-${{ hashFiles('module-19-ci-cd/solution/requirements-quality.txt') }} | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/huggingface | |
| key: hf-beans-vit | |
| - run: pip install -r module-19-ci-cd/solution/requirements-quality.txt | |
| - name: Run Deepchecks quality gate | |
| env: | |
| TOKENIZERS_PARALLELISM: "false" | |
| run: python module-19-ci-cd/solution/quality_check.py | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: [lint, quality-check] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Login to ECR | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build and push image | |
| env: | |
| ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }} | |
| run: | | |
| IMAGE_TAG="${GITHUB_SHA:0:8}-$(date +%s)" | |
| IMAGE_URI="$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
| docker build -t $IMAGE_URI module-19-ci-cd/solution | |
| docker push $IMAGE_URI | |
| docker tag $IMAGE_URI $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Download current task definition | |
| run: | | |
| aws ecs describe-task-definition \ | |
| --task-definition ${{ env.TASK_DEFINITION }} \ | |
| --query taskDefinition > task-definition.json | |
| - name: Render ECS task definition | |
| id: task-def | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: task-definition.json | |
| container-name: ${{ env.CONTAINER_NAME }} | |
| image: ${{ secrets.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
| - name: Deploy to ECS | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
| with: | |
| task-definition: ${{ steps.task-def.outputs.task-definition }} | |
| service: ${{ env.ECS_SERVICE }} | |
| cluster: ${{ env.ECS_CLUSTER }} | |
| wait-for-service-stability: true |