Even more cleanup (on aisle my arms)

This commit is contained in:
informaticker 2024-07-02 13:02:31 +00:00
parent c678f67abe
commit 0adaa3e1ee
2 changed files with 15 additions and 47 deletions

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
# Function to display progress bar
show_progress() { show_progress() {
local current=$1 local current=$1
local total=$2 local total=$2
@ -11,15 +9,9 @@ show_progress() {
printf "\rProgress: [%-${width}s] %d%%" "$(printf '#%.0s' $(seq 1 $completed))$(printf ' %.0s' $(seq 1 $remaining))" "$percentage" printf "\rProgress: [%-${width}s] %d%%" "$(printf '#%.0s' $(seq 1 $completed))$(printf ' %.0s' $(seq 1 $remaining))" "$percentage"
} }
# Start timing
start_time=$(date +%s) start_time=$(date +%s)
# Total number of steps
total_steps=7 total_steps=7
current_step=0 current_step=0
# Execute commands with progress updates
oc delete -f deployment/configmap.yaml > /dev/null oc delete -f deployment/configmap.yaml > /dev/null
((current_step++)) ((current_step++))
show_progress $current_step $total_steps show_progress $current_step $total_steps
@ -47,16 +39,8 @@ show_progress $current_step $total_steps
oc delete -f deployment/hpa.yaml > /dev/null oc delete -f deployment/hpa.yaml > /dev/null
((current_step++)) ((current_step++))
show_progress $current_step $total_steps show_progress $current_step $total_steps
# End timing
end_time=$(date +%s) end_time=$(date +%s)
# Calculate duration
duration=$((end_time - start_time)) duration=$((end_time - start_time))
# Print newline after progress bar
echo echo
# Display final timing information
echo "Cleaned up ^w^" echo "Cleaned up ^w^"
echo "Execution completed in $duration seconds." echo "Execution completed in $duration seconds."

View File

@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
# IMPORTANT!!
# Change this to your github username.
# (lowercase or else docker will complain)
GITHUB_USERNAME="informaticker" GITHUB_USERNAME="informaticker"
#GITHUB_USERNAME="your_github_username"
VERSION="v1" VERSION="v1"
# Function to display progress bar and status
show_progress() { show_progress() {
local current=$1 local current=$1
local total=$2 local total=$2
@ -12,21 +13,13 @@ show_progress() {
local percentage=$((current * 100 / total)) local percentage=$((current * 100 / total))
local completed=$((width * current / total)) local completed=$((width * current / total))
local remaining=$((width - completed)) local remaining=$((width - completed))
# Move cursor to the beginning of the line and clear it
echo -ne "\r\033[K" echo -ne "\r\033[K"
# Print status and progress bar
echo -ne "$status\n" echo -ne "$status\n"
printf "Progress: [%-${width}s] %d%%" "$(printf '#%.0s' $(seq 1 $completed))$(printf ' %.0s' $(seq 1 $remaining))" "$percentage" printf "Progress: [%-${width}s] %d%%" "$(printf '#%.0s' $(seq 1 $completed))$(printf ' %.0s' $(seq 1 $remaining))" "$percentage"
} }
# Function to run command and check for errors
run_command() { run_command() {
local command="$1" local command="$1"
local status="$2" local status="$2"
# Save cursor position
tput sc tput sc
show_progress $current_step $total_steps "$status" show_progress $current_step $total_steps "$status"
@ -35,40 +28,27 @@ run_command() {
exit 1 exit 1
fi fi
((current_step++)) ((current_step++))
# Restore cursor position
tput rc tput rc
} }
# Start timing
start_time=$(date +%s) start_time=$(date +%s)
# Total number of steps
total_steps=11 total_steps=11
current_step=0 current_step=0
# Clear screen and move cursor to top-left
clear clear
tput cup 0 0 tput cup 0 0
if [ "$GITHUB_USERNAME" == "your_github_username" ]; then if [ "$GITHUB_USERNAME" == "your_github_username" ]; then
echo "You buffoon, change your github username in the file." echo "You buffoon, change your github username in the file."
exit 1 exit 1
fi fi
replace_placeholders() { replace_placeholders() {
run_command "sed -i \"s|ghcr.io/informaticker/zli-counter-frontend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}|g\" deployment/frontend.yaml && \ run_command "sed -i \"s|ghcr.io/informaticker/zli-counter-frontend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}|g\" deployment/frontend.yaml && \
sed -i \"s|ghcr.io/informaticker/zli-counter-backend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}|g\" deployment/backend.yaml" \ sed -i \"s|ghcr.io/informaticker/zli-counter-backend:v1|ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}|g\" deployment/backend.yaml" \
"Replacing placeholders in deployment files" "Replacing placeholders in deployment files"
} }
run_command "docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION} counter_kand/backend" "Building backend Docker image" run_command "docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION} counter_kand/backend" "Building backend Docker image"
run_command "docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION} counter_kand/frontend" "Building frontend Docker image" run_command "docker build -t ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION} counter_kand/frontend" "Building frontend Docker image"
run_command "docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}" "Pushing backend Docker image" run_command "docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-backend:${VERSION}" "Pushing backend Docker image"
run_command "docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}" "Pushing frontend Docker image" run_command "docker push ghcr.io/${GITHUB_USERNAME}/zli-counter-frontend:${VERSION}" "Pushing frontend Docker image"
replace_placeholders replace_placeholders
run_command "oc apply -f deployment/configmap.yaml" "Applying configmap" run_command "oc apply -f deployment/configmap.yaml" "Applying configmap"
run_command "oc apply -f deployment/secrets.yaml" "Applying secrets" run_command "oc apply -f deployment/secrets.yaml" "Applying secrets"
run_command "oc apply -f deployment/database.yaml" "Applying database configuration" run_command "oc apply -f deployment/database.yaml" "Applying database configuration"
@ -76,16 +56,20 @@ run_command "oc apply -f deployment/pvc.yaml" "Applying PVC"
run_command "oc apply -f deployment/backend.yaml" "Applying backend configuration" run_command "oc apply -f deployment/backend.yaml" "Applying backend configuration"
run_command "oc apply -f deployment/frontend.yaml" "Applying frontend configuration" run_command "oc apply -f deployment/frontend.yaml" "Applying frontend configuration"
run_command "oc apply -f deployment/hpa.yaml" "Applying HPA" run_command "oc apply -f deployment/hpa.yaml" "Applying HPA"
# End timing
end_time=$(date +%s) end_time=$(date +%s)
# Calculate duration
duration=$((end_time - start_time)) duration=$((end_time - start_time))
# Move cursor down and clear the progress bar
tput cud 2 tput cud 2
tput el tput el
echo "Deployment completed successfully! ^w^" echo "Deployment completed successfully! ^w^"
echo "Total execution time: $duration seconds." echo "Total execution time: $duration seconds."
echo "Getting frontend route..."
frontend_route=$(oc get routes -o jsonpath='{.items[?(@.metadata.name=="counter-frontend")].spec.host}')
if [ -n "$frontend_route" ]; then
echo "Frontend route: https://$frontend_route/"
else
echo "Error: Could not retrieve frontend route."
fi
echo "Visit the URL to use the application."