-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_web.sh
34 lines (29 loc) · 1.14 KB
/
update_web.sh
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
#!/bin/bash
# Define variables for deployment details
DEPLOYMENT_LABEL="app=caddy"
CONTAINER_NAME="caddy"
DESTINATION_PATH="/usr/share/caddy/"
SOURCE_PATH="./_site/"
# Check if the source directory exists and is not empty
if [ ! -d "$SOURCE_PATH" ] || [ -z "$(ls -A $SOURCE_PATH)" ]; then
echo "Error: Source directory does not exist or is empty: $SOURCE_PATH"
exit 1
fi
# Get the first pod name matching the deployment label
POD_NAME=$(kubectl get pods -l $DEPLOYMENT_LABEL -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: No pods found matching the deployment label $DEPLOYMENT_LABEL."
exit 1
fi
# Navigate to source path and copy files to the pod
pushd $SOURCE_PATH
if ! kubectl cp ./ $POD_NAME:$DESTINATION_PATH -c $CONTAINER_NAME; then
echo "Error: Failed to copy files to pod $POD_NAME."
popd # Ensure the directory is popped regardless of success or failure
exit 1
fi
popd
kubectl exec $POD_NAME -c $CONTAINER_NAME -- ls -la $DESTINATION_PATH
kubectl exec $POD_NAME -c $CONTAINER_NAME -- grep bg /usr/share/caddy/style.css
STYLE=style.css
echo "Files successfully copied to $POD_NAME:$DESTINATION_PATH"