From e402687988ee57c147e0464f819c58cf9513c484 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 15 May 2025 23:09:39 -0400 Subject: [PATCH] Add prettier-plugin-sh (#762) ## Description: Add prettier-plugin-sh to format shell files. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- .dockerignore | 2 +- .editorconfig | 3 ++ .gitignore | 2 +- .husky/pre-commit | 2 +- .prettierrc | 16 ++++++++- Dockerfile | 4 +-- deploy.sh | 46 ++++++++++++------------ example.env | 2 +- package-lock.json | 53 ++++++++++++++++++++++++++-- package.json | 1 + setup.sh | 46 ++++++++++++------------ startup.sh | 90 ++++++++++++++++++++++++----------------------- update.sh | 53 ++++++++++++++-------------- 13 files changed, 193 insertions(+), 127 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9b495245d..f965aed11 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,4 +12,4 @@ helm-charts .env .editorconfig .idea -coverage* \ No newline at end of file +coverage* diff --git a/.editorconfig b/.editorconfig index fb081eac4..9a46a9a1f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true + +[*.sh] +indent_size = 4 diff --git a/.gitignore b/.gitignore index f65e77037..90ce6e054 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ TODO.txt resources/images/.DS_Store resources/.DS_Store .env* -.DS_Store \ No newline at end of file +.DS_Store diff --git a/.husky/pre-commit b/.husky/pre-commit index 2b8ba2862..a282f31f5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -5,4 +5,4 @@ export PATH="/usr/local/bin:$HOME/.npm-global/bin:$HOME/.nvm/versions/node/$(node -v)/bin:$PATH" # Then run lint-staged if tests pass -npx lint-staged \ No newline at end of file +npx lint-staged diff --git a/.prettierrc b/.prettierrc index 55c1943ae..b203bcc81 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,17 @@ { - "plugins": ["prettier-plugin-organize-imports"] + "overrides": [ + { + "files": ".husky/**", + "options": { + "plugins": [] + } + }, + { + "files": "Dockerfile", + "options": { + "plugins": [] + } + } + ], + "plugins": ["prettier-plugin-organize-imports", "prettier-plugin-sh"] } diff --git a/Dockerfile b/Dockerfile index 91404240d..e904f6bbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ WORKDIR /usr/src/app COPY package*.json ./ # Install dependencies while bypassing Husky hooks -ENV HUSKY=0 +ENV HUSKY=0 ENV NPM_CONFIG_IGNORE_SCRIPTS=1 RUN mkdir -p .git && npm install @@ -60,4 +60,4 @@ COPY startup.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/startup.sh # Use the startup script as the entrypoint -ENTRYPOINT ["/usr/local/bin/startup.sh"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/startup.sh"] diff --git a/deploy.sh b/deploy.sh index 6a254fa38..48c9cc5f5 100755 --- a/deploy.sh +++ b/deploy.sh @@ -5,7 +5,7 @@ # 2. Copies the update script to Hetzner server # 3. Executes the update script on the Hetzner server -set -e # Exit immediately if a command exits with a non-zero status +set -e # Exit immediately if a command exits with a non-zero status # Initialize variables ENABLE_BASIC_AUTH=false @@ -13,16 +13,16 @@ ENABLE_BASIC_AUTH=false # Parse command line arguments POSITIONAL_ARGS=() while [[ $# -gt 0 ]]; do - case $1 in - --enable_basic_auth) - ENABLE_BASIC_AUTH=true - shift - ;; - *) - POSITIONAL_ARGS+=("$1") - shift - ;; - esac + case $1 in + --enable_basic_auth) + ENABLE_BASIC_AUTH=true + shift + ;; + *) + POSITIONAL_ARGS+=("$1") + shift + ;; + esac done # Restore positional parameters @@ -58,7 +58,7 @@ print_header() { ENV=$1 HOST=$2 -SUBDOMAIN=$3 # Optional third argument for custom subdomain +SUBDOMAIN=$3 # Optional third argument for custom subdomain # Set subdomain - use the custom subdomain if provided, otherwise use REGION if [ -n "$SUBDOMAIN" ]; then @@ -116,10 +116,10 @@ else fi # Configuration -UPDATE_SCRIPT="./update.sh" # Path to your update script -REMOTE_USER="openfront" -REMOTE_UPDATE_PATH="/home/$REMOTE_USER" -REMOTE_UPDATE_SCRIPT="$REMOTE_UPDATE_PATH/update-openfront.sh" # Where to place the script on server +UPDATE_SCRIPT="./update.sh" # Path to your update script +REMOTE_USER="openfront" +REMOTE_UPDATE_PATH="/home/$REMOTE_USER" +REMOTE_UPDATE_SCRIPT="$REMOTE_UPDATE_PATH/update-openfront.sh" # Where to place the script on server VERSION_TAG=$(date +"%Y%m%d-%H%M%S") DOCKER_IMAGE="${DOCKER_USERNAME}/${DOCKER_REPO}:${VERSION_TAG}" @@ -139,15 +139,15 @@ echo "Using version tag: $VERSION_TAG" echo "Docker repository: $DOCKER_REPO" # Get Git commit for build info -GIT_COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown") +GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null || echo "unknown") echo "Git commit: $GIT_COMMIT" docker buildx build \ - --platform linux/amd64 \ - --build-arg GIT_COMMIT=$GIT_COMMIT \ - -t $DOCKER_IMAGE \ - --push \ - . + --platform linux/amd64 \ + --build-arg GIT_COMMIT=$GIT_COMMIT \ + -t $DOCKER_IMAGE \ + --push \ + . if [ $? -ne 0 ]; then echo "❌ Docker build failed. Stopping deployment." @@ -206,4 +206,4 @@ if [ "$ENABLE_BASIC_AUTH" = true ]; then echo "🔒 Basic authentication enabled with user: $BASIC_AUTH_USER" fi echo "🌐 Check your server to verify the deployment." -echo "=======================================================" \ No newline at end of file +echo "=======================================================" diff --git a/example.env b/example.env index 14430d50d..03ce7bd1d 100644 --- a/example.env +++ b/example.env @@ -29,4 +29,4 @@ MON_USERNAME=monitor_username MON_PASSWORD=monitor_password # Version -VERSION_TAG="latest" \ No newline at end of file +VERSION_TAG="latest" diff --git a/package-lock.json b/package-lock.json index 2d589423f..562345cd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -114,6 +114,7 @@ "postcss-loader": "^8.1.1", "prettier": "^3.5.3", "prettier-plugin-organize-imports": "^4.1.0", + "prettier-plugin-sh": "^0.17.4", "raw-loader": "^4.0.2", "sinon": "^18.0.0", "sinon-chai": "^4.0.0", @@ -6826,6 +6827,16 @@ "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", "license": "BSD-3-Clause" }, + "node_modules/@reteps/dockerfmt": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/@reteps/dockerfmt/-/dockerfmt-0.3.6.tgz", + "integrity": "sha512-Tb5wIMvBf/nLejTQ61krK644/CEMB/cpiaIFXqGApfGqO3GwcR3qnI0DbmkFVCl2OyEp8LnLX3EkucoL0+tbFg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^v12.20.0 || ^14.13.0 || >=16.0.0" + } + }, "node_modules/@sapphire/async-queue": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.5.tgz", @@ -17734,6 +17745,26 @@ } } }, + "node_modules/prettier-plugin-sh": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/prettier-plugin-sh/-/prettier-plugin-sh-0.17.4.tgz", + "integrity": "sha512-aAVKXZ7GTEMZdZsIPSwMwddwPvt2ibMbRGd4OJAP0G7QoeYZV+mPNg2Oln3R53sZ4PVjeAA7Xzi/PuI0QlHHfQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@reteps/dockerfmt": "^0.3.5", + "sh-syntax": "^0.5.6" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + }, + "peerDependencies": { + "prettier": "^3.0.3" + } + }, "node_modules/pretty-error": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", @@ -18746,6 +18777,22 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/sh-syntax": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/sh-syntax/-/sh-syntax-0.5.7.tgz", + "integrity": "sha512-74m9dt91konrF5+m0kASugzi37VxKsnTJQ6yvdDZu3IijG5/vIZpImP6FadsJLWNt2X2YD0VaTwW5W7Ox7mFVg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tslib": "^2.8.1" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/sh-syntax" + } + }, "node_modules/shallow-clone": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", @@ -20244,9 +20291,9 @@ } }, "node_modules/tslib": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", - "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, "node_modules/tsx": { diff --git a/package.json b/package.json index 8f6cfe02f..a21f588ec 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "postcss-loader": "^8.1.1", "prettier": "^3.5.3", "prettier-plugin-organize-imports": "^4.1.0", + "prettier-plugin-sh": "^0.17.4", "raw-loader": "^4.0.2", "sinon": "^18.0.0", "sinon-chai": "^4.0.0", diff --git a/setup.sh b/setup.sh index f1165b338..8e9cd176b 100644 --- a/setup.sh +++ b/setup.sh @@ -31,7 +31,7 @@ fi echo "👤 Setting up openfront user..." # Create openfront user if it doesn't exist -if id "openfront" &>/dev/null; then +if id "openfront" &> /dev/null; then echo "User openfront already exists" else useradd -m -s /bin/bash openfront @@ -72,7 +72,7 @@ else echo "# UDP buffer size settings for improved QUIC performance" >> /etc/sysctl.conf echo "net.core.rmem_max=7500000" >> /etc/sysctl.conf echo "net.core.wmem_max=7500000" >> /etc/sysctl.conf - + # Apply the settings immediately sysctl -p echo "UDP buffer sizes configured and applied" @@ -139,41 +139,41 @@ chown -R openfront:openfront "$OTEL_CONFIG_DIR" # Run Node Exporter echo "🚀 Starting Node Exporter..." docker pull prom/node-exporter:latest -docker rm -f node-exporter 2>/dev/null || true +docker rm -f node-exporter 2> /dev/null || true docker run -d \ - --name=node-exporter \ - --restart=unless-stopped \ - --net="host" \ - --pid="host" \ - -v "/:/host:ro,rslave" \ - prom/node-exporter:latest \ - --path.rootfs=/host + --name=node-exporter \ + --restart=unless-stopped \ + --net="host" \ + --pid="host" \ + -v "/:/host:ro,rslave" \ + prom/node-exporter:latest \ + --path.rootfs=/host # Run OpenTelemetry Collector echo "🚀 Starting OpenTelemetry Collector..." docker pull otel/opentelemetry-collector-contrib:latest -docker rm -f otel-collector 2>/dev/null || true +docker rm -f otel-collector 2> /dev/null || true # Run OpenTelemetry Collector with appropriate permissions # Run OpenTelemetry Collector echo "🚀 Starting OpenTelemetry Collector..." docker pull otel/opentelemetry-collector-contrib:latest -docker rm -f otel-collector 2>/dev/null || true +docker rm -f otel-collector 2> /dev/null || true docker run -d \ - --name=otel-collector \ - --restart=unless-stopped \ - --network=host \ - --user=0 \ - -v "$OTEL_CONFIG_DIR/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro" \ - -e OTEL_ENDPOINT="${OTEL_ENDPOINT}" \ - otel/opentelemetry-collector-contrib:latest + --name=otel-collector \ + --restart=unless-stopped \ + --network=host \ + --user=0 \ + -v "$OTEL_CONFIG_DIR/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro" \ + -e OTEL_ENDPOINT="${OTEL_ENDPOINT}" \ + otel/opentelemetry-collector-contrib:latest # Check if containers are running if docker ps | grep -q node-exporter && docker ps | grep -q otel-collector; then - echo "✅ Node Exporter and OpenTelemetry Collector started successfully!" + echo "✅ Node Exporter and OpenTelemetry Collector started successfully!" else - echo "❌ Failed to start containers. Check logs with: docker logs node-exporter or docker logs otel-collector" - exit 1 + echo "❌ Failed to start containers. Check logs with: docker logs node-exporter or docker logs otel-collector" + exit 1 fi echo "=====================================================" @@ -188,4 +188,4 @@ echo "📝 Configuration:" echo " - Config Directory: $OTEL_CONFIG_DIR" echo " - OpenTelemetry Endpoint: $OTEL_ENDPOINT" echo " - Username: $OTEL_USERNAME" -echo "=====================================================" \ No newline at end of file +echo "=====================================================" diff --git a/startup.sh b/startup.sh index a7d7d76ff..393c85c22 100644 --- a/startup.sh +++ b/startup.sh @@ -3,9 +3,9 @@ set -e # Check if required environment variables are set if [ -z "$CF_API_TOKEN" ] || [ -z "$CF_ACCOUNT_ID" ] || [ -z "$SUBDOMAIN" ] || [ -z "$DOMAIN" ]; then - echo "Error: Required environment variables not set" - echo "Please set CF_API_TOKEN, CF_ACCOUNT_ID, SUBDOMAIN, and DOMAIN" - exit 1 + echo "Error: Required environment variables not set" + echo "Please set CF_API_TOKEN, CF_ACCOUNT_ID, SUBDOMAIN, and DOMAIN" + exit 1 fi # Generate a unique tunnel name using timestamp @@ -16,18 +16,18 @@ echo "Using unique tunnel name: ${TUNNEL_NAME}" # Create a new tunnel echo "Creating Cloudflare tunnel for subdomain ${SUBDOMAIN}..." TUNNEL_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/cfd_tunnel" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "{\"name\":\"${TUNNEL_NAME}\"}") + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "{\"name\":\"${TUNNEL_NAME}\"}") # Extract tunnel ID and token TUNNEL_ID=$(echo $TUNNEL_RESPONSE | jq -r '.result.id') TUNNEL_TOKEN=$(echo $TUNNEL_RESPONSE | jq -r '.result.token') if [ -z "$TUNNEL_ID" ] || [ "$TUNNEL_ID" == "null" ]; then - echo "Failed to create tunnel" - echo $TUNNEL_RESPONSE - exit 1 + echo "Failed to create tunnel" + echo $TUNNEL_RESPONSE + exit 1 fi echo "Tunnel created with ID: ${TUNNEL_ID}" @@ -35,47 +35,47 @@ echo "Tunnel created with ID: ${TUNNEL_ID}" # Configure the tunnel with hostname echo "Configuring tunnel to point to ${SUBDOMAIN}.${DOMAIN}..." curl -s -X PUT "https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/cfd_tunnel/${TUNNEL_ID}/configurations" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "{\"config\":{\"ingress\":[{\"hostname\":\"${SUBDOMAIN}.${DOMAIN}\",\"service\":\"http://localhost:80\"},{\"service\":\"http_status:404\"}]}}" + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "{\"config\":{\"ingress\":[{\"hostname\":\"${SUBDOMAIN}.${DOMAIN}\",\"service\":\"http://localhost:80\"},{\"service\":\"http_status:404\"}]}}" # Update DNS record to point to the new tunnel echo "Updating DNS record to point to the new tunnel..." # First check if DNS record exists DNS_RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json") + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json") ZONE_ID=$(echo $DNS_RECORDS | jq -r '.result[0].id') if [ -z "$ZONE_ID" ] || [ "$ZONE_ID" == "null" ]; then - echo "Could not find zone ID for domain ${DOMAIN}" - exit 1 + echo "Could not find zone ID for domain ${DOMAIN}" + exit 1 fi # Check for existing record EXISTING_RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?name=${SUBDOMAIN}.${DOMAIN}" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json") + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json") RECORD_ID=$(echo $EXISTING_RECORDS | jq -r '.result[0].id') # Create or update the DNS record if [ -z "$RECORD_ID" ] || [ "$RECORD_ID" == "null" ]; then - # Create new record - echo "Creating new DNS record..." - DNS_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") + # Create new record + echo "Creating new DNS record..." + DNS_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \ + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") else - # Update existing record - echo "Updating existing DNS record..." - DNS_RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \ - -H "Authorization: Bearer ${CF_API_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") + # Update existing record + echo "Updating existing DNS record..." + DNS_RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \ + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") fi # Log the tunnel information @@ -84,23 +84,25 @@ echo "Tunnel is set up! Site will be available at: https://${SUBDOMAIN}.${DOMAIN # Export the tunnel token for supervisord export CLOUDFLARE_TUNNEL_TOKEN=${TUNNEL_TOKEN} - # Check if Basic Auth credentials are set if [ -z "$BASIC_AUTH_USER" ] || [ -z "$BASIC_AUTH_PASS" ]; then - echo "HTTP Basic Authentication will be disabled" + echo "HTTP Basic Authentication will be disabled" else - # Create the htpasswd file - echo "Creating basic auth credentials for user: ${BASIC_AUTH_USER}" - # Ensure apache2-utils is installed for htpasswd - command -v htpasswd >/dev/null 2>&1 || { echo "htpasswd not found, installing apache2-utils..."; apt-get update && apt-get install -y apache2-utils; } - # Create the password file - htpasswd -bc /etc/nginx/.htpasswd ${BASIC_AUTH_USER} ${BASIC_AUTH_PASS} - - # Update Nginx configuration to enable Basic Auth - sed -i '1i auth_basic "Restricted Access";' /etc/nginx/conf.d/default.conf - sed -i '2i auth_basic_user_file /etc/nginx/.htpasswd;' /etc/nginx/conf.d/default.conf - - echo "HTTP Basic Authentication enabled for user: ${BASIC_AUTH_USER}" + # Create the htpasswd file + echo "Creating basic auth credentials for user: ${BASIC_AUTH_USER}" + # Ensure apache2-utils is installed for htpasswd + command -v htpasswd > /dev/null 2>&1 || { + echo "htpasswd not found, installing apache2-utils..." + apt-get update && apt-get install -y apache2-utils + } + # Create the password file + htpasswd -bc /etc/nginx/.htpasswd ${BASIC_AUTH_USER} ${BASIC_AUTH_PASS} + + # Update Nginx configuration to enable Basic Auth + sed -i '1i auth_basic "Restricted Access";' /etc/nginx/conf.d/default.conf + sed -i '2i auth_basic_user_file /etc/nginx/.htpasswd;' /etc/nginx/conf.d/default.conf + + echo "HTTP Basic Authentication enabled for user: ${BASIC_AUTH_USER}" fi # Start supervisord diff --git a/update.sh b/update.sh index 97d57a451..59962bf92 100755 --- a/update.sh +++ b/update.sh @@ -4,15 +4,14 @@ # Load environment variables if .env exists if [ -f /home/openfront/.env ]; then - echo "Loading environment variables from .env file..." - export $(grep -v '^#' /home/openfront/.env | xargs) + echo "Loading environment variables from .env file..." + export $(grep -v '^#' /home/openfront/.env | xargs) fi echo "======================================================" echo "🔄 UPDATING SERVER: ${HOST} ENVIRONMENT" echo "======================================================" - # Container and image configuration CONTAINER_NAME="openfront-${ENV}-${SUBDOMAIN}" @@ -23,45 +22,45 @@ echo "Checking for existing container..." # Check for running container RUNNING_CONTAINER=$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}') if [ -n "$RUNNING_CONTAINER" ]; then - echo "Stopping running container $RUNNING_CONTAINER..." - docker stop $RUNNING_CONTAINER - echo "Waiting for container to fully stop and release resources..." - sleep 5 # Add a 5-second delay - docker rm $RUNNING_CONTAINER - echo "Container $RUNNING_CONTAINER stopped and removed." + echo "Stopping running container $RUNNING_CONTAINER..." + docker stop $RUNNING_CONTAINER + echo "Waiting for container to fully stop and release resources..." + sleep 5 # Add a 5-second delay + docker rm $RUNNING_CONTAINER + echo "Container $RUNNING_CONTAINER stopped and removed." fi # Also check for stopped containers with the same name STOPPED_CONTAINER=$(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}') if [ -n "$STOPPED_CONTAINER" ]; then - echo "Removing stopped container $STOPPED_CONTAINER..." - docker rm $STOPPED_CONTAINER - echo "Container $STOPPED_CONTAINER removed." + echo "Removing stopped container $STOPPED_CONTAINER..." + docker rm $STOPPED_CONTAINER + echo "Container $STOPPED_CONTAINER removed." fi echo "Starting new container for ${HOST} environment..." docker run -d \ - --restart=always \ - --env-file /home/openfront/.env \ - --name ${CONTAINER_NAME} \ - $DOCKER_IMAGE + --restart=always \ + --env-file /home/openfront/.env \ + --name ${CONTAINER_NAME} \ + $DOCKER_IMAGE if [ $? -eq 0 ]; then - echo "Update complete! New ${CONTAINER_NAME} container is running." - - # Final cleanup after successful deployment - echo "Performing final cleanup of unused Docker resources..." - echo "Removing unused images (not referenced)..." - docker image prune -a -f - docker container prune -f - echo "Cleanup complete." + echo "Update complete! New ${CONTAINER_NAME} container is running." + + # Final cleanup after successful deployment + echo "Performing final cleanup of unused Docker resources..." + echo "Removing unused images (not referenced)..." + docker image prune -a -f + docker container prune -f + echo "Cleanup complete." else - echo "Failed to start container" - exit 1 + echo "Failed to start container" + exit 1 fi echo "======================================================" echo "✅ SERVER UPDATE COMPLETED SUCCESSFULLY" echo "Container name: ${CONTAINER_NAME}" echo "Image: ${FULL_IMAGE_NAME}" -echo "======================================================" \ No newline at end of file +echo "======================================================"