mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Add environment variable support for Docker image (#2201)
* Add `gettext` dependencies as we need `envsubst` command; * Modified s6's gitea setup script, instead of `cp` the template if no `app.ini` exist, it will substitude the envvars and generate the new `app.ini`; * Make `/docker/etc/templates/app.ini` a template contains environment variables; Signed-off-by: Tao Wang <twang2218@gmail.com>
This commit is contained in:
		@@ -14,6 +14,7 @@ RUN apk --no-cache add \
 | 
				
			|||||||
    s6 \
 | 
					    s6 \
 | 
				
			||||||
    curl \
 | 
					    curl \
 | 
				
			||||||
    openssh \
 | 
					    openssh \
 | 
				
			||||||
 | 
					    gettext \
 | 
				
			||||||
    tzdata
 | 
					    tzdata
 | 
				
			||||||
RUN addgroup \
 | 
					RUN addgroup \
 | 
				
			||||||
    -S -g 1000 \
 | 
					    -S -g 1000 \
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ RUN apk --no-cache add \
 | 
				
			|||||||
    s6 \
 | 
					    s6 \
 | 
				
			||||||
    curl \
 | 
					    curl \
 | 
				
			||||||
    openssh \
 | 
					    openssh \
 | 
				
			||||||
 | 
					    gettext \
 | 
				
			||||||
    tzdata
 | 
					    tzdata
 | 
				
			||||||
RUN addgroup \
 | 
					RUN addgroup \
 | 
				
			||||||
    -S -g 1000 \
 | 
					    -S -g 1000 \
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ RUN apk --no-cache add \
 | 
				
			|||||||
    s6 \
 | 
					    s6 \
 | 
				
			||||||
    curl \
 | 
					    curl \
 | 
				
			||||||
    openssh \
 | 
					    openssh \
 | 
				
			||||||
 | 
					    gettext \
 | 
				
			||||||
    tzdata
 | 
					    tzdata
 | 
				
			||||||
RUN addgroup \
 | 
					RUN addgroup \
 | 
				
			||||||
    -S -g 1000 \
 | 
					    -S -g 1000 \
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,29 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if [ ! -f /data/gitea/conf/app.ini ]; then
 | 
					if [ ! -f /data/gitea/conf/app.ini ]; then
 | 
				
			||||||
    mkdir -p /data/gitea/conf
 | 
					    mkdir -p /data/gitea/conf
 | 
				
			||||||
    cp /etc/templates/app.ini /data/gitea/conf/app.ini
 | 
					
 | 
				
			||||||
 | 
					    # 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Substitude the environment variables in the template
 | 
				
			||||||
 | 
					    APP_NAME=${APP_NAME:-"Gitea: Git with a cup of tea"} \
 | 
				
			||||||
 | 
					    APP_MODE=${APP_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"} \
 | 
				
			||||||
 | 
					    SECRET_KEY=${SECRET_KEY:-""} \
 | 
				
			||||||
 | 
					    envsubst < /etc/templates/app.ini > /data/gitea/conf/app.ini
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
chown -R git:git /data/gitea /app/gitea /data/git
 | 
					chown -R git:git /data/gitea /app/gitea /data/git
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
[repository]
 | 
					[repository]
 | 
				
			||||||
 | 
					APP_NAME = $APP_NAME
 | 
				
			||||||
 | 
					APP_MODE = $APP_MODE
 | 
				
			||||||
ROOT = /data/git/repositories
 | 
					ROOT = /data/git/repositories
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[repository.upload]
 | 
					[repository.upload]
 | 
				
			||||||
@@ -6,10 +8,19 @@ TEMP_PATH = /data/gitea/uploads
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[server]
 | 
					[server]
 | 
				
			||||||
APP_DATA_PATH = /data/gitea
 | 
					APP_DATA_PATH = /data/gitea
 | 
				
			||||||
 | 
					SSH_DOMAIN       = $SSH_DOMAIN
 | 
				
			||||||
 | 
					HTTP_PORT        = $HTTP_PORT
 | 
				
			||||||
 | 
					ROOT_URL         = $ROOT_URL
 | 
				
			||||||
 | 
					DISABLE_SSH      = $DISABLE_SSH
 | 
				
			||||||
 | 
					SSH_PORT         = $SSH_PORT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[database]
 | 
					[database]
 | 
				
			||||||
DB_TYPE = sqlite3
 | 
					 | 
				
			||||||
PATH = /data/gitea/gitea.db
 | 
					PATH = /data/gitea/gitea.db
 | 
				
			||||||
 | 
					DB_TYPE = $DB_TYPE
 | 
				
			||||||
 | 
					HOST    = $DB_HOST
 | 
				
			||||||
 | 
					NAME    = $DB_NAME
 | 
				
			||||||
 | 
					USER    = $DB_USER
 | 
				
			||||||
 | 
					PASSWD  = $DB_PASSWD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[session]
 | 
					[session]
 | 
				
			||||||
PROVIDER_CONFIG = /data/gitea/sessions
 | 
					PROVIDER_CONFIG = /data/gitea/sessions
 | 
				
			||||||
@@ -22,3 +33,7 @@ PATH = /data/gitea/attachments
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[log]
 | 
					[log]
 | 
				
			||||||
ROOT_PATH = /data/gitea/log
 | 
					ROOT_PATH = /data/gitea/log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[security]
 | 
				
			||||||
 | 
					INSTALL_LOCK = $INSTALL_LOCK
 | 
				
			||||||
 | 
					SECRET_KEY   = $SECRET_KEY
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user