-
Notifications
You must be signed in to change notification settings - Fork 2
164 lines (136 loc) · 6.36 KB
/
deploy-prod.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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