diff --git a/deploy.sh b/deploy.sh index bb27655..dc67183 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,24 +4,27 @@ APP_NAME=s464951-gitea WEB_URL=$(heroku create --stack container --region eu $APP_NAME --json | jq -r '.web_url') -echo $WEB_URL +echo $WEB_URL > heroku-app.txt # Add Heroku Postgres add-on heroku addons:create heroku-postgresql:essential-0 --app $APP_NAME -while true; do - ADDON_STATUS=$(heroku addons:info heroku-postgresql --app $APP_NAME | grep 'State:' | awk '{print $2}') - echo "Postgres add-on state: $ADDON_STATUS" +#while true; do +# ADDON_STATUS=$(heroku addons:info heroku-postgresql --app $APP_NAME | grep 'State:' | awk '{print $2}') +# echo "Postgres add-on state: $ADDON_STATUS" +# +# if [ "$ADDON_STATUS" == "created" ]; then +# echo "Heroku Postgres add-on is ready!" +# break +# fi +# +# echo "Waiting for Postgres add-on to be ready..." +# sleep 5 +#done - if [ "$ADDON_STATUS" == "created" ]; then - echo "Heroku Postgres add-on is ready!" - break - fi - - echo "Waiting for Postgres add-on to be ready..." - sleep 5 -done +echo "Waiting for Heroku Postgres to be fully provisioned..." +heroku pg:wait --app $APP_NAME echo $DATABASE_URL # Push to Heroku diff --git a/heroku-app.txt b/heroku-app.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/heroku-app.txt @@ -0,0 +1 @@ + diff --git a/run.sh b/run.sh index 5cce56d..bfbb2e4 100644 --- a/run.sh +++ b/run.sh @@ -1,27 +1,32 @@ #!/bin/bash -echo APP_URL: -echo $APP_URL -echo DATABASE_URL: -echo $DATABASE_URL +# Database type +DB_TYPE=postgres -HOST=`echo $DATABASE_URL | grep -o "@.*/" | sed 's/.$//' | cut -c 2-` -NAME=`echo $DATABASE_URL | grep -o "/[[:alnum:]]*$" | cut -c 2-` -USER=`echo $DATABASE_URL | grep -o "//[[:alnum:]]*:" | grep -o "[[:alnum:]]*"` -PASSWD=`echo $DATABASE_URL | grep -o ":[[:alnum:]]*@" | grep -o "[[:alnum:]]*"` +# SSL mode +SSL_MODE=require +# Extract database credentials from DATABASE_URL +if [[ $DATABASE_URL =~ ^postgres://([^:]*):([^@]*)@([^:]*):([0-9]+)/([^/]*)$ ]]; then + USER="${BASH_REMATCH[1]}" + PASSWD="${BASH_REMATCH[2]}" + HOST="${BASH_REMATCH[3]}:${BASH_REMATCH[4]}" + NAME="${BASH_REMATCH[5]}" +else + echo "Invalid DATABASE_URL: $DATABASE_URL" + exit 1 +fi + +# Get app url +FILE=/app/heroku-app.txt +ROOT_URL=$(cat $FILE) + +# Custom configuration mkdir -p /var/lib/gitea/custom/conf -echo "[server]" > /var/lib/gitea/custom/conf/app.ini -echo "ROOT_URL = $APP_URL" >> /var/lib/gitea/custom/conf/app.ini +# Add custom configuration +printf "[server]\nROOT_URL = $ROOT_URL\n" > /var/lib/gitea/custom/conf/app.ini +printf "[database]\nDB_TYPE = $DB_TYPE\nHOST = $HOST\nNAME = $NAME\nUSER = $USER\nPASSWD = $PASSWD\nSSL_MODE = $SSL_MODE\n" >> /var/lib/gitea/custom/conf/app.ini -echo "[database]" >> /var/lib/gitea/custom/conf/app.ini -echo "DB_TYPE = postgres" >> /var/lib/gitea/custom/conf/app.ini -echo "HOST = $HOST" >> /var/lib/gitea/custom/conf/app.ini -echo "NAME = $NAME" >> /var/lib/gitea/custom/conf/app.ini -echo "USER = $USER" >> /var/lib/gitea/custom/conf/app.ini -echo "PASSWD = $PASSWD" >> /var/lib/gitea/custom/conf/app.ini -echo "SSL_MODE = require" >> /var/lib/gitea/custom/conf/app.ini - -cat /var/lib/gitea/custom/conf/app.ini -/usr/local/bin/gitea web --port $PORT \ No newline at end of file +# Start Gitea +/usr/local/bin/gitea web -port $PORT \ No newline at end of file