-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·70 lines (54 loc) · 1.89 KB
/
deploy.sh
File metadata and controls
executable file
·70 lines (54 loc) · 1.89 KB
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
#!/bin/bash
# Execute from within app directory with `../deploy.sh` command or with `./deploy.sh --no-install` to skip installation
# Source the configuration file
source ../pitcher_config.sh
# Function to format JSON or display raw output if not valid JSON
format_or_echo() {
if jq -e . >/dev/null 2>&1 <<<"$1"; then
jq '.' <<<"$1"
else
echo "Response is not valid JSON. Raw output:"
echo "$1"
fi
}
file="app.json"
# Check if file exists and exit if not
if [ ! -f "$file" ]; then
echo "This is not an app. $file not found!"
exit 1
fi
# Extract app_name from app.json
app_name=$(jq -r '.name' $file)
# Construct the new version out of the current date and time
new_version=$(date +"%Y.%m.%d.%H.%M.%S")
# Update the version in the JSON file
jq --arg new_version "$new_version" '.version = $new_version' $file > "tmp.json" && mv "tmp.json" $file
# Create the zip file
zip -r app.zip . -x "*.zip"
# Publish the app
echo ""
echo "Deploying app ${app_name}..."
echo "https://${PITCHER_DOMAIN}.my.pitcher.com/api/v1/apps/publish/"
PUBLISH_RESPONSE=$(curl -s -X POST \
-H "X-API-Key: ${PITCHER_API_KEY}" \
-H "Content-Type: multipart/form-data" \
-F "file=@app.zip" \
"https://${PITCHER_DOMAIN}.my.pitcher.com/api/v1/apps/publish/")
format_or_echo "${PUBLISH_RESPONSE}"
# Clean up
rm app.zip
echo ""
# Check if --no-install flag is present
if [[ "$1" != "--no-install" ]]; then
# Install the app
echo "Installing app ${app_name}..."
echo "https://${PITCHER_DOMAIN}.my.pitcher.com/api/v1/apps/${app_name}/install/"
INSTALL_RESPONSE=$(curl -s -X POST \
-H "X-API-Key: ${PITCHER_API_KEY}" \
-H "Content-Type: multipart/form-data" \
-F "instance_ids=${PITCHER_INSTANCE_ID}" \
"https://${PITCHER_DOMAIN}.my.pitcher.com/api/v1/apps/${app_name}/install/")
format_or_echo "${INSTALL_RESPONSE}"
else
echo "Skipping installation as --no-install flag is present."
fi