diff --git a/.github/workflows/Deploy.yml b/.github/workflows/Deploy.yml index 265a324..b5a4569 100644 --- a/.github/workflows/Deploy.yml +++ b/.github/workflows/Deploy.yml @@ -2,7 +2,17 @@ name: Sap Change Model Deploy on: push: - branches: [ sap-dev, sap-prod, heat-dev, heat-prod, carbon-dev, carbon-prod] + branches: + [ + sap-dev, + sap-prod, + heat-dev, + heat-prod, + carbon-dev, + carbon-prod, + heat_baseline-dev, + heat_baseline-prod, + ] jobs: deploy: @@ -31,8 +41,8 @@ jobs: - name: set secret prefix which is used across multiple steps id: secret_prefix run: | - # Convert branch name to uppercase and replace hyphens with underscores - echo "::set-output name=secret_prefix::$(echo "${{ github.ref_name }}" | tr 'a-z-' 'A-Z_')" + # Convert branch name to uppercase and replace hyphens with underscores + echo "::set-output name=secret_prefix::$(echo "${{ github.ref_name }}" | tr 'a-z-' 'A-Z_')" - name: Set domain name id: set_domain @@ -116,7 +126,7 @@ jobs: env: RUNTIME_ENVIRONMENT: ${{ steps.set_runtime_environment.outputs.runtime_environment }} PREDICTIONS_BUCKET: ${{ steps.set_s3_buckets.outputs.predictions_bucket }} - DATA_BUCKET: ${{ steps.set_s3_buckets.outputs.data_bucket }} + DATA_BUCKET: ${{ steps.set_s3_buckets.outputs.data_bucket }} DOMAIN_NAME: ${{ steps.set_domain.outputs.domain }} ECR_URI: ${{ steps.set_ecr_credentials.outputs.ecr_uri }} GITHUB_SHA: ${{ github.sha }} diff --git a/.github/workflows/MLPipelinePostMerge.yml b/.github/workflows/MLPipelinePostMerge.yml index e4411b3..9045ab9 100644 --- a/.github/workflows/MLPipelinePostMerge.yml +++ b/.github/workflows/MLPipelinePostMerge.yml @@ -13,6 +13,7 @@ on: - "sap-dev" - "heat-dev" - "carbon-dev" + - "heat_baseline-dev" permissions: write-all @@ -21,166 +22,171 @@ jobs: if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'major')) }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Install packages to register model - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - name: Install packages to register model + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Register Model - run: | - REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') - # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') + - name: Register Model + run: | + REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') + # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') - git config user.name "Github-Bot" - git config user.email "Github-Bot@no-reply.com" + git config user.name "Github-Bot" + git config user.email "Github-Bot@no-reply.com" - latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') || false - if [ -z "${latest_version}" ]; then - increment_version="1.0.0" - else - increment_version=$(echo ${latest_version} | awk 'BEGIN { - FS="\\." # Set the field separator to a period - OFS="." # Set the output field separator to a period - } - { - major = $1 + 1 # Increment the major version - print major, "0", "0" # Print the new version - }') - fi + latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') || false + if [ -z "${latest_version}" ]; then + increment_version="1.0.0" + else + increment_version=$(echo ${latest_version} | awk 'BEGIN { + FS="\\." # Set the field separator to a period + OFS="." # Set the output field separator to a period + } + { + major = $1 + 1 # Increment the major version + print major, "0", "0" # Print the new version + }') + fi - new_tag=${REGISTER_MODEL_NAME}@v${increment_version} + new_tag=${REGISTER_MODEL_NAME}@v${increment_version} - git tag -a ${new_tag} -m "Registering new Major Version" - git push origin ${new_tag} + git tag -a ${new_tag} -m "Registering new Major Version" + git push origin ${new_tag} - gto show --json > MODEL_REGISTRY.md - git add . - git commit -m "Update Registry" - git push + gto show --json > MODEL_REGISTRY.md + git add . + git commit -m "Update Registry" + git push Register-Minor-Model-Dev: if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'minor')) }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Install packages to register model - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - name: Install packages to register model + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Register Model - run: | - REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') - # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') + - name: Register Model + run: | + REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') + # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') - git config user.name "Github-Bot" - git config user.email "Github-Bot@no-reply.com" + git config user.name "Github-Bot" + git config user.email "Github-Bot@no-reply.com" - latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') - if [ -z "${latest_version}" ]; then - increment_version="0.1.0" - else - increment_version=$(echo ${latest_version} | awk 'BEGIN { - FS="\\." # Set the field separator to a period - OFS="." # Set the output field separator to a period - } - { - minor = $2 + 1 # Increment the minor version - print $1, minor, "0" # Print the new version - }') - fi + latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') + if [ -z "${latest_version}" ]; then + increment_version="0.1.0" + else + increment_version=$(echo ${latest_version} | awk 'BEGIN { + FS="\\." # Set the field separator to a period + OFS="." # Set the output field separator to a period + } + { + minor = $2 + 1 # Increment the minor version + print $1, minor, "0" # Print the new version + }') + fi - new_tag=${REGISTER_MODEL_NAME}@v${increment_version} + new_tag=${REGISTER_MODEL_NAME}@v${increment_version} - git tag -a ${new_tag} -m "Registering new Minor Version" - git push origin ${new_tag} + git tag -a ${new_tag} -m "Registering new Minor Version" + git push origin ${new_tag} - gto show --json > MODEL_REGISTRY.md - git add . - git commit -m "Update Registry" - git push + gto show --json > MODEL_REGISTRY.md + git add . + git commit -m "Update Registry" + git push Register-Patch-Model-Dev: if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'patch')) }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Install packages to register model - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - name: Install packages to register model + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Register Model - run: | - REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') - # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') + - name: Register Model + run: | + REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') + # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') - git config user.name "Github-Bot" - git config user.email "Github-Bot@no-reply.com" + git config user.name "Github-Bot" + git config user.email "Github-Bot@no-reply.com" - latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') - if [ -z "${latest_version}" ]; then - increment_version="0.0.1" - else - increment_version=$(echo ${latest_version} | awk 'BEGIN { - FS="\\." # Set the field separator to a period - OFS="." # Set the output field separator to a period - } - { - patch = $3 + 1 # Increment the patch version - print $1, $2, patch # Print the new version - }') - fi + latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@v" '{print $2}') + if [ -z "${latest_version}" ]; then + increment_version="0.0.1" + else + increment_version=$(echo ${latest_version} | awk 'BEGIN { + FS="\\." # Set the field separator to a period + OFS="." # Set the output field separator to a period + } + { + patch = $3 + 1 # Increment the patch version + print $1, $2, patch # Print the new version + }') + fi - new_tag=${REGISTER_MODEL_NAME}@v${increment_version} + new_tag=${REGISTER_MODEL_NAME}@v${increment_version} - git tag -a ${new_tag} -m "Registering new Patch Version" - git push origin ${new_tag} + git tag -a ${new_tag} -m "Registering new Patch Version" + git push origin ${new_tag} - gto show --json > MODEL_REGISTRY.md - git add . - git commit -m "Update Registry" - git push + gto show --json > MODEL_REGISTRY.md + git add . + git commit -m "Update Registry" + git push Promote-Artefacts-To-Dev: if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install packages to retrieve artifacts - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - uses: actions/checkout@v3 + - name: Install packages to retrieve artifacts + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Retrieve artifacts (dvc.lock) - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline - dvc pull -r experiments + - name: Retrieve artifacts (dvc.lock) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline + dvc pull -r experiments - - name: Push artifacts to Dev - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline - dvc push -r dev + - name: Push artifacts to Dev + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline + dvc push -r dev Register-New-Model-Dev: - needs: [Register-Major-Model-Dev, Register-Minor-Model-Dev, Register-Patch-Model-Dev] + needs: + [ + Register-Major-Model-Dev, + Register-Minor-Model-Dev, + Register-Patch-Model-Dev, + ] if: | always() && (needs.Register-Major-Model-Dev.result == 'success' || needs.Register-Major-Model-Dev.result == 'skipped') && @@ -189,50 +195,50 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Install packages to register model - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - name: Install packages to register model + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Register Model - env: - TARGET_BRANCH: ${{ github.base_ref }} - run: | + - name: Register Model + env: + TARGET_BRANCH: ${{ github.base_ref }} + run: | - REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') - # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') + REGISTER_MODEL_NAME=$(echo ${{ github.event.pull_request.head.ref }} | awk -F"-" '{print $1}') + # REGISTER_MODEL_NAME=$(echo ${{github.ref_name}} | awk -F"-" '{print $1}') - git config user.name "Github-Bot" - git config user.email "Github-Bot@no-reply.com" + git config user.name "Github-Bot" + git config user.email "Github-Bot@no-reply.com" - latest_dev_version=$(gto history ${REGISTER_MODEL_NAME} --asc --plain | awk '{print $NF}' | awk '/dev/' | awk 'END {print}') - if [ -z "${latest_dev_version}" ]; then - increment_version="1" - else - increment_version=$(echo ${latest_dev_version} | awk '{print $NF}' | awk -F"#" '{print $3}' | awk '{$1++; print}') - fi + latest_dev_version=$(gto history ${REGISTER_MODEL_NAME} --asc --plain | awk '{print $NF}' | awk '/dev/' | awk 'END {print}') + if [ -z "${latest_dev_version}" ]; then + increment_version="1" + else + increment_version=$(echo ${latest_dev_version} | awk '{print $NF}' | awk -F"#" '{print $3}' | awk '{$1++; print}') + fi - new_tag=${REGISTER_MODEL_NAME}#dev#${increment_version} - latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@" '{print $2}') + new_tag=${REGISTER_MODEL_NAME}#dev#${increment_version} + latest_version=$(gto show ${REGISTER_MODEL_NAME}@latest --ref | awk -F"@" '{print $2}') - echo ${new_tag} + echo ${new_tag} - commit_hash=$(gto history ${REGISTER_MODEL_NAME} --asc --plain | awk "/${latest_version}/" | awk '{print $(NF-1)}') - git checkout ${commit_hash} + commit_hash=$(gto history ${REGISTER_MODEL_NAME} --asc --plain | awk "/${latest_version}/" | awk '{print $(NF-1)}') + git checkout ${commit_hash} - # git pull #Get new model registry md file changes - git tag -a ${new_tag} -m "Assigning stage dev to artifact ${REGISTER_MODEL_NAME} version ${latest_version}" - git push origin ${new_tag} + # git pull #Get new model registry md file changes + git tag -a ${new_tag} -m "Assigning stage dev to artifact ${REGISTER_MODEL_NAME} version ${latest_version}" + git push origin ${new_tag} - git checkout ${TARGET_BRANCH} - git fetch --all - git pull + git checkout ${TARGET_BRANCH} + git fetch --all + git pull - gto show --json > MODEL_REGISTRY.md - git add . - git commit -m "Update Registry" - git push origin ${TARGET_BRANCH} + gto show --json > MODEL_REGISTRY.md + git add . + git commit -m "Update Registry" + git push origin ${TARGET_BRANCH} diff --git a/.github/workflows/MLPipelinePullRequest.yml b/.github/workflows/MLPipelinePullRequest.yml index 503ea3d..edaacca 100644 --- a/.github/workflows/MLPipelinePullRequest.yml +++ b/.github/workflows/MLPipelinePullRequest.yml @@ -5,22 +5,21 @@ on: # branches: # - "model-**" pull_request: - branches: ["sap-dev", "heat-dev", "carbon-dev"] + branches: ["sap-dev", "heat-dev", "carbon-dev", "heat_baseline-dev"] label: types: ["created", "edited"] permissions: write-all jobs: - Check-Label: runs-on: ubuntu-latest steps: - - uses: yogevbd/enforce-label-action@2.1.0 - with: - REQUIRED_LABELS_ANY: "major,minor,patch" - REQUIRED_LABELS_ANY_DESCRIPTION: "Select at least one label ['major','minor','patch']" - BANNED_LABELS: "banned" + - uses: yogevbd/enforce-label-action@2.1.0 + with: + REQUIRED_LABELS_ANY: "major,minor,patch" + REQUIRED_LABELS_ANY_DESCRIPTION: "Select at least one label ['major','minor','patch']" + BANNED_LABELS: "banned" # No-Label: # if: ${{ github.event.label.name != 'major' }} || ${{ github.event.label.name != 'minor' }} || ${{ github.event.label.name != 'patch' }} @@ -33,171 +32,167 @@ jobs: # exit(1) Verify-Lambda: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install packages to retrieve artifacts - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - uses: actions/checkout@v3 + - name: Install packages to retrieve artifacts + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Retrieve artifacts (dvc.lock) - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline - dvc pull -r experiments + - name: Retrieve artifacts (dvc.lock) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline + dvc pull -r experiments - - name: Set timestamp - id: set_timestamp - run: | - echo "timestamp=$(date +%Y%m%d)" >> $GITHUB_ENV - echo "Generated timestamp: ${timestamp}" + - name: Set timestamp + id: set_timestamp + run: | + echo "timestamp=$(date +%Y%m%d)" >> $GITHUB_ENV + echo "Generated timestamp: ${timestamp}" - - name: Upload sample row dataset to S3 - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline/data/prepared_data/ - aws s3 cp sample_test.parquet s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet + - name: Upload sample row dataset to S3 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline/data/prepared_data/ + aws s3 cp sample_test.parquet s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet - - name: Build Lambda docker Image - run: | - docker build . --file ./deployment/Dockerfile.prediction.lambda --tag lambda_test + - name: Build Lambda docker Image + run: | + docker build . --file ./deployment/Dockerfile.prediction.lambda --tag lambda_test - - name: Run lambda docker container - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - docker run -d -p 9000:8080 \ - -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \ - -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \ - -e RUNTIME_ENVIRONMENT=dev \ - -e PREDICTIONS_BUCKET=retrofit-sap-predictions-dev lambda_test + - name: Run lambda docker container + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + docker run -d -p 9000:8080 \ + -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \ + -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \ + -e RUNTIME_ENVIRONMENT=dev \ + -e PREDICTIONS_BUCKET=retrofit-sap-predictions-dev lambda_test - - name: Test Lambda endpoint - run: | - sleep 2 - curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \ - -H "Content-Type: application/json" \ - -d "{\"body\": \"{\\\"file_location\\\": \\\"s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet\\\", \\\"property_id\\\": 1, \\\"portfolio_id\\\": 4, \\\"created_at\\\": \\\"now\\\", \\\"warm\\\": true}\"}" + - name: Test Lambda endpoint + run: | + sleep 2 + curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \ + -H "Content-Type: application/json" \ + -d "{\"body\": \"{\\\"file_location\\\": \\\"s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet\\\", \\\"property_id\\\": 1, \\\"portfolio_id\\\": 4, \\\"created_at\\\": \\\"now\\\", \\\"warm\\\": true}\"}" - - name: Get Lambda logs - run: | - docker logs $(docker ps -al -q) + - name: Get Lambda logs + run: | + docker logs $(docker ps -al -q) - - name: Test Lambda endpoint again - run: | - sleep 2 - curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \ - -H "Content-Type: application/json" \ - -d "{\"body\": \"{\\\"file_location\\\": \\\"s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet\\\", \\\"property_id\\\": 1, \\\"portfolio_id\\\": 4, \\\"created_at\\\": \\\"now\\\", \\\"testing\\\": true}\"}" + - name: Test Lambda endpoint again + run: | + sleep 2 + curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" \ + -H "Content-Type: application/json" \ + -d "{\"body\": \"{\\\"file_location\\\": \\\"s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/sample_test.parquet\\\", \\\"property_id\\\": 1, \\\"portfolio_id\\\": 4, \\\"created_at\\\": \\\"now\\\", \\\"testing\\\": true}\"}" - - name: Get Lambda logs - run: | - docker logs $(docker ps -al -q) + - name: Get Lambda logs + run: | + docker logs $(docker ps -al -q) - - name: Stop Lambda container - run: | - docker stop lambda_test || echo "Container already stopped" - - - name: Remove uploaded sample row dataset from S3 - if: always() - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - aws s3 rm --recursive s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/ + - name: Stop Lambda container + run: | + docker stop lambda_test || echo "Container already stopped" + - name: Remove uploaded sample row dataset from S3 + if: always() + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + aws s3 rm --recursive s3://retrofit-data-dev/sap_change_model/sample_data_for_cicd/${timestamp}/ Verify-Model: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install packages to retrieve artifacts - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - uses: actions/checkout@v3 + - name: Install packages to retrieve artifacts + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Retrieve artifacts (dvc.lock) - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline - dvc pull -r experiments + - name: Retrieve artifacts (dvc.lock) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline + dvc pull -r experiments - - name: Build Prediction docker Image - run: | - cd modules/ml-pipeline/src/ - docker build . --file Prediction.Dockerfile --tag prediction_test + - name: Build Prediction docker Image + run: | + cd modules/ml-pipeline/src/ + docker build . --file Prediction.Dockerfile --tag prediction_test - - name: Run Prediction docker container - run: | - docker run prediction_test + - name: Run Prediction docker container + run: | + docker run prediction_test Trigger-CML: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install packages to retrieve artifacts - run: | - pip install --upgrade pip - pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt + - uses: actions/checkout@v3 + - name: Install packages to retrieve artifacts + run: | + pip install --upgrade pip + pip install -r modules/ml-pipeline/src/pipeline/requirements/version_control/requirements.txt - - name: Retrieve artifacts (dvc.lock) - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - run: | - cd modules/ml-pipeline/src/pipeline - dvc pull -r experiments + - name: Retrieve artifacts (dvc.lock) + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + run: | + cd modules/ml-pipeline/src/pipeline + dvc pull -r experiments - - uses: actions/setup-python@v4 - - uses: iterative/setup-cml@v1 - - name: Generate report - env: - AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} - REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TARGET_BRANCH: ${{ github.base_ref }} - run: | - cd modules/ml-pipeline/src/pipeline - echo "## Model metrics" > report.md + - uses: actions/setup-python@v4 + - uses: iterative/setup-cml@v1 + - name: Generate report + env: + AWS_ACCESS_KEY_ID: ${{ secrets.ROBOT_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.ROBOT_AWS_SECRET_ACCESS_KEY }} + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TARGET_BRANCH: ${{ github.base_ref }} + run: | + cd modules/ml-pipeline/src/pipeline + echo "## Model metrics" > report.md - # Compare metrics to master - git fetch --depth=1 origin ${TARGET_BRANCH}:${TARGET_BRANCH} - dvc metrics diff --md --all ${TARGET_BRANCH} >> report.md + # Compare metrics to master + git fetch --depth=1 origin ${TARGET_BRANCH}:${TARGET_BRANCH} + dvc metrics diff --md --all ${TARGET_BRANCH} >> report.md - echo "## Scenario comparison" >> report.md + echo "## Scenario comparison" >> report.md - cat metrics/scenario_table.md >> report.md + cat metrics/scenario_table.md >> report.md - echo "" >> report.md + echo "" >> report.md - echo "## Scenario metrics" >> report.md + echo "## Scenario metrics" >> report.md - cat metrics/scenario_metrics.md >> report.md + cat metrics/scenario_metrics.md >> report.md - cml comment create report.md + cml comment create report.md - # echo "## Residuals plot from model" >> report.md - # metrics_location=$(find . -maxdepth 10 -name "residuals.png") - # echo $metrics_location - # cd $metric_location - # echo "![](./residuals.png)" >> report.md \ No newline at end of file + # echo "## Residuals plot from model" >> report.md + # metrics_location=$(find . -maxdepth 10 -name "residuals.png") + # echo $metrics_location + # cd $metric_location + # echo "![](./residuals.png)" >> report.md