From 62b07630b7ad22b62a0e2c0f06facb9049292498 Mon Sep 17 00:00:00 2001 From: asmigiel Date: Tue, 7 Jan 2025 21:12:07 +0100 Subject: [PATCH] Deploy to Heroku --- Dockerfile | 1 - app_url.txt | 1 + deploy.sh | 22 ++++------------------ run.sh | 45 ++++++++++++++++++++------------------------- 4 files changed, 25 insertions(+), 44 deletions(-) create mode 100644 app_url.txt diff --git a/Dockerfile b/Dockerfile index 878306b..cc24add 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,6 @@ WORKDIR /app COPY run.sh ./ -# ENV GITEA_CUSTOM=/var/lib/gitea/custom RUN chmod +x ./run.sh diff --git a/app_url.txt b/app_url.txt new file mode 100644 index 0000000..ce1fb77 --- /dev/null +++ b/app_url.txt @@ -0,0 +1 @@ +https://s464951-gitea-451bd4d0ed7a.herokuapp.com/ diff --git a/deploy.sh b/deploy.sh index dc67183..cb26757 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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 . diff --git a/run.sh b/run.sh index bfbb2e4..5cce56d 100644 --- a/run.sh +++ b/run.sh @@ -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 \ No newline at end of file +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