Update README.md #7
This file contains 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: Deploy to Prod Workspace | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
DEEPSET_CLOUD_API_KEY: ${{ secrets.DEEPSET_CLOUD_API_KEY }} | |
DEEPSET_CLOUD_WORKSPACE_NAME: "YOUR_PROD_WORKSPACE_NAME" | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install jq and yq | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq | |
sudo chmod +x /usr/bin/yq | |
- name: Check if workspace exists | |
run: | | |
echo "Checking if workspace ${DEEPSET_CLOUD_WORKSPACE_NAME} exists..." | |
response=$(curl --silent --show-error \ | |
--write-out "\n%{http_code}" \ | |
--request GET \ | |
--url "https://api.cloud.deepset.ai/api/v1/workspaces/${DEEPSET_CLOUD_WORKSPACE_NAME}" \ | |
--header "Authorization: Bearer ${DEEPSET_CLOUD_API_KEY}") | |
status_code=$(echo "$response" | tail -n1) | |
response_body=$(echo "$response" | sed '$d') | |
echo "Workspace check status code: $status_code" | |
echo "Workspace check response body: $response_body" | |
if [[ $status_code != "200" ]]; then | |
echo "Error: Workspace ${DEEPSET_CLOUD_WORKSPACE_NAME} does not exist or cannot be accessed" | |
exit 1 | |
fi | |
- name: Create or Update Pipelines | |
run: | | |
for pipeline_dir in pipelines/*/; do | |
pipeline_name=$(basename "$pipeline_dir") | |
indexing_yaml="${pipeline_dir}indexing.yaml" | |
query_yaml="${pipeline_dir}query.yaml" | |
echo "Processing pipeline: $pipeline_name" | |
echo "Indexing YAML: $indexing_yaml" | |
echo "Query YAML: $query_yaml" | |
if [[ ! -f "$indexing_yaml" || ! -f "$query_yaml" ]]; then | |
echo "Error: Both indexing.yaml and query.yaml must exist in $pipeline_dir" | |
exit 1 | |
fi | |
# Check if pipeline exists | |
echo "Checking if pipeline $pipeline_name exists..." | |
pipeline_exists=$(curl --silent --show-error \ | |
--write-out "%{http_code}" \ | |
--output /dev/null \ | |
--request GET \ | |
--url "https://api.cloud.deepset.ai/api/v1/workspaces/${DEEPSET_CLOUD_WORKSPACE_NAME}/pipelines/${pipeline_name}" \ | |
--header "Authorization: Bearer ${DEEPSET_CLOUD_API_KEY}") | |
echo "Pipeline existence check status code: $pipeline_exists" | |
indexing_content=$(cat "$indexing_yaml") | |
query_content=$(cat "$query_yaml") | |
if [[ $pipeline_exists == "404" ]]; then | |
echo "Pipeline $pipeline_name doesn't exist. Creating new pipeline..." | |
payload=$(jq -n \ | |
--arg name "$pipeline_name" \ | |
--arg indexing "$indexing_content" \ | |
--arg query "$query_content" \ | |
'{ | |
"name": $name, | |
"deepset_cloud_version": "v2", | |
"indexing_yaml": $indexing, | |
"query_yaml": $query | |
}') | |
response=$(curl --silent --show-error \ | |
--write-out "\n%{http_code}" \ | |
--request POST \ | |
--url "https://api.cloud.deepset.ai/api/v1/workspaces/${DEEPSET_CLOUD_WORKSPACE_NAME}/pipelines" \ | |
--header "Authorization: Bearer ${DEEPSET_CLOUD_API_KEY}" \ | |
--header 'Content-Type: application/json' \ | |
--data "$payload") | |
else | |
echo "Pipeline $pipeline_name exists. Updating pipeline..." | |
payload=$(jq -n \ | |
--arg indexing "$indexing_content" \ | |
--arg query "$query_content" \ | |
'{ | |
"indexing_yaml": $indexing, | |
"query_yaml": $query | |
}') | |
response=$(curl --silent --show-error \ | |
--write-out "\n%{http_code}" \ | |
--request PUT \ | |
--url "https://api.cloud.deepset.ai/api/v1/workspaces/${DEEPSET_CLOUD_WORKSPACE_NAME}/pipelines/${pipeline_name}/yaml" \ | |
--header "Authorization: Bearer ${DEEPSET_CLOUD_API_KEY}" \ | |
--header 'Content-Type: application/json' \ | |
--data "$payload") | |
fi | |
status_code=$(echo "$response" | tail -n1) | |
response_body=$(echo "$response" | sed '$d') | |
echo "Pipeline operation response for $pipeline_name:" | |
echo "Status code: $status_code" | |
echo "Response body: $response_body" | |
if [[ $status_code != "201" && $status_code != "200" ]]; then | |
echo "Pipeline operation failed for $pipeline_name" | |
exit 1 | |
fi | |
done | |
- name: Validate Pipelines | |
run: | | |
echo "Validating pipelines..." | |
validation_response=$(curl --silent --show-error \ | |
--write-out "\n%{http_code}" \ | |
--request POST \ | |
--url "https://api.cloud.deepset.ai/api/v1/workspaces/${DEEPSET_CLOUD_WORKSPACE_NAME}/pipeline_validations" \ | |
--header "Authorization: Bearer ${DEEPSET_CLOUD_API_KEY}" \ | |
--header 'content-type: application/json' \ | |
--data '{"deepset_cloud_version": "v2"}') | |
status_code=$(echo "$validation_response" | tail -n1) | |
response_body=$(echo "$validation_response" | sed '$d') | |
echo "Validation status code: $status_code" | |
echo "Validation response body: $response_body" | |
if [[ $status_code != "204" ]]; then | |
echo "Pipeline validation failed" | |
exit 1 | |
fi | |
- name: Deploy Pipelines to Prod Workspace | |
env: | |
DEEPSET_CLOUD_API_KEY: ${{ secrets.DEEPSET_CLOUD_API_KEY }} | |
DEEPSET_CLOUD_WORKSPACE_NAME: "YOUR_PROD_WORKSPACE_NAME" | |
run: | | |
for pipeline in pipelines/*.yaml; do | |
deepset-cloud pipelines upload \ | |
--api-key "$DEEPSET_CLOUD_API_KEY" \ | |
--workspace-name "$DEEPSET_CLOUD_WORKSPACE_NAME" \ | |
--file "$pipeline" | |
done |