diff --git a/docker/deployment/Dockerfile b/docker/deployment/Dockerfile index f280e637..321003ea 100644 --- a/docker/deployment/Dockerfile +++ b/docker/deployment/Dockerfile @@ -1,4 +1,4 @@ -# modify time: 202310191733, you can modify here to trigger Docker Build action +# modify time: 2023102400933, you can modify here to trigger Docker Build action # step1: Build entrypoint execute program init_portainer by golang FROM golang:latest AS builder diff --git a/docker/deployment/init_portainer.go b/docker/deployment/init_portainer.go index d8ae36ea..9584dc44 100644 --- a/docker/deployment/init_portainer.go +++ b/docker/deployment/init_portainer.go @@ -12,17 +12,25 @@ import ( func main() { filePath := "/data/credential" + initPath := "/data/init" _, err := os.Stat(filePath) if os.IsNotExist(err) { - fmt.Println("credential is not exist, create it.") - password := generatePassword(16) - err := writeToFile(filePath, password) - if err != nil { - fmt.Println("write file error:", err) - return + _, err := os.Stat(initPath) + + if os.IsNotExist(err) { + fmt.Println("credential is not exist, create it.") + password := generatePassword(16) + err := writeToFile(filePath, password) + if err != nil { + fmt.Println("write file error:", err) + return + } + } else { + fmt.Println("credential is exist, skip it.") } + // call portainer cmd := exec.Command("./portainer", "--admin-password-file", filePath) cmd.Stdout = os.Stdout @@ -32,6 +40,8 @@ func main() { if err != nil { fmt.Println("error running compiled_program:", err) return + }else{ + os.Create(initPath) } }else{ fmt.Println("credential is exist, skip it.") diff --git a/docker/proxy/Dockerfile b/docker/proxy/Dockerfile index 575dc871..046c2b1e 100644 --- a/docker/proxy/Dockerfile +++ b/docker/proxy/Dockerfile @@ -1,4 +1,4 @@ -# modify time: 202310231624, you can modify here to trigger Docker Build action +# modify time: 202310240910, you can modify here to trigger Docker Build action # Dockerfile refer to:https://github.com/NginxProxyManager/nginx-proxy-manager/blob/develop/docker/Dockerfile FROM jc21/nginx-proxy-manager:2.10.4 diff --git a/docker/proxy/s6/init_user/init_user.sh b/docker/proxy/s6/init_user/init_user.sh index 4880ab21..d79bba76 100644 --- a/docker/proxy/s6/init_user/init_user.sh +++ b/docker/proxy/s6/init_user/init_user.sh @@ -5,6 +5,7 @@ username="help@websoft9.com" password=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16) token="" cred_path="/data/credential" +max_attempts=10 echo "Start to change nginxproxymanage users" if [ -e "$cred_path" ]; then @@ -23,7 +24,7 @@ while [ -z "$token" ]; do done echo "Change username(email)" -while true; do +for attempt in $(seq 1 $max_attempts); 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 "Set username successful" @@ -31,11 +32,15 @@ while true; do else echo "Set username failed, retrying..." sleep 5 + if [ $attempt -eq $max_attempts ]; then + echo "Failed to set username after $max_attempts attempts. Exiting." + exit 1 + fi fi done echo "Update password" -while true; do +for attempt in $(seq 1 $max_attempts); 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 "Set password successful" @@ -46,6 +51,10 @@ while true; do else echo "Set password failed, retrying..." sleep 5 + if [ $attempt -eq $max_attempts ]; then + echo "Failed to set password after $max_attempts attempts. Exiting." + exit 1 + fi fi done diff --git a/version.json b/version.json index 2bff9b34..e6396220 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "0.8.26-rc81", + "version": "0.8.26-rc82", "plugins": { "portainer": "0.0.7", "nginx": "0.0.5",