From 07333806fc7b38f744b50b901fe89cb648527767 Mon Sep 17 00:00:00 2001 From: asmigiel Date: Tue, 7 Jan 2025 20:06:44 +0100 Subject: [PATCH] Deploy to Heroku --- Dockerfile | 28 ++++++------------------ conf/app.ini | 0 deploy.sh | 20 +++++++++++++++++ heroku.yml | 19 ++-------------- run.sh | 62 +++++++++++++++++++--------------------------------- 5 files changed, 51 insertions(+), 78 deletions(-) delete mode 100644 conf/app.ini create mode 100755 deploy.sh diff --git a/Dockerfile b/Dockerfile index 78d1e9b..878306b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,11 @@ -FROM gitea/gitea:1.14.5-rootless -ARG DATABASE_URL -ENV DATABASE_URL=${DATABASE_URL} -COPY --chown=root:root run.sh /usr/local/bin/ -ADD conf/ /var/lib/gitea/custom/conf/ -USER root -RUN chmod 755 /usr/local/bin/run.sh -RUN chmod a+rwx /var/lib/gitea/custom/conf/app.ini +FROM gitea/gitea:1.14.5 -USER 1000:1000 +WORKDIR /app -CMD ["/usr/local/bin/run.sh"] +COPY run.sh ./ +# ENV GITEA_CUSTOM=/var/lib/gitea/custom -#FROM gitea/gitea:1.14.5 -# -#WORKDIR /app -# -#COPY run.sh ./ -# -#ENV GITEA_CUSTOM=/var/lib/gitea/custom -# -#RUN chmod +x ./run.sh -# -#ENTRYPOINT ["./run.sh"] +RUN chmod +x ./run.sh + +ENTRYPOINT ["./run.sh"] diff --git a/conf/app.ini b/conf/app.ini deleted file mode 100644 index e69de29..0000000 diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..a4ade73 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# App name +APP_NAME=s464951-gitea + +WEB_URL=$(heroku create --stack container --region eu $APP_NAME --json | jq -r '.web_url') +echo $WEB_URL + +# Add Heroku Postgres add-on +heroku addons:create heroku-postgresql:essential-0 --app $APP_NAME + +echo echo $DATABASE_URL +# Push to Heroku +heroku git:remote --app $APP_NAME +git add . +git commit -m "Deploy to Heroku" +git push heroku main + +# Open the app in the browser +heroku open --app $APP_NAME \ No newline at end of file diff --git a/heroku.yml b/heroku.yml index 8382201..3315a0f 100644 --- a/heroku.yml +++ b/heroku.yml @@ -1,23 +1,8 @@ setup: addons: - - plan: heroku-postgresql:standard-0 + - plan: heroku-postgresql as: DATABASE + build: docker: web: Dockerfile -run: - web: /usr/local/bin/run.sh - - -#setup: -# addons: -# - plan: heroku-postgresql -# as: DATABASE -## config: -## POSTGRES_USER: "gitea" -## POSTGRES_PASSWORD: "gitea" -## POSTGRES_DB: "gitea" -# -#build: -# docker: -# web: Dockerfile diff --git a/run.sh b/run.sh index 851c394..5cce56d 100644 --- a/run.sh +++ b/run.sh @@ -1,45 +1,27 @@ +#!/bin/bash + +echo APP_URL: +echo $APP_URL +echo DATABASE_URL: +echo $DATABASE_URL + 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:]]*"` -printf "[server]\nHTTP_PORT = $PORT;\n" > /var/lib/gitea/custom/conf/app.ini -printf "DOMAIN = $HEROKU_APP_DEFAULT_DOMAIN_NAME\n" >> /var/lib/gitea/custom/conf/app.ini -printf "\n[database]\nDB_TYPE = postgres;\n" >> /var/lib/gitea/custom/conf/app.ini -printf "NAME = $NAME;\n" >> /var/lib/gitea/custom/conf/app.ini -printf "HOST = $HOST;\n" >> /var/lib/gitea/custom/conf/app.ini -printf "USER = $USER;\n" >> /var/lib/gitea/custom/conf/app.ini -printf "PASSWD = $PASSWD;\n" >> /var/lib/gitea/custom/conf/app.ini -printf "SSL_MODE=require ;\n" >> /var/lib/gitea/custom/conf/app.ini + +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 + +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 - - - -##!/bin/bash -# -# -# -#echo $APP_URL -#echo DATABASE_URL -#echo $DATABASE_URL -# -#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:]]*"` -# -#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 -# -#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 +/usr/local/bin/gitea web --port $PORT \ No newline at end of file