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>
This commit is contained in:
Scott Anderson
2025-05-15 23:09:39 -04:00
committed by GitHub
parent 6517f80f68
commit e402687988
13 changed files with 193 additions and 127 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ helm-charts
.env .env
.editorconfig .editorconfig
.idea .idea
coverage* coverage*
+3
View File
@@ -7,3 +7,6 @@ end_of_line = lf
indent_size = 2 indent_size = 2
indent_style = space indent_style = space
insert_final_newline = true insert_final_newline = true
[*.sh]
indent_size = 4
+1 -1
View File
@@ -6,4 +6,4 @@ TODO.txt
resources/images/.DS_Store resources/images/.DS_Store
resources/.DS_Store resources/.DS_Store
.env* .env*
.DS_Store .DS_Store
+1 -1
View File
@@ -5,4 +5,4 @@
export PATH="/usr/local/bin:$HOME/.npm-global/bin:$HOME/.nvm/versions/node/$(node -v)/bin:$PATH" export PATH="/usr/local/bin:$HOME/.npm-global/bin:$HOME/.nvm/versions/node/$(node -v)/bin:$PATH"
# Then run lint-staged if tests pass # Then run lint-staged if tests pass
npx lint-staged npx lint-staged
+15 -1
View File
@@ -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"]
} }
+2 -2
View File
@@ -33,7 +33,7 @@ WORKDIR /usr/src/app
COPY package*.json ./ COPY package*.json ./
# Install dependencies while bypassing Husky hooks # Install dependencies while bypassing Husky hooks
ENV HUSKY=0 ENV HUSKY=0
ENV NPM_CONFIG_IGNORE_SCRIPTS=1 ENV NPM_CONFIG_IGNORE_SCRIPTS=1
RUN mkdir -p .git && npm install RUN mkdir -p .git && npm install
@@ -60,4 +60,4 @@ COPY startup.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/startup.sh RUN chmod +x /usr/local/bin/startup.sh
# Use the startup script as the entrypoint # Use the startup script as the entrypoint
ENTRYPOINT ["/usr/local/bin/startup.sh"] ENTRYPOINT ["/usr/local/bin/startup.sh"]
+23 -23
View File
@@ -5,7 +5,7 @@
# 2. Copies the update script to Hetzner server # 2. Copies the update script to Hetzner server
# 3. Executes the update script on the 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 # Initialize variables
ENABLE_BASIC_AUTH=false ENABLE_BASIC_AUTH=false
@@ -13,16 +13,16 @@ ENABLE_BASIC_AUTH=false
# Parse command line arguments # Parse command line arguments
POSITIONAL_ARGS=() POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--enable_basic_auth) --enable_basic_auth)
ENABLE_BASIC_AUTH=true ENABLE_BASIC_AUTH=true
shift shift
;; ;;
*) *)
POSITIONAL_ARGS+=("$1") POSITIONAL_ARGS+=("$1")
shift shift
;; ;;
esac esac
done done
# Restore positional parameters # Restore positional parameters
@@ -58,7 +58,7 @@ print_header() {
ENV=$1 ENV=$1
HOST=$2 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 # Set subdomain - use the custom subdomain if provided, otherwise use REGION
if [ -n "$SUBDOMAIN" ]; then if [ -n "$SUBDOMAIN" ]; then
@@ -116,10 +116,10 @@ else
fi fi
# Configuration # Configuration
UPDATE_SCRIPT="./update.sh" # Path to your update script UPDATE_SCRIPT="./update.sh" # Path to your update script
REMOTE_USER="openfront" REMOTE_USER="openfront"
REMOTE_UPDATE_PATH="/home/$REMOTE_USER" REMOTE_UPDATE_PATH="/home/$REMOTE_USER"
REMOTE_UPDATE_SCRIPT="$REMOTE_UPDATE_PATH/update-openfront.sh" # Where to place the script on server 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") VERSION_TAG=$(date +"%Y%m%d-%H%M%S")
DOCKER_IMAGE="${DOCKER_USERNAME}/${DOCKER_REPO}:${VERSION_TAG}" DOCKER_IMAGE="${DOCKER_USERNAME}/${DOCKER_REPO}:${VERSION_TAG}"
@@ -139,15 +139,15 @@ echo "Using version tag: $VERSION_TAG"
echo "Docker repository: $DOCKER_REPO" echo "Docker repository: $DOCKER_REPO"
# Get Git commit for build info # 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" echo "Git commit: $GIT_COMMIT"
docker buildx build \ docker buildx build \
--platform linux/amd64 \ --platform linux/amd64 \
--build-arg GIT_COMMIT=$GIT_COMMIT \ --build-arg GIT_COMMIT=$GIT_COMMIT \
-t $DOCKER_IMAGE \ -t $DOCKER_IMAGE \
--push \ --push \
. .
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "❌ Docker build failed. Stopping deployment." 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" echo "🔒 Basic authentication enabled with user: $BASIC_AUTH_USER"
fi fi
echo "🌐 Check your server to verify the deployment." echo "🌐 Check your server to verify the deployment."
echo "=======================================================" echo "======================================================="
+1 -1
View File
@@ -29,4 +29,4 @@ MON_USERNAME=monitor_username
MON_PASSWORD=monitor_password MON_PASSWORD=monitor_password
# Version # Version
VERSION_TAG="latest" VERSION_TAG="latest"
+50 -3
View File
@@ -114,6 +114,7 @@
"postcss-loader": "^8.1.1", "postcss-loader": "^8.1.1",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-sh": "^0.17.4",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"sinon": "^18.0.0", "sinon": "^18.0.0",
"sinon-chai": "^4.0.0", "sinon-chai": "^4.0.0",
@@ -6826,6 +6827,16 @@
"integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==",
"license": "BSD-3-Clause" "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": { "node_modules/@sapphire/async-queue": {
"version": "1.5.5", "version": "1.5.5",
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.5.tgz", "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": { "node_modules/pretty-error": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz",
@@ -18746,6 +18777,22 @@
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC" "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": { "node_modules/shallow-clone": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz",
@@ -20244,9 +20291,9 @@
} }
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.8.0", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD" "license": "0BSD"
}, },
"node_modules/tsx": { "node_modules/tsx": {
+1
View File
@@ -61,6 +61,7 @@
"postcss-loader": "^8.1.1", "postcss-loader": "^8.1.1",
"prettier": "^3.5.3", "prettier": "^3.5.3",
"prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-sh": "^0.17.4",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"sinon": "^18.0.0", "sinon": "^18.0.0",
"sinon-chai": "^4.0.0", "sinon-chai": "^4.0.0",
+23 -23
View File
@@ -31,7 +31,7 @@ fi
echo "👤 Setting up openfront user..." echo "👤 Setting up openfront user..."
# Create openfront user if it doesn't exist # 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" echo "User openfront already exists"
else else
useradd -m -s /bin/bash openfront useradd -m -s /bin/bash openfront
@@ -72,7 +72,7 @@ else
echo "# UDP buffer size settings for improved QUIC performance" >> /etc/sysctl.conf echo "# UDP buffer size settings for improved QUIC performance" >> /etc/sysctl.conf
echo "net.core.rmem_max=7500000" >> /etc/sysctl.conf echo "net.core.rmem_max=7500000" >> /etc/sysctl.conf
echo "net.core.wmem_max=7500000" >> /etc/sysctl.conf echo "net.core.wmem_max=7500000" >> /etc/sysctl.conf
# Apply the settings immediately # Apply the settings immediately
sysctl -p sysctl -p
echo "UDP buffer sizes configured and applied" echo "UDP buffer sizes configured and applied"
@@ -139,41 +139,41 @@ chown -R openfront:openfront "$OTEL_CONFIG_DIR"
# Run Node Exporter # Run Node Exporter
echo "🚀 Starting Node Exporter..." echo "🚀 Starting Node Exporter..."
docker pull prom/node-exporter:latest 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 \ docker run -d \
--name=node-exporter \ --name=node-exporter \
--restart=unless-stopped \ --restart=unless-stopped \
--net="host" \ --net="host" \
--pid="host" \ --pid="host" \
-v "/:/host:ro,rslave" \ -v "/:/host:ro,rslave" \
prom/node-exporter:latest \ prom/node-exporter:latest \
--path.rootfs=/host --path.rootfs=/host
# Run OpenTelemetry Collector # Run OpenTelemetry Collector
echo "🚀 Starting OpenTelemetry Collector..." echo "🚀 Starting OpenTelemetry Collector..."
docker pull otel/opentelemetry-collector-contrib:latest 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 with appropriate permissions
# Run OpenTelemetry Collector # Run OpenTelemetry Collector
echo "🚀 Starting OpenTelemetry Collector..." echo "🚀 Starting OpenTelemetry Collector..."
docker pull otel/opentelemetry-collector-contrib:latest 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 \ docker run -d \
--name=otel-collector \ --name=otel-collector \
--restart=unless-stopped \ --restart=unless-stopped \
--network=host \ --network=host \
--user=0 \ --user=0 \
-v "$OTEL_CONFIG_DIR/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro" \ -v "$OTEL_CONFIG_DIR/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro" \
-e OTEL_ENDPOINT="${OTEL_ENDPOINT}" \ -e OTEL_ENDPOINT="${OTEL_ENDPOINT}" \
otel/opentelemetry-collector-contrib:latest otel/opentelemetry-collector-contrib:latest
# Check if containers are running # Check if containers are running
if docker ps | grep -q node-exporter && docker ps | grep -q otel-collector; then 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 else
echo "❌ Failed to start containers. Check logs with: docker logs node-exporter or docker logs otel-collector" echo "❌ Failed to start containers. Check logs with: docker logs node-exporter or docker logs otel-collector"
exit 1 exit 1
fi fi
echo "=====================================================" echo "====================================================="
@@ -188,4 +188,4 @@ echo "📝 Configuration:"
echo " - Config Directory: $OTEL_CONFIG_DIR" echo " - Config Directory: $OTEL_CONFIG_DIR"
echo " - OpenTelemetry Endpoint: $OTEL_ENDPOINT" echo " - OpenTelemetry Endpoint: $OTEL_ENDPOINT"
echo " - Username: $OTEL_USERNAME" echo " - Username: $OTEL_USERNAME"
echo "=====================================================" echo "====================================================="
+46 -44
View File
@@ -3,9 +3,9 @@ set -e
# Check if required environment variables are set # Check if required environment variables are set
if [ -z "$CF_API_TOKEN" ] || [ -z "$CF_ACCOUNT_ID" ] || [ -z "$SUBDOMAIN" ] || [ -z "$DOMAIN" ]; then if [ -z "$CF_API_TOKEN" ] || [ -z "$CF_ACCOUNT_ID" ] || [ -z "$SUBDOMAIN" ] || [ -z "$DOMAIN" ]; then
echo "Error: Required environment variables not set" echo "Error: Required environment variables not set"
echo "Please set CF_API_TOKEN, CF_ACCOUNT_ID, SUBDOMAIN, and DOMAIN" echo "Please set CF_API_TOKEN, CF_ACCOUNT_ID, SUBDOMAIN, and DOMAIN"
exit 1 exit 1
fi fi
# Generate a unique tunnel name using timestamp # Generate a unique tunnel name using timestamp
@@ -16,18 +16,18 @@ echo "Using unique tunnel name: ${TUNNEL_NAME}"
# Create a new tunnel # Create a new tunnel
echo "Creating Cloudflare tunnel for subdomain ${SUBDOMAIN}..." 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" \ 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 "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "{\"name\":\"${TUNNEL_NAME}\"}") --data "{\"name\":\"${TUNNEL_NAME}\"}")
# Extract tunnel ID and token # Extract tunnel ID and token
TUNNEL_ID=$(echo $TUNNEL_RESPONSE | jq -r '.result.id') TUNNEL_ID=$(echo $TUNNEL_RESPONSE | jq -r '.result.id')
TUNNEL_TOKEN=$(echo $TUNNEL_RESPONSE | jq -r '.result.token') TUNNEL_TOKEN=$(echo $TUNNEL_RESPONSE | jq -r '.result.token')
if [ -z "$TUNNEL_ID" ] || [ "$TUNNEL_ID" == "null" ]; then if [ -z "$TUNNEL_ID" ] || [ "$TUNNEL_ID" == "null" ]; then
echo "Failed to create tunnel" echo "Failed to create tunnel"
echo $TUNNEL_RESPONSE echo $TUNNEL_RESPONSE
exit 1 exit 1
fi fi
echo "Tunnel created with ID: ${TUNNEL_ID}" echo "Tunnel created with ID: ${TUNNEL_ID}"
@@ -35,47 +35,47 @@ echo "Tunnel created with ID: ${TUNNEL_ID}"
# Configure the tunnel with hostname # Configure the tunnel with hostname
echo "Configuring tunnel to point to ${SUBDOMAIN}.${DOMAIN}..." 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" \ 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 "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "{\"config\":{\"ingress\":[{\"hostname\":\"${SUBDOMAIN}.${DOMAIN}\",\"service\":\"http://localhost:80\"},{\"service\":\"http_status:404\"}]}}" --data "{\"config\":{\"ingress\":[{\"hostname\":\"${SUBDOMAIN}.${DOMAIN}\",\"service\":\"http://localhost:80\"},{\"service\":\"http_status:404\"}]}}"
# Update DNS record to point to the new tunnel # Update DNS record to point to the new tunnel
echo "Updating DNS record to point to the new tunnel..." echo "Updating DNS record to point to the new tunnel..."
# First check if DNS record exists # First check if DNS record exists
DNS_RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}" \ DNS_RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}" \
-H "Authorization: Bearer ${CF_API_TOKEN}" \ -H "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
ZONE_ID=$(echo $DNS_RECORDS | jq -r '.result[0].id') ZONE_ID=$(echo $DNS_RECORDS | jq -r '.result[0].id')
if [ -z "$ZONE_ID" ] || [ "$ZONE_ID" == "null" ]; then if [ -z "$ZONE_ID" ] || [ "$ZONE_ID" == "null" ]; then
echo "Could not find zone ID for domain ${DOMAIN}" echo "Could not find zone ID for domain ${DOMAIN}"
exit 1 exit 1
fi fi
# Check for existing record # Check for existing record
EXISTING_RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?name=${SUBDOMAIN}.${DOMAIN}" \ 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 "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
RECORD_ID=$(echo $EXISTING_RECORDS | jq -r '.result[0].id') RECORD_ID=$(echo $EXISTING_RECORDS | jq -r '.result[0].id')
# Create or update the DNS record # Create or update the DNS record
if [ -z "$RECORD_ID" ] || [ "$RECORD_ID" == "null" ]; then if [ -z "$RECORD_ID" ] || [ "$RECORD_ID" == "null" ]; then
# Create new record # Create new record
echo "Creating new DNS record..." echo "Creating new DNS record..."
DNS_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \ DNS_RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \
-H "Authorization: Bearer ${CF_API_TOKEN}" \ -H "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}")
else else
# Update existing record # Update existing record
echo "Updating existing DNS 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}" \ 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 "Authorization: Bearer ${CF_API_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}") --data "{\"type\":\"CNAME\",\"name\":\"${SUBDOMAIN}\",\"content\":\"${TUNNEL_ID}.cfargotunnel.com\",\"ttl\":1,\"proxied\":true}")
fi fi
# Log the tunnel information # 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 the tunnel token for supervisord
export CLOUDFLARE_TUNNEL_TOKEN=${TUNNEL_TOKEN} export CLOUDFLARE_TUNNEL_TOKEN=${TUNNEL_TOKEN}
# Check if Basic Auth credentials are set # Check if Basic Auth credentials are set
if [ -z "$BASIC_AUTH_USER" ] || [ -z "$BASIC_AUTH_PASS" ]; then 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 else
# Create the htpasswd file # Create the htpasswd file
echo "Creating basic auth credentials for user: ${BASIC_AUTH_USER}" echo "Creating basic auth credentials for user: ${BASIC_AUTH_USER}"
# Ensure apache2-utils is installed for htpasswd # 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; } command -v htpasswd > /dev/null 2>&1 || {
# Create the password file echo "htpasswd not found, installing apache2-utils..."
htpasswd -bc /etc/nginx/.htpasswd ${BASIC_AUTH_USER} ${BASIC_AUTH_PASS} apt-get update && apt-get install -y apache2-utils
}
# Update Nginx configuration to enable Basic Auth # Create the password file
sed -i '1i auth_basic "Restricted Access";' /etc/nginx/conf.d/default.conf htpasswd -bc /etc/nginx/.htpasswd ${BASIC_AUTH_USER} ${BASIC_AUTH_PASS}
sed -i '2i auth_basic_user_file /etc/nginx/.htpasswd;' /etc/nginx/conf.d/default.conf
# Update Nginx configuration to enable Basic Auth
echo "HTTP Basic Authentication enabled for user: ${BASIC_AUTH_USER}" 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 fi
# Start supervisord # Start supervisord
+26 -27
View File
@@ -4,15 +4,14 @@
# Load environment variables if .env exists # Load environment variables if .env exists
if [ -f /home/openfront/.env ]; then if [ -f /home/openfront/.env ]; then
echo "Loading environment variables from .env file..." echo "Loading environment variables from .env file..."
export $(grep -v '^#' /home/openfront/.env | xargs) export $(grep -v '^#' /home/openfront/.env | xargs)
fi fi
echo "======================================================" echo "======================================================"
echo "🔄 UPDATING SERVER: ${HOST} ENVIRONMENT" echo "🔄 UPDATING SERVER: ${HOST} ENVIRONMENT"
echo "======================================================" echo "======================================================"
# Container and image configuration # Container and image configuration
CONTAINER_NAME="openfront-${ENV}-${SUBDOMAIN}" CONTAINER_NAME="openfront-${ENV}-${SUBDOMAIN}"
@@ -23,45 +22,45 @@ echo "Checking for existing container..."
# Check for running container # Check for running container
RUNNING_CONTAINER=$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}') RUNNING_CONTAINER=$(docker ps | grep ${CONTAINER_NAME} | awk '{print $1}')
if [ -n "$RUNNING_CONTAINER" ]; then if [ -n "$RUNNING_CONTAINER" ]; then
echo "Stopping running container $RUNNING_CONTAINER..." echo "Stopping running container $RUNNING_CONTAINER..."
docker stop $RUNNING_CONTAINER docker stop $RUNNING_CONTAINER
echo "Waiting for container to fully stop and release resources..." echo "Waiting for container to fully stop and release resources..."
sleep 5 # Add a 5-second delay sleep 5 # Add a 5-second delay
docker rm $RUNNING_CONTAINER docker rm $RUNNING_CONTAINER
echo "Container $RUNNING_CONTAINER stopped and removed." echo "Container $RUNNING_CONTAINER stopped and removed."
fi fi
# Also check for stopped containers with the same name # Also check for stopped containers with the same name
STOPPED_CONTAINER=$(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}') STOPPED_CONTAINER=$(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}')
if [ -n "$STOPPED_CONTAINER" ]; then if [ -n "$STOPPED_CONTAINER" ]; then
echo "Removing stopped container $STOPPED_CONTAINER..." echo "Removing stopped container $STOPPED_CONTAINER..."
docker rm $STOPPED_CONTAINER docker rm $STOPPED_CONTAINER
echo "Container $STOPPED_CONTAINER removed." echo "Container $STOPPED_CONTAINER removed."
fi fi
echo "Starting new container for ${HOST} environment..." echo "Starting new container for ${HOST} environment..."
docker run -d \ docker run -d \
--restart=always \ --restart=always \
--env-file /home/openfront/.env \ --env-file /home/openfront/.env \
--name ${CONTAINER_NAME} \ --name ${CONTAINER_NAME} \
$DOCKER_IMAGE $DOCKER_IMAGE
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Update complete! New ${CONTAINER_NAME} container is running." echo "Update complete! New ${CONTAINER_NAME} container is running."
# Final cleanup after successful deployment # Final cleanup after successful deployment
echo "Performing final cleanup of unused Docker resources..." echo "Performing final cleanup of unused Docker resources..."
echo "Removing unused images (not referenced)..." echo "Removing unused images (not referenced)..."
docker image prune -a -f docker image prune -a -f
docker container prune -f docker container prune -f
echo "Cleanup complete." echo "Cleanup complete."
else else
echo "Failed to start container" echo "Failed to start container"
exit 1 exit 1
fi fi
echo "======================================================" echo "======================================================"
echo "✅ SERVER UPDATE COMPLETED SUCCESSFULLY" echo "✅ SERVER UPDATE COMPLETED SUCCESSFULLY"
echo "Container name: ${CONTAINER_NAME}" echo "Container name: ${CONTAINER_NAME}"
echo "Image: ${FULL_IMAGE_NAME}" echo "Image: ${FULL_IMAGE_NAME}"
echo "======================================================" echo "======================================================"