Go for the postdeploy.sh approach

This commit is contained in:
Luke Murphy 2020-03-12 15:01:36 +01:00
parent 88ac6e9526
commit 4c8fe79dbe
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 49 additions and 1 deletions

View File

@ -2,4 +2,7 @@ FROM gitea/gitea:1.11.2
COPY . ${WORKDIR}
RUN mkdir -p /app/
COPY postdeploy.sh /app/
EXPOSE 80:3000

View File

@ -1,5 +1,6 @@
{
"name": "gitea",
"description": "Gitea is a painless self-hosted Git service.",
"repository": "https://gitlab.com/autonomic-cooperative/gitea-dokku"
"repository": "https://gitlab.com/autonomic-cooperative/gitea-dokku",
"scripts": { "dokku": { "postdeploy": "bash /app/postdeploy.sh" } }
}

44
postdeploy.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
set -eu -o pipefail
setup_root_user() {
set -eu
# TODO(decentral1se): fix to use sqlite3 database for now
user_count=$(mysql -u"${DB_USER}" -p"${DB_PASS}" -h mysql --database="${DB_NAME}" -N -B -e "SELECT count(*) FROM user;")
if [[ "${user_count}" == "0" ]]; then
echo "==> Setting up root user for first run"
if gitea create-admin --name "$ADMIN_USER" --password "$ADMIN_PASS" --email "$ADMIN_MAIL"; then
echo "==> root user added"
else
echo "==> Failed to add root user"
exit 1
fi
fi
}
do_healthcheck() {
set -eu
echo "==> Running Gitea healthcheck"
while ! curl --fail "https://${DOMAIN}/healthcheck"; do
echo "==> Waiting for Gitea to come up"
sleep 1
done
echo "==> Gitea is up"
}
main() {
set -eu
do_healthcheck
setup_root_user
}
# TODO(decentral1se): test manually for now...
# main