@@ -125,6 +125,7 @@ services:
125125 image : gogs/gogs:0.14
126126 volumes :
127127 - gogs-data:/data
128+ - ./resources/gogs/app.ini:/data/gogs/conf/app.ini
128129 ports :
129130 - " 3002:3000"
130131 healthcheck :
@@ -135,59 +136,41 @@ services:
135136 start_period : 15s
136137
137138 gogs-bootstrap :
138- image : alpine/curl:8.12.1
139+ image : gogs/gogs:0.14
139140 volumes :
140141 - gogs-data:/data
141142 depends_on :
142143 gogs :
143144 condition : service_healthy
145+ entrypoint : /bin/sh
144146 environment :
145147 - GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-utopia}
146148 - GOGS_ADMIN_PASSWORD=${GOGS_ADMIN_PASSWORD:-password}
147149 - GOGS_ADMIN_EMAIL=${GOGS_ADMIN_EMAIL:-utopia@example.com}
148- entrypoint : /bin/sh
149150 command :
150- - -ce
151+ - -c
151152 - |
152- if [ -f /data/gogs/token.txt ]; then exit 0; fi
153-
154- apk add --no-cache jq
155-
156- curl -s -o /dev/null -X POST http://gogs:3000/install \
157- -d db_type=SQLite3 \
158- -d db_path=/data/gogs.db \
159- -d app_name=Gogs \
160- -d repo_root_path=/data/repositories \
161- -d run_user=git \
162- -d domain=gogs \
163- -d http_port=3000 \
164- -d app_url=http://gogs:3000/ \
165- -d log_root_path=/data/gogs/log \
166- -d default_branch=master \
167- -d admin_name=$$GOGS_ADMIN_USERNAME \
168- -d admin_passwd=$$GOGS_ADMIN_PASSWORD \
169- -d admin_confirm_passwd=$$GOGS_ADMIN_PASSWORD \
170- -d admin_email=$$GOGS_ADMIN_EMAIL \
171- || true
153+ USER=git /app/gogs/gogs admin create-user \
154+ --admin \
155+ --name $$GOGS_ADMIN_USERNAME \
156+ --password $$GOGS_ADMIN_PASSWORD \
157+ --email $$GOGS_ADMIN_EMAIL \
158+ --config /data/gogs/conf/app.ini || true
172159
173- sleep 3
174-
175- if ! grep -q '\[webhook\]' /data/gogs/conf/app.ini; then
176- printf '\n[webhook]\nDELIVER_TIMEOUT = 10\nSKIP_TLS_VERIFY = true\n' >> /data/gogs/conf/app.ini
160+ if [ ! -f /data/gogs/token.txt ]; then
161+ sleep 2
162+ TOKEN=$$(curl -s \
163+ -X POST \
164+ -u $$GOGS_ADMIN_USERNAME:$$GOGS_ADMIN_PASSWORD \
165+ -H "Content-Type: application/json" \
166+ -d "{\"name\":\"bootstrap\"}" \
167+ http://gogs:3000/api/v1/users/$$GOGS_ADMIN_USERNAME/tokens \
168+ | grep -o '"sha1":"[^"]*"' | cut -d'"' -f4)
169+ if [ -z "$$TOKEN" ]; then echo "Failed to get token"; exit 1; fi
170+ mkdir -p /data/gogs
171+ echo $$TOKEN > /data/gogs/token.txt
177172 fi
178173
179- RESPONSE=$$(curl -s -X POST http://gogs:3000/api/v1/users/$$GOGS_ADMIN_USERNAME/tokens \
180- -H 'Content-Type: application/json' \
181- -d "{\"name\":\"bootstrap-$$(date +%s)\"}" \
182- -u $$GOGS_ADMIN_USERNAME:$$GOGS_ADMIN_PASSWORD)
183- echo "Token API response: $$RESPONSE"
184-
185- TOKEN=$$(echo "$$RESPONSE" | jq -r '.sha1')
186- if [ -z "$$TOKEN" ] || [ "$$TOKEN" = "null" ]; then echo 'Failed to extract token'; exit 1; fi
187-
188- mkdir -p /data/gogs
189- echo $$TOKEN > /data/gogs/token.txt
190-
191174volumes :
192175 gitea-data :
193176 forgejo-data :
0 commit comments