From 09592c6cda27cb7638cb556e191b74fb46b6f0e4 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 13 Oct 2015 15:27:09 -0700 Subject: [PATCH] make it work with readonly rootfs --- Dockerfile | 10 +++++++++- app.ini.template | 6 ++++++ start.sh | 39 +++++++++++++++++---------------------- supervisor/gogs.conf | 4 +--- supervisor/sshd.conf | 7 +++++-- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8c68b97..b24b03e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cloudron/base:0.4.0 +FROM cloudron/base:0.6.0 RUN apt-get update && \ apt-get install -y openssh-server && \ @@ -6,6 +6,8 @@ RUN apt-get update && \ ADD supervisor/ /etc/supervisor/conf.d/ +ENV GOROOT /usr/local/go-1.5.1 +ENV PATH $GOROOT/bin:$PATH ENV GOPATH /home/cloudron/gows RUN mkdir -p /home/cloudron/gows /home/cloudron/gogs ## TODO: use redis as well @@ -22,7 +24,13 @@ RUN mkdir -p ${GOPATH}/src/github.com/gogits && \ cp -r ${GOPATH}/src/github.com/gogits/gogs/public/ /home/cloudron/gogs/. && \ rm -rf ${GOPATH} +# setup config paths ADD app.ini.template /home/cloudron/app.ini.template +RUN mkdir -p /run/gogs && chown -R cloudron:cloudron /run/gogs + +# setup log paths +RUN mkdir -p /var/log/gogs && chown -R cloudron:cloudron /var/log/gogs + ADD start.sh /home/cloudron/start.sh # disable pam authentication for sshd diff --git a/app.ini.template b/app.ini.template index c3cf510..b9f580e 100644 --- a/app.ini.template +++ b/app.ini.template @@ -43,3 +43,9 @@ SECRET_KEY = ##SECRET_KEY DISABLE_REGISTRATION = false SHOW_REGISTRATION_BUTTON = false ENABLE_NOTIFY_MAIL = true + +[log] +; Either "console", "file", "conn", "smtp" or "database", default is "console" +MODE = console +; used for xorm.log +ROOT_PATH = /var/log/gogs diff --git a/start.sh b/start.sh index de78188..4424922 100755 --- a/start.sh +++ b/start.sh @@ -2,20 +2,23 @@ set -eu -o pipefail -fqdn=$(hostname -f) +readonly fqdn=$(hostname -f) -chown -R cloudron.cloudron /app/data +setup_ldap_source() { + # Wait for gogs to finish db setup, before we insert ldap source in db + while ! curl --fail http://localhost:3000/healthcheck; do + echo "Waiting for gogs to come up" + sleep 1 + done -# clean up old logs -rm -rf /home/cloudron/gogs/log && mkdir -p /home/cloudron/gogs/log -chown cloudron:cloudron /home/cloudron/gogs/log + # id, type, name, is_actived, cfg, allow_auto_register, created, updated + mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \ + -e "REPLACE INTO login_source VALUES (1,2,'cloudron',1,'{\"Name\":\"cloudron\",\"Host\":\"${LDAP_SERVER}\",\"Port\":${LDAP_PORT},\"UseSSL\":false,\"UserBase\":\"${LDAP_USERS_BASE_DN}\",\"AttributeUsername\":\"uid\",\"AttributeName\":\"\",\"AttributeSurname\":\"\",\"AttributeMail\":\"mail\",\"Filter\":\"(\\\\u0026(objectClass=user)(uid=%s))\",\"AdminFilter\":\"(memberof=cn=admins,${LDAP_GROUPS_BASE_DN})\",\"Enabled\":true}',1,'2015-06-24 17:14:12','2015-06-24 17:25:03');" +} -# 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 - -mkdir -p /home/cloudron/gogs/custom/conf + /etc/ssh/sshd_config > /run/gogs/sshd_config sed -e "s/##HOSTNAME/${fqdn}/g" \ -e "s/##SSH_PORT/${SSH_PORT}/g" \ @@ -28,21 +31,13 @@ sed -e "s/##HOSTNAME/${fqdn}/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" + /home/cloudron/app.ini.template > "/run/gogs/app.ini" -chown cloudron:cloudron /home/cloudron/gogs/custom/conf/app.ini +chown cloudron:cloudron /run/gogs -/usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs & +chown -R cloudron.cloudron /app/data -# Wait for gogs to finish db setup, before we insert ldap source in db -while ! curl --fail http://localhost:3000/healthcheck; do - echo "Waiting for gogs to come up" - sleep 1 -done +( setup_ldap_source ) & -# id, type, name, is_actived, cfg, allow_auto_register, created, updated -mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \ - -e "REPLACE INTO login_source VALUES (1,2,'cloudron',1,'{\"Name\":\"cloudron\",\"Host\":\"${LDAP_SERVER}\",\"Port\":${LDAP_PORT},\"UseSSL\":false,\"UserBase\":\"${LDAP_USERS_BASE_DN}\",\"AttributeUsername\":\"uid\",\"AttributeName\":\"\",\"AttributeSurname\":\"\",\"AttributeMail\":\"mail\",\"Filter\":\"(\\\\u0026(objectClass=user)(uid=%s))\",\"AdminFilter\":\"(memberof=cn=admins,${LDAP_GROUPS_BASE_DN})\",\"Enabled\":true}',1,'2015-06-24 17:14:12','2015-06-24 17:25:03');" - -wait +exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs diff --git a/supervisor/gogs.conf b/supervisor/gogs.conf index 543ff3d..3155266 100644 --- a/supervisor/gogs.conf +++ b/supervisor/gogs.conf @@ -1,6 +1,6 @@ [program:gogs] directory=/home/cloudron/gogs -command=/home/cloudron/gogs/gogs web +command=/home/cloudron/gogs/gogs web -c /run/gogs/app.ini -p 3000 user=cloudron autostart=true autorestart=true @@ -9,6 +9,4 @@ 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" diff --git a/supervisor/sshd.conf b/supervisor/sshd.conf index 84d4761..b738f17 100644 --- a/supervisor/sshd.conf +++ b/supervisor/sshd.conf @@ -4,5 +4,8 @@ command=/usr/sbin/sshd -D user=root autostart=true autorestart=true -stdout_logfile=/var/log/supervisor/%(program_name)s.log -stderr_logfile=/var/log/supervisor/%(program_name)s.log +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +