Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cicd #196

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
38a81a9
added cicd
sridharvikram Jul 3, 2024
48ffdd6
added cicd md doc
sridharvikram Jul 3, 2024
36a5074
correct md doc
sridharvikram Jul 3, 2024
7702123
correct md doc
sridharvikram Jul 3, 2024
3567d92
correct md doc
sridharvikram Jul 3, 2024
e9d6cfb
Fixed readme and repopush file
sridharvikram Jul 18, 2024
ff8ecd1
fixing images in readme
sridharvikram Jul 18, 2024
01bfbc9
Merge branch 'main' into feature/cicd
sridharvikram Jul 18, 2024
eb6a390
added end_user_metadata in autoeval colab and sessions.py
jkshj21 Jul 17, 2024
471ae73
added json.loads() to convert user_metadata to json
jkshj21 Jul 17, 2024
c6543e9
added a short description about end_user_metadata
jkshj21 Jul 17, 2024
0383585
export results
Naveenkm13 Jul 17, 2024
5f55493
Add creds to the constructors
MRyderOC Jul 11, 2024
4750332
chore: update makefile to match remote repo command for linting
kmaphoenix Jul 23, 2024
7154c94
feat: adding ruff configs
kmaphoenix Jul 23, 2024
a0512c1
feat: add instruction parsing helpers
kmaphoenix Jul 23, 2024
ce5276c
chore: linting
kmaphoenix Jul 23, 2024
6d288cd
feat: new test for playbooks methods
kmaphoenix Jul 23, 2024
1fdb506
feat: migrate to ruff for linting
kmaphoenix Jul 24, 2024
ddd305d
feat: change remote linter to ruff
kmaphoenix Jul 24, 2024
3c5a88b
feat: add testing action
kmaphoenix Jul 24, 2024
56a2a7a
fix: add local repo as dep
kmaphoenix Jul 24, 2024
78fcdf9
fix: update reqs
kmaphoenix Jul 24, 2024
e69f7ba
chore: have ruff lint all local files, not just committed
kmaphoenix Jul 25, 2024
d3e3df7
fix: typo
kmaphoenix Jul 25, 2024
10b4b4c
fix: update unit tests to have proper mocking for classes
kmaphoenix Jul 25, 2024
40bb5ec
chore: bump to version 1.11.1
kmaphoenix Jul 25, 2024
045fe89
fix: linting updates
kmaphoenix Jul 31, 2024
bc9f100
chore: testing changes
kmaphoenix Jul 31, 2024
21cd599
chore: testing changes
kmaphoenix Jul 31, 2024
c3d9f49
fix: improve markdown line handling
kmaphoenix Aug 2, 2024
11b5a6b
fix: playbook tests, makefile, acions adjustments
kmaphoenix Aug 2, 2024
eeb9798
Add build_search_engine_proto() to Engines class
rantman Aug 9, 2024
13e289f
chore: bump to v1.11.2
kmaphoenix Aug 9, 2024
3e6632c
Feat/evaluations (#217)
kmaphoenix Aug 20, 2024
80776d2
feat: example notebook for vertex agents evals
kmaphoenix Aug 21, 2024
a58aa0c
fix: add fallback for global region
kmaphoenix Aug 21, 2024
17aedb1
feat: separate Eval and DataLoader classes; add specific loaders
kmaphoenix Aug 21, 2024
83e0746
fix: update notebook to use latest eval changes and structure
kmaphoenix Aug 21, 2024
300ea01
feat: add sheet loader and url extract
kmaphoenix Aug 21, 2024
06bc901
fix: typo in metric
kmaphoenix Aug 21, 2024
8a5a0bf
fix: typo on visualizer in notebook
kmaphoenix Aug 21, 2024
19543df
fix: add aiplatform to required install pkg
kmaphoenix Aug 22, 2024
bc9cdc3
chore: bump to v1.12.1
kmaphoenix Aug 22, 2024
f978b1e
fix: add support for language_code on applicable methods
kmaphoenix Aug 23, 2024
32e7a9f
fix: update copy_util to resolve bug issue 192
my3sons Jul 15, 2024
645d0b4
feat: add support for parameters / end_user_metadata
kmaphoenix Aug 27, 2024
850f93e
fix: input dataframe prep col types
kmaphoenix Aug 27, 2024
0909acb
feat: add support for playbook versions
kmaphoenix Aug 27, 2024
430b9e2
chore: ignore linting of ipynb files
kmaphoenix Sep 3, 2024
5375a0d
fix: inherited auth and scopes fix for dffx class
kmaphoenix Sep 3, 2024
2239d22
Update vertex_agents_evals.ipynb
YuncongZhou Sep 10, 2024
1e4ec49
linting fixes
sridharvikram Sep 14, 2024
68ed3a4
readme doc fix
sridharvikram Sep 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pylint
name: Ruff

on:
push:
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint==3.1.0
- name: Running Pylint
pip install ruff
- name: Running Ruff Check
run: |
pylint --rcfile=.pylintrc $(git ls-files '*.py')
ruff check $(git ls-files '*.py')
29 changes: 29 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: pytest

on:
push:
branches:
- '**'
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pandas tqdm
pip install -e .
pip install -r requirements.txt
- name: Running Tests
run: |
pytest tests/dfcx_scrapi/ -vv
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.py[cod]
*.sw[op]

# specific files
code-context.txt

# cloud shell
.theia

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ pfreeze:
pip freeze > requirements.txt

test:
pytest tests/dfcx_scrapi/core/$(f)
@if [ -n "$(v)" ]; then \
pytest tests/dfcx_scrapi/$(f) -vv; \
else \
pytest tests/dfcx_scrapi/$(f); \
fi

lint:
pylint --rcfile=.pylintrc src/dfcx_scrapi/*
pylint --rcfile=.pylintrc tests/dfcx_scrapi/*
ruff check

# just fix selected whitespace
autofix-min-whitespace:
Expand All @@ -35,3 +38,6 @@ fix:
build:
python3 -m build
pip uninstall dfcx-scrapi -y

context-file:
find . -name "*.py" -print0 | xargs -0 -I {} sh -c 'echo "=== {} ==="; cat {}' > code-context.txt
Empty file.
49 changes: 49 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/UAT/cloudbuild_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
steps:

- id: SHAGCSCopy
name: gcr.io/google.com/cloudsdktool/cloud-sdk
#dir: 'set your path till the readme doc in the git'
entrypoint: /bin/bash
args:
- '-c'
- |
chmod 777 UAT/gcssha.sh
UAT/gcssha.sh $COMMIT_SHA

- id: deployagent
name: 'python:3.10'
#dir: 'set your path till the readme doc in the git'
entrypoint: /bin/bash
args:
- -c
- |
pip3 install -r UAT/requirements.txt
python3 -m UAT.deploy $COMMIT_SHA
echo $?

- id: CheckExitCode
name: 'gcr.io/cloud-builders/gcloud'
#dir: 'set your path till the readme doc in the git'
entrypoint: 'bash'
args:
- '-c'
- |
if [[ "$$BUILD_STATUS" -ne 0 ]]; then
echo "Stopping the build due to a previous failure."
exit 1
fi


- id: triggerproddeploy
name: gcr.io/google.com/cloudsdktool/cloud-sdk
#dir: 'set your path till the readme doc in the git'
entrypoint: /bin/bash
args:
- '-c'
- |
chmod 777 UAT/trigger.sh
UAT/trigger.sh $LOCATION $COMMIT_SHA


options:
logging: CLOUD_LOGGING_ONLY
71 changes: 71 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/UAT/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
""" UAT Deployment functions"""

import sys
import json
import logging

from shared.deployment import Deployment


#from .shared.deployments import Deployment
# logging config
logging.basicConfig(
level=logging.INFO,
format="UAT: %(asctime)s %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)


def main(data):
"""
Deploys and tests a Dialogflow CX agent in a UAT environment.

This function performs the following steps:

1. Initializes a Deployment object with the provided data.
2. Imports the agent to the specified UAT webhook environment.
3. Validates test cases.
4. Collects flow IDs.
5. Deletes versions based on count.
6. Cuts a new version.
7. Deploys the new version.
8. Updates the datastore with UAT information.

Args:
data: A dictionary containing configuration data, including the 'uat_webhook_env' key.
"""

dep=Deployment(data)
# call the steps sequentially
dep.import_agent(webhookenv=data["uat_webhook_env"])
dep.test_case_validation()
dep.collect_flow_id()
dep.version_count_delete()
dep.version_cut()
dep.deploy_versions()
dep.datastore_update("uat")



if __name__=="__main__":
# read env variables
with open("config.json" , encoding='utf-8') as config_file:
config = json.load(config_file)
SHA_ID=sys.argv[1]
obj=f"UAT/{config['agent_name']}/{SHA_ID}"
sha_gs_loc=(
f"gs://{config['bucket']}/UAT/{config['agent_name']}/{SHA_ID}"
)
logging.info("Agent location: %s" ,sha_gs_loc)
#adding additional variables to dict
config["sha_agent_gcs_location"]=sha_gs_loc
config["target_project_id"] = config["uat_project"]
config["target_environment_name"]=config["uat_env_deploy"]
with open("agent_artifacts/metadata.json" , encoding='utf-8') as metadata_file:
metadata = json.load(metadata_file)

config["source_flow_names"]=metadata["source_flow_names"]
config["updated_commit_message"]=metadata["updated_commit_message"]

# To execute steps in order
main(config)
21 changes: 21 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/UAT/gcssha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Set your GCS bucket name and destination directory
apt-get update && apt-get install -y jq
export GCS_BUCKET=$(jq -r .bucket config.json)
export agent_name=$(jq -r .agent_name config.json)
export DESTINATION_DIR="UAT/${agent_name}/"
echo $DESTINATION_DIR
# Create a local directory
mkdir -p $1

# Copy your two files to the local directory
cp agent_artifacts/$agent_name $1
cp agent_artifacts/metadata.json $1

# Upload the local directory to GCS
gsutil -m cp -r $1 "gs://$GCS_BUCKET/$DESTINATION_DIR"

# Clean up the local directory if needed
rm -r $1

echo "Files copied and uploaded to GCS."
3 changes: 3 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/UAT/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dfcx-scrapi
google-cloud-storage
pandas
22 changes: 22 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/UAT/trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
echo $1
apt-get update && apt-get install -y jq
export devops_project_id=$(jq -r .devops_project config.json)
export prod_project_id=$(jq -r .prod_project config.json)

#Use below command to trigger the build if manual invokation is used. Since there is no secret , no extra charges

export build_info=$(gcloud builds triggers run prodbuild --project=$devops_project_id --substitutions=_COMMIT_SHA=$2 --region=$1 --format=json)
echo "devops prod triggerdone"


#getting the trigger id of the above trigger

export prod_build_id=$(echo "$build_info" | jq -r '.metadata.build.id')
echo "build id returned back is"
echo $prod_build_id


#Trigger the build in prod project which is used for approval
gcloud builds triggers run prodapprovebuild --project=$devops_project_id --substitutions=_APP_BUILD_ID=$prod_build_id --region=$1

echo "prod project approve build triggered"
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
steps:
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
args:
- '-c'
- |
apt-get update && apt-get install -y jq
echo $BUILD_ID

export devopsprojecthere=$(jq -r .devops_project config.json)
export build_info=$(gcloud builds describe $BUILD_ID --region=us-central1 --format=json)
export approverhere=$(echo "$build_info" | jq -r '.approval.result.approverAccount')
export commenthere=$(echo "$build_info" | jq -r '.approval.result.comment')
export tokenhere=$(gcloud auth print-access-token)

echo $approverhere
echo $tokenhere

chmod 777 approveprod/trigger.sh

sed -i "s/tokenhere/$tokenhere/g" approveprod/trigger.sh
sed -i "s/approverhere/$approverhere/g" approveprod/trigger.sh
sed -i "s/devopsprojecthere/$devopsprojecthere/g" approveprod/trigger.sh
sed -i "s/commenthere/$commenthere/g" approveprod/trigger.sh
sed -i "s/appbuildhere/$_APP_BUILD_ID/g" approveprod/trigger.sh
cat approveprod/trigger.sh
approveprod/trigger.sh
echo $?
echo "prod build approved from code"

echo "error exit code"

id: triggerexportbuild
entrypoint: /bin/bash
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
6 changes: 6 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/approveprod/trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
curl --request POST \
'https://cloudbuild.googleapis.com/v1/projects/devopsprojecthere/locations/us-central1/builds/appbuildhere:approve?access_token=tokenhere' \
--header 'Accept: application/json'\
--header 'Content-Type:application/json' --data \
'{"approvalResult":{"decision":"APPROVED","comment":"commenthere","approverAccount":"approverhere"}}' \
--compressed
16 changes: 16 additions & 0 deletions examples/dfcx_agent_cicd/cicd_code/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"agent_name" : "carrental",
"dev_env_pull" : "ready to deploy",
"uat_env_deploy" : "ready to test",
"prod_env_deploy" :"deployed",
"devprodsyncenv" :"deployed",
"bucket": "dfcx_agent_cicd_export",
"dev_project": "yourprojectid",
"uat_project" : "yourprojectid",
"prod_project": "yourprojectid",
"devops_project": "yourprojectid",
"uat_webhook_env": "uat",
"prod_webhook_env": "prod",
"uat_engine_id" :"",
"prod_engine_id" :""
}
Empty file.
Loading
Loading