Skip to content

[docker] Separate various /data/gitea #6652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ RUN addgroup \

ENV USER git
ENV GITEA_CUSTOM /data/gitea
# See docker/etc/s6/gitea/default_env file for configurable env variable

VOLUME ["/data"]

Expand Down
2 changes: 0 additions & 2 deletions docker/etc/profile.d/gitea.sh

This file was deleted.

30 changes: 30 additions & 0 deletions docker/etc/s6/gitea/default_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Define the environment variables
export DATA_PATH=${DATA_PATH:-"/data/gitea"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these hidden in a service file?

Except for the INSTALL_LOCK they can all go into the Dockerfile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I didn't want to cluter the dockerfile but still wanted to have a dedicated file detailing all the env variable possible to use and their default. But it could be in the Dockerfile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment to the Dockerfile to indicate to go see this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the various config options seem to clutter the Dockerfile.

Removing the GITEA_CUSTOM environment variable breaks the ad-hoc commands.

# docker run -d --name gitea_no_env gitea:sapk
# docker exec -it gitea_no_env gitea dump
2019/04/17 13:14:08 ...s/setting/setting.go:501:NewContext() [W] Custom config '/usr/local/bin/custom/conf/app.ini' not found, ignore this if you're running first time
<snip>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why DATA_PATH? APP_DATA_PATH is already a setting in app.ini we should keep name same for same purpose.

export GITEA_CUSTOM=${GITEA_CUSTOM:-"/data/gitea"}
export RUN_DIR=${RUN_DIR:-"/app/gitea"}


# Set INSTALL_LOCK to true only if SECRET_KEY is not empty and
# INSTALL_LOCK is empty
if [ -n "$SECRET_KEY" ] && [ -z "$INSTALL_LOCK" ]; then
INSTALL_LOCK=true
fi

export APP_NAME=${APP_NAME:-"Gitea: Git with a cup of tea"}
export RUN_MODE=${RUN_MODE:-"dev"}
export SSH_DOMAIN=${SSH_DOMAIN:-"localhost"}
export HTTP_PORT=${HTTP_PORT:-"3000"}
export ROOT_URL=${ROOT_URL:-""}
export DISABLE_SSH=${DISABLE_SSH:-"false"}
export SSH_PORT=${SSH_PORT:-"22"}
export DB_TYPE=${DB_TYPE:-"sqlite3"}
export DB_HOST=${DB_HOST:-"localhost:3306"}
export DB_NAME=${DB_NAME:-"gitea"}
export DB_USER=${DB_USER:-"root"}
export DB_PASSWD=${DB_PASSWD:-""}
export INSTALL_LOCK=${INSTALL_LOCK:-"false"}
export DISABLE_REGISTRATION=${DISABLE_REGISTRATION:-"false"}
export REQUIRE_SIGNIN_VIEW=${REQUIRE_SIGNIN_VIEW:-"false"}
export SECRET_KEY=${SECRET_KEY:-""}
3 changes: 2 additions & 1 deletion docker/etc/s6/gitea/run
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
[[ -f ./default_env ]] && source ./default_env
[[ -f ./setup ]] && source ./setup

pushd /app/gitea > /dev/null
pushd "${RUN_DIR}" > /dev/null
exec su-exec $USER /app/gitea/gitea web
popd
37 changes: 8 additions & 29 deletions docker/etc/s6/gitea/setup
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,20 @@ if [ ! -d /data/git/.ssh ]; then
fi

if [ ! -f /data/git/.ssh/environment ]; then
echo "GITEA_CUSTOM=/data/gitea" >| /data/git/.ssh/environment
echo "GITEA_CUSTOM=${GITEA_CUSTOM}" >| /data/git/.ssh/environment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A change of GITEA_CUSTOM will not propagate to the /data/git/.ssh/environment file.

See PR #6608 for a workaround:
https://github.com/go-gitea/gitea/pull/6608/files#diff-e9383835b6feff19b2e8f36745b70414R12

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should wait for your PR to get merged and I will rebased this PR on.

chmod 600 /data/git/.ssh/environment
fi

if [ ! -f /data/gitea/conf/app.ini ]; then
mkdir -p /data/gitea/conf

# Set INSTALL_LOCK to true only if SECRET_KEY is not empty and
# INSTALL_LOCK is empty
if [ -n "$SECRET_KEY" ] && [ -z "$INSTALL_LOCK" ]; then
INSTALL_LOCK=true
fi
if [ ! -f "${GITEA_CUSTOM}/conf/app.ini" ]; then
mkdir -p "${GITEA_CUSTOM}/conf"

# Substitude the environment variables in the template
APP_NAME=${APP_NAME:-"Gitea: Git with a cup of tea"} \
RUN_MODE=${RUN_MODE:-"dev"} \
SSH_DOMAIN=${SSH_DOMAIN:-"localhost"} \
HTTP_PORT=${HTTP_PORT:-"3000"} \
ROOT_URL=${ROOT_URL:-""} \
DISABLE_SSH=${DISABLE_SSH:-"false"} \
SSH_PORT=${SSH_PORT:-"22"} \
DB_TYPE=${DB_TYPE:-"sqlite3"} \
DB_HOST=${DB_HOST:-"localhost:3306"} \
DB_NAME=${DB_NAME:-"gitea"} \
DB_USER=${DB_USER:-"root"} \
DB_PASSWD=${DB_PASSWD:-""} \
INSTALL_LOCK=${INSTALL_LOCK:-"false"} \
DISABLE_REGISTRATION=${DISABLE_REGISTRATION:-"false"} \
REQUIRE_SIGNIN_VIEW=${REQUIRE_SIGNIN_VIEW:-"false"} \
SECRET_KEY=${SECRET_KEY:-""} \
envsubst < /etc/templates/app.ini > /data/gitea/conf/app.ini
envsubst < /etc/templates/app.ini > "${GITEA_CUSTOM}/conf/app.ini"
fi

# only chown if current owner is not already the gitea ${USER}. No recursive check to save time
if ! [[ $(ls -ld /data/gitea | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /data/gitea; fi
if ! [[ $(ls -ld /app/gitea | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /app/gitea; fi
if ! [[ $(ls -ld "${GITEA_CUSTOM}" | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git "${GITEA_CUSTOM}"; fi
if ! [[ $(ls -ld "${DATA_PATH}" | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git "${DATA_PATH}"; fi
if ! [[ $(ls -ld "${RUN_DIR}" | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git "${RUN_DIR}"; fi
if ! [[ $(ls -ld /data/git | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /data/git; fi
chmod 0755 /data/gitea /app/gitea /data/git
chmod 0755 "${GITEA_CUSTOM}" "${DATA_PATH}" "${RUN_DIR}" /data/git
18 changes: 9 additions & 9 deletions docker/etc/templates/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ RUN_MODE = $RUN_MODE
ROOT = /data/git/repositories

[repository.local]
LOCAL_COPY_PATH = /data/gitea/tmp/local-repo
LOCAL_COPY_PATH = $DATA_PATH/tmp/local-repo

[repository.upload]
TEMP_PATH = /data/gitea/uploads
TEMP_PATH = $DATA_PATH/uploads

[server]
APP_DATA_PATH = /data/gitea
APP_DATA_PATH = $DATA_PATH
SSH_DOMAIN = $SSH_DOMAIN
HTTP_PORT = $HTTP_PORT
ROOT_URL = $ROOT_URL
Expand All @@ -20,27 +20,27 @@ SSH_PORT = $SSH_PORT
LFS_CONTENT_PATH = /data/git/lfs

[database]
PATH = /data/gitea/gitea.db
PATH = $DATA_PATH/gitea.db
DB_TYPE = $DB_TYPE
HOST = $DB_HOST
NAME = $DB_NAME
USER = $DB_USER
PASSWD = $DB_PASSWD

[indexer]
ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve
ISSUE_INDEXER_PATH = $DATA_PATH/indexers/issues.bleve

[session]
PROVIDER_CONFIG = /data/gitea/sessions
PROVIDER_CONFIG = $DATA_PATH/sessions

[picture]
AVATAR_UPLOAD_PATH = /data/gitea/avatars
AVATAR_UPLOAD_PATH = $DATA_PATH/avatars

[attachment]
PATH = /data/gitea/attachments
PATH = $DATA_PATH/attachments

[log]
ROOT_PATH = /data/gitea/log
ROOT_PATH = $DATA_PATH/log

[security]
INSTALL_LOCK = $INSTALL_LOCK
Expand Down
2 changes: 1 addition & 1 deletion docker/usr/bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ -n "${USER_UID}" ] && [ "${USER_UID}" != "`id -u ${USER}`" ]; then
sed -i -e "s/^${USER}:\([^:]*\):[0-9]*:\([0-9]*\)/${USER}:\1:${USER_UID}:\2/" /etc/passwd
fi

for FOLDER in /data/gitea/conf /data/gitea/log /data/git /data/ssh; do
for FOLDER in "${GITEA_CUSTOM}/conf" "${DATA_PATH}/log" /data/git /data/ssh; do
mkdir -p ${FOLDER}
done

Expand Down