From 9bb06646889fb3ed16e0059f6eacd11af4109ad1 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 28 Apr 2015 21:57:58 -0700 Subject: [PATCH] Make it work --- Dockerfile | 1 + README.md | 4 ++++ app.ini.template | 51 +++++++++++++++++--------------------------- start.sh | 50 ++++++++++++++++++++++++++++++++++++------- supervisor/gogs.conf | 11 +++++++--- 5 files changed, 74 insertions(+), 43 deletions(-) create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile index 3f1bfe6..2b2a0b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ADD supervisor/ /etc/supervisor/conf.d/ RUN cd /tmp && \ wget https://github.com/gogits/gogs/releases/download/v0.6.1/linux_amd64.zip && \ unzip linux_amd64.zip -d /home/cloudron && \ + chown -R cloudron:cloudron /home/cloudron/gogs && \ rm linux_amd64.zip ADD app.ini.template /home/cloudron/app.ini.template diff --git a/README.md b/README.md new file mode 100644 index 0000000..305e279 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Automated installs +------------------ +https://github.com/gogits/gogs/issues/145#issuecomment-41863670 +https://github.com/geerlingguy/ansible-role-gogs/issues/1 diff --git a/app.ini.template b/app.ini.template index 8215e3d..e329f95 100644 --- a/app.ini.template +++ b/app.ini.template @@ -1,10 +1,15 @@ -; App name that shows on every page title -APP_NAME = Gogs: Go Git Service -; Change it if you run locally RUN_USER = cloudron -; Either "dev", "prod" or "test", default is "dev" RUN_MODE = prod +[database] +DB_TYPE = mysql +HOST = ##MYSQL_HOST:##MYSQL_PORT +NAME = ##MYSQL_DATABASE +USER = ##MYSQL_USERNAME +PASSWD = ##MYSQL_PASSWORD +SSL_MODE = +PATH = + [repository] ROOT = /app/data SCRIPT_TYPE = bash @@ -15,43 +20,25 @@ DOMAIN = ##HOSTNAME ROOT_URL = https://%(DOMAIN)s/ HTTP_ADDR = HTTP_PORT = 3000 -; Disable SSH feature when not available DISABLE_SSH = false SSH_PORT = ##SSH_PORT ; Landing page for non-logged users, can be "home" or "explore" LANDING_PAGE = explore -[database] -; Either "mysql", "postgres" or "sqlite3", it's your choice -DB_TYPE = mysql -HOST = ##MYSQL_HOST:##MYSQL_PORT -NAME = ##MYSQL_DATABASE -USER = ##MYSQL_USERNAME -PASSWD = ##MYSQL_PASSWORD +[mailer] +ENABLED = true +HOST = ##MAIL_SERVER:##MAIL_PORT +USER = +PASSWD = +FROM = ##MAIL_FROM [admin] [security] INSTALL_LOCK = true +SECRET_KEY = ##SECRET_KEY -[mailer] -ENABLED = true -; Name displayed in mail title -SUBJECT = %(APP_NAME)s -; Mail server -; Gmail: smtp.gmail.com:587 -; QQ: smtp.qq.com:25 -; Note, if the port ends with "465", SMTPS will be used. Using STARTTLS on port 587 is recommended per RFC 6409. If the server supports STARTTLS it will always be used. -HOST = ##MAIL_SERVER:##MAIL_PORT -; Do not verify the certificate of the server. Only use this for self-signed certificates -SKIP_VERIFY = -; Use client certificate -USE_CERTIFICATE = false -CERT_FILE = -KEY_FILE = -; Mail from address, RFC 5322. This can be just an email address, or the "Name" format -FROM = ##MAIL_FROM -; Mailer user name and password -USER = -PASSWD = +[service] +DISABLE_REGISTRATION = false +SHOW_REGISTRATION_BUTTON = false diff --git a/start.sh b/start.sh index 5ac6a4f..9ac1af7 100755 --- a/start.sh +++ b/start.sh @@ -4,8 +4,46 @@ set -eu -o pipefail fqdn=$(hostname -f) -mkdir -p /home/cloudron/gogs/custom/conf +chown -R cloudron.cloudron /app/data +# Dockerfile changes the ownership of this file to make it writable by cloudron user +sed -e "s/^Port .*/Port ${SSH_PORT}/" \ + -e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \ + -i /etc/ssh/sshd_config + +/usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs & + +sleep 3 + +if [[ ! -f /home/cloudron/gogs/custom/conf/app.ini ]]; then + echo "Triggering installation" + + mkdir -p /home/cloudron/gogs/custom/conf + touch /home/cloudron/gogs/custom/conf/app.ini + chown cloudron:cloudron /home/cloudron/gogs/custom/conf/app.ini + + # this creates the custom/conf/app.ini + curl -X POST http://localhost:3000/install \ + --data db_type=MySQL \ + --data-urlencode "db_host=${MYSQL_HOST}:${MYSQL_PORT}" \ + --data "db_user=${MYSQL_USERNAME}" \ + --data-urlencode "db_passwd=${MYSQL_PASSWORD}" \ + --data "db_name=${MYSQL_DATABASE}" \ + --data-urlencode "repo_root_path=/tmp" \ + --data run_user=cloudron \ + --data "domain=${fqdn}" \ + --data http_port=3000 \ + --data-urlencode "app_url=https://${fqdn}/" \ + --data "smtp_host=${MAIL_SMTP_SERVER}" \ + --data smtp_user= \ + --data smtp_pwd= \ + --data admin_name=admin \ + --data admin_passwd=admin \ + --data admin_confirm_passwd=admin \ + --data-urlencode admin_email=girish@forwardbias.in +fi + +# use GOGS_CONFIG maybe for this but not very documented sed -e "s/##HOSTNAME/${fqdn}/g" \ -e "s/##SSH_PORT/${SSH_PORT}/g" \ -e "s/##MYSQL_HOST/${MYSQL_HOST}/g" \ @@ -16,14 +54,10 @@ sed -e "s/##HOSTNAME/${fqdn}/g" \ -e "s/##MAIL_SERVER/${MAIL_SMTP_SERVER}/g" \ -e "s/##MAIL_PORT/${MAIL_SMTP_PORT}/g" \ -e "s/##MAIL_FROM/${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}/g" \ + -e "s/##SECRET_KEY/$(pwgen -1 -s)/g" \ /home/cloudron/app.ini.template > "/home/cloudron/gogs/custom/conf/app.ini" -chown -R cloudron.cloudron /app/data +supervisorctl restart gogs -# Dockerfile changes the ownership of this file to make it writable by cloudron user -sed -e "s/^Port .*/Port ${SSH_PORT}/" \ - -e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \ - -i /etc/ssh/sshd_config - -/usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs +wait diff --git a/supervisor/gogs.conf b/supervisor/gogs.conf index 40ff1de..543ff3d 100644 --- a/supervisor/gogs.conf +++ b/supervisor/gogs.conf @@ -4,6 +4,11 @@ command=/home/cloudron/gogs/gogs web user=cloudron autostart=true autorestart=true -stdout_logfile=/var/log/supervisor/%(program_name)s.log -stderr_logfile=/var/log/supervisor/%(program_name)s.log -environment=USER="cloudron" +; https://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +; stdout_logfile=/var/log/supervisor/%(program_name)s.log +; stderr_logfile=/var/log/supervisor/%(program_name)s.log +environment=HOME="/home/cloudron",USER="cloudron"