diff --git a/apphub/src/media.py b/apphub/src/media.py new file mode 100644 index 00000000..34bb8945 --- /dev/null +++ b/apphub/src/media.py @@ -0,0 +1,5 @@ +from starlette.applications import Starlette +from starlette.staticfiles import StaticFiles + +app = Starlette() +app.mount("/images", StaticFiles(directory="/websoft9/media"), name="images") \ No newline at end of file diff --git a/docker/apphub/Dockerfile b/docker/apphub/Dockerfile index d87922ca..c9751c7b 100644 --- a/docker/apphub/Dockerfile +++ b/docker/apphub/Dockerfile @@ -1,4 +1,4 @@ -# modify time: 202310230550, you can modify here to trigger Docker Build action +# modify time: 202310231530, you can modify here to trigger Docker Build action FROM python:3.10-bullseye AS buildstage LABEL maintainer="Websoft9" diff --git a/docker/apphub/config/developer.sh b/docker/apphub/config/developer.sh index 60dcbd7f..808e4c0c 100644 --- a/docker/apphub/config/developer.sh +++ b/docker/apphub/config/developer.sh @@ -6,6 +6,7 @@ echo "Start to cp source code" if [ ! "$(ls -A $source_path)" ]; then cp -r /websoft9/apphub/* $source_path fi +cp -r /websoft9/apphub/swagger-ui $source_path echo "Install apphub cli" pip uninstall apphub -y diff --git a/docker/apphub/config/entrypoint.sh b/docker/apphub/config/entrypoint.sh index 7cad001b..ff4ef6ca 100644 --- a/docker/apphub/config/entrypoint.sh +++ b/docker/apphub/config/entrypoint.sh @@ -8,7 +8,6 @@ set -e try_times=5 -# TODO start by supervisord on frontground(/usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf) supervisord supervisorctl start apphub @@ -42,4 +41,20 @@ else exit 1 fi +create_apikey() { + # 容器第一次启动时,不管apikey是否为空,调用apphub genkey + if [ ! -f /websoft9/first_run ]; then + echo "Create new apikey" + apphub genkey + touch /websoft9/first_run + fi + # apphub getkey 为空时,创建新的apikey + if [ -z "$(apphub getkey)" ]; then + echo "Create new apikey" + apphub genkey + fi +} + +create_apikey + tail -f /var/log/supervisord.log \ No newline at end of file diff --git a/docker/apphub/config/supervisord.conf b/docker/apphub/config/supervisord.conf index d32c6be0..9235054d 100644 --- a/docker/apphub/config/supervisord.conf +++ b/docker/apphub/config/supervisord.conf @@ -23,4 +23,14 @@ user=root stdout_logfile=/var/log/supervisord.log stdout_logfile_maxbytes=0 stderr_logfile=/var/log/supervisord.log +stderr_logfile_maxbytes=0 + +[program:media] +command=uvicorn src.media:app --host 0.0.0.0 --port 8081 +autostart=true +user=root +directory=/websoft9/apphub +stdout_logfile=/var/log/supervisord.log +stdout_logfile_maxbytes=0 +stderr_logfile=/var/log/supervisord.log stderr_logfile_maxbytes=0 \ No newline at end of file diff --git a/docker/git/src/s6/user/setup b/docker/git/src/s6/user/setup index 9ce44dbe..34006c23 100644 --- a/docker/git/src/s6/user/setup +++ b/docker/git/src/s6/user/setup @@ -8,6 +8,7 @@ response="" cred_path="/data/gitea/credential" admin_username="websoft9" admin_email="help@websoft9.com" +user_exist=0 while [ "$response" != "200" ]; do response=$(curl -s -o /dev/null -w "%{http_code}" localhost:3000) @@ -34,17 +35,20 @@ su -c " exit 0 else gitea admin user create --admin --username '$admin_username' --random-password --email '$admin_email' > /tmp/credential + user_exist=1 fi " git -echo "Read credential from tmp" -username=$(grep -o "New user '[^']*" /tmp/credential | sed "s/New user '//") -if [ -z "$username" ] || [ "$username" != "websoft9" ]; then - echo "username is not websoft9, exit" -fi -password=$(grep -o "generated random password is '[^']*" /tmp/credential | sed "s/generated random password is '//") -rm -rf /tmp/credential +if [ "$user_exist" -eq 1 ]; then + echo "Read credential from tmp" + username=$(grep -o "New user '[^']*" /tmp/credential | sed "s/New user '//") + if [ -z "$username" ] || [ "$username" != "websoft9" ]; then + echo "username is not websoft9, exit" + fi + password=$(grep -o "generated random password is '[^']*" /tmp/credential | sed "s/generated random password is '//") + rm -rf /tmp/credential -echo "Save to credential" -json="{\"username\":\"$admin_username\",\"password\":\"$password\",\"email\":\"$admin_email\"}" -echo "$json" > "$cred_path" + echo "Save to credential" + json="{\"username\":\"$admin_username\",\"password\":\"$password\",\"email\":\"$admin_email\"}" + echo "$json" > "$cred_path" +fi diff --git a/docker/proxy/s6/init_user/init_user.sh b/docker/proxy/s6/init_user/init_user.sh index 57817877..4880ab21 100644 --- a/docker/proxy/s6/init_user/init_user.sh +++ b/docker/proxy/s6/init_user/init_user.sh @@ -26,10 +26,10 @@ echo "Change username(email)" while true; do response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"email": "'$username'", "nickname": "admin", "is_disabled": false, "roles": ["admin"]}' http://localhost:81/api/users/1) if [ $? -eq 0 ]; then - echo "HTTP call successful" + echo "Set username successful" break else - echo "HTTP call Change username failed, retrying..." + echo "Set username failed, retrying..." sleep 5 fi done @@ -38,15 +38,15 @@ echo "Update password" while true; do response=$(curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"type":"password","current":"changeme","secret":"'$password'"}' http://localhost:81/api/users/1/auth) if [ $? -eq 0 ]; then - echo "HTTP call successful" + echo "Set password successful" + echo "Save to credential" + json="{\"username\":\"$username\",\"password\":\"$password\"}" + echo "$json" > "$cred_path" break else - echo "HTTP call Update password failed, retrying..." + echo "Set password failed, retrying..." sleep 5 fi done -echo "Save to credential" -json="{\"username\":\"$username\",\"password\":\"$password\"}" -echo "$json" > "$cred_path" set -e \ No newline at end of file diff --git a/version.json b/version.json index 86a7e1df..2bff9b34 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "0.8.26-rc80", + "version": "0.8.26-rc81", "plugins": { "portainer": "0.0.7", "nginx": "0.0.5",