Deploy to Heroku

This commit is contained in:
asmigiel 2025-01-07 20:35:59 +01:00
parent 251d503358
commit f0e4ac1948
3 changed files with 41 additions and 32 deletions

View File

@ -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

1
heroku-app.txt Normal file
View File

@ -0,0 +1 @@

45
run.sh
View File

@ -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
# Start Gitea
/usr/local/bin/gitea web -port $PORT