From 0c0ecb5c656bba0d9977ce5b96649564e3430a9e Mon Sep 17 00:00:00 2001 From: PeterNashaat Date: Thu, 15 May 2025 13:53:25 +0000 Subject: [PATCH 1/2] fixing funkwhale --- tfgrid3/funkwhale/scripts/start-fk.sh | 72 +++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/tfgrid3/funkwhale/scripts/start-fk.sh b/tfgrid3/funkwhale/scripts/start-fk.sh index b1c7ea9a..f1e402d7 100644 --- a/tfgrid3/funkwhale/scripts/start-fk.sh +++ b/tfgrid3/funkwhale/scripts/start-fk.sh @@ -4,8 +4,8 @@ set -ex # Check if FUNKWHALE_VERSION is set, if not, default to 1.4.0 FUNKWHALE_VERSION=${FUNKWHALE_VERSION:-1.4.0} -# Create and Change to Funkwhale directory -mkdir /srv/funkwhale/ +# Change to Funkwhale directory +mkdir -p /srv/funkwhale/ cd /srv/funkwhale/ # Download the Docker Compose and environment files for the specified version @@ -21,26 +21,76 @@ sed -i "s#^DJANGO_SECRET_KEY=.*#DJANGO_SECRET_KEY=$DJANGO_SECRET#" .env # Add environment variables to the .env file sed -i "s#^FUNKWHALE_VERSION=.*#FUNKWHALE_VERSION=$FUNKWHALE_VERSION#" .env -sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$Domain#" .env -sed -i 's/^FUNKWHALE_API_IP=.*/FUNKWHALE_API_IP=0.0.0.0/' .env +sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$domain#" .env +sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$FUNKWHALE_HOSTNAME#" .env +sed -i "s#^FUNKWHALE_API_IP=.*#FUNKWHALE_API_IP=0.0.0.0#" .env -# Setting SMTP Config -bash /usr/local/bin/configure-smtp.sh # Pull the latest Docker images for Funkwhale docker-compose pull # Start PSQL service docker-compose up -d postgres +# Waiting for postgres to be ready +echo "[INFO] Waiting for PostgreSQL to be ready..." +until docker-compose exec -T postgres pg_isready -U funkwhale > /dev/null 2>&1; do + echo "[INFO] PostgreSQL not ready yet. Retrying in 5s..." + sleep 5 +done + +echo "[SUCCESS] PostgreSQL is ready. Continuing..." + # Run database migrations docker-compose run --rm api funkwhale-manage migrate # Create a superuser using the provided credentials -docker-compose run --rm -T api funkwhale-manage fw users create --superuser < /etc/nginx/sites-available/funkwhale.conf + +# Comment out SSL cert lines temporarily to allow HTTP access before SSL setup +sed -i "s/listen 443 ssl http2\;/#listen 443 ssl http2\;/" /etc/nginx/sites-available/funkwhale.conf +sed -i "s/listen \[::\]:443 ssl http2;/#listen \[::\]:443 ssl http2;/" /etc/nginx/sites-available/funkwhale.conf +sed -i "s/ssl_certificate/\#ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf + +# Enable the Funkwhale Nginx site and create a backup of the current configuration +ln -s /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-enabled/ +cp /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-available/funkwhale.conf.bak + +# Generate SSL certificate using Certbot +certbot --nginx -d $Domain --non-interactive --agree-tos --register-unsafely-without-email + +# Restore the original Nginx configuration from the backup +mv /etc/nginx/sites-available/funkwhale.conf.bak /etc/nginx/sites-available/funkwhale.conf + +# Uncomment the SSL lines after Certbot finishes +sed -i "s/\#ssl_certificate/ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf +sed -i "s/\#listen/listen/" /etc/nginx/sites-available/funkwhale.conf + +# Add HTTP to HTTPS redirection in the Nginx configuration +sed -i "11a \ if (\$host = $Domain) {\n return 301 https://\$host\$request_uri;\n }" /etc/nginx/sites-available/funkwhale.conf + +# Restart Nginx to apply the New SSL configuration +zinit stop nginx +zinit start nginx From cd75a6418e6db67cf12fd3a3817e200fa1e7e50e Mon Sep 17 00:00:00 2001 From: PeterNashaat Date: Sun, 18 May 2025 08:44:06 +0000 Subject: [PATCH 2/2] changing port number --- tfgrid3/funkwhale/Dockerfile | 2 +- tfgrid3/funkwhale/scripts/start-fk.sh | 42 +-------------------------- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/tfgrid3/funkwhale/Dockerfile b/tfgrid3/funkwhale/Dockerfile index da651ac0..9e5fb758 100644 --- a/tfgrid3/funkwhale/Dockerfile +++ b/tfgrid3/funkwhale/Dockerfile @@ -44,7 +44,7 @@ RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Expose ports for HTTP access -EXPOSE 5000 +EXPOSE 80 # Command to run Zinit in the container CMD ["/sbin/zinit", "init", "--container"] diff --git a/tfgrid3/funkwhale/scripts/start-fk.sh b/tfgrid3/funkwhale/scripts/start-fk.sh index f1e402d7..785c1916 100644 --- a/tfgrid3/funkwhale/scripts/start-fk.sh +++ b/tfgrid3/funkwhale/scripts/start-fk.sh @@ -24,6 +24,7 @@ sed -i "s#^FUNKWHALE_VERSION=.*#FUNKWHALE_VERSION=$FUNKWHALE_VERSION#" .env sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$domain#" .env sed -i "s#^FUNKWHALE_HOSTNAME=.*#FUNKWHALE_HOSTNAME=$FUNKWHALE_HOSTNAME#" .env sed -i "s#^FUNKWHALE_API_IP=.*#FUNKWHALE_API_IP=0.0.0.0#" .env +sed -i 's/^FUNKWHALE_API_PORT=.*/FUNKWHALE_API_PORT=80/' .env # Pull the latest Docker images for Funkwhale docker-compose pull @@ -53,44 +54,3 @@ echo "$USER_INPUT" | docker-compose run --rm -T api funkwhale-manage fw users cr # Start Funkwhale services docker-compose up -d - -# Check if $Domain is set before proceeding with SSL generation -if [ -z "$Domain" ]; then - echo "No Domain provided. Skipping SSL setup and exiting." - zinit stop nginx - exit 0 -fi - -# Download and apply the Funkwhale Nginx proxy configuration -curl -L -o /etc/nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$FUNKWHALE_VERSION/deploy/funkwhale_proxy.conf" -curl -L -o /etc/nginx/sites-available/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$FUNKWHALE_VERSION/deploy/docker.proxy.template" - -# Apply environment variables to the Nginx template and create the final Nginx configuration -set -a && source /srv/funkwhale/.env && set +a -envsubst "`env | awk -F = '{printf \" $%s\", $$1}'`" < /etc/nginx/sites-available/funkwhale.template > /etc/nginx/sites-available/funkwhale.conf - -# Comment out SSL cert lines temporarily to allow HTTP access before SSL setup -sed -i "s/listen 443 ssl http2\;/#listen 443 ssl http2\;/" /etc/nginx/sites-available/funkwhale.conf -sed -i "s/listen \[::\]:443 ssl http2;/#listen \[::\]:443 ssl http2;/" /etc/nginx/sites-available/funkwhale.conf -sed -i "s/ssl_certificate/\#ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf - -# Enable the Funkwhale Nginx site and create a backup of the current configuration -ln -s /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-enabled/ -cp /etc/nginx/sites-available/funkwhale.conf /etc/nginx/sites-available/funkwhale.conf.bak - -# Generate SSL certificate using Certbot -certbot --nginx -d $Domain --non-interactive --agree-tos --register-unsafely-without-email - -# Restore the original Nginx configuration from the backup -mv /etc/nginx/sites-available/funkwhale.conf.bak /etc/nginx/sites-available/funkwhale.conf - -# Uncomment the SSL lines after Certbot finishes -sed -i "s/\#ssl_certificate/ssl_certificate/" /etc/nginx/sites-available/funkwhale.conf -sed -i "s/\#listen/listen/" /etc/nginx/sites-available/funkwhale.conf - -# Add HTTP to HTTPS redirection in the Nginx configuration -sed -i "11a \ if (\$host = $Domain) {\n return 301 https://\$host\$request_uri;\n }" /etc/nginx/sites-available/funkwhale.conf - -# Restart Nginx to apply the New SSL configuration -zinit stop nginx -zinit start nginx