Deploy to Heroku

This commit is contained in:
asmigiel 2025-01-07 21:12:07 +01:00
parent f0e4ac1948
commit 62b07630b7
4 changed files with 25 additions and 44 deletions

View File

@ -4,7 +4,6 @@ WORKDIR /app
COPY run.sh ./
# ENV GITEA_CUSTOM=/var/lib/gitea/custom
RUN chmod +x ./run.sh

1
app_url.txt Normal file
View File

@ -0,0 +1 @@
https://s464951-gitea-451bd4d0ed7a.herokuapp.com/

View File

@ -3,30 +3,16 @@
# App name
APP_NAME=s464951-gitea
WEB_URL=$(heroku create --stack container --region eu $APP_NAME --json | jq -r '.web_url')
echo $WEB_URL > heroku-app.txt
heroku create --stack container --region eu $APP_NAME --json
APP_URL=$(heroku info -s | grep web_url | cut -d= -f2)
echo $APP_URL > app_url.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"
#
# 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
heroku git:remote --app $APP_NAME
git add .

45
run.sh
View File

@ -1,32 +1,27 @@
#!/bin/bash
# Database type
DB_TYPE=postgres
echo APP_URL:
echo $APP_URL
echo DATABASE_URL:
echo $DATABASE_URL
# SSL mode
SSL_MODE=require
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:]]*"`
# 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
# 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 "[server]" > /var/lib/gitea/custom/conf/app.ini
echo "ROOT_URL = $APP_URL" >> /var/lib/gitea/custom/conf/app.ini
# Start Gitea
/usr/local/bin/gitea web -port $PORT
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