This commit is contained in:
qiaofeng1227 2023-10-24 09:05:28 +08:00
parent 325adc32ed
commit aede9231b7
5 changed files with 30 additions and 11 deletions

View File

@ -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 # step1: Build entrypoint execute program init_portainer by golang
FROM golang:latest AS builder FROM golang:latest AS builder

View File

@ -12,17 +12,25 @@ import (
func main() { func main() {
filePath := "/data/credential" filePath := "/data/credential"
initPath := "/data/init"
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
fmt.Println("credential is not exist, create it.")
password := generatePassword(16)
err := writeToFile(filePath, password) _, err := os.Stat(initPath)
if err != nil {
fmt.Println("write file error:", err) if os.IsNotExist(err) {
return 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 // call portainer
cmd := exec.Command("./portainer", "--admin-password-file", filePath) cmd := exec.Command("./portainer", "--admin-password-file", filePath)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
@ -32,6 +40,8 @@ func main() {
if err != nil { if err != nil {
fmt.Println("error running compiled_program:", err) fmt.Println("error running compiled_program:", err)
return return
}else{
os.Create(initPath)
} }
}else{ }else{
fmt.Println("credential is exist, skip it.") fmt.Println("credential is exist, skip it.")

View File

@ -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 # Dockerfile refer to:https://github.com/NginxProxyManager/nginx-proxy-manager/blob/develop/docker/Dockerfile
FROM jc21/nginx-proxy-manager:2.10.4 FROM jc21/nginx-proxy-manager:2.10.4

View File

@ -5,6 +5,7 @@ username="help@websoft9.com"
password=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16) password=$(openssl rand -base64 16 | tr -d '/+' | cut -c1-16)
token="" token=""
cred_path="/data/credential" cred_path="/data/credential"
max_attempts=10
echo "Start to change nginxproxymanage users" echo "Start to change nginxproxymanage users"
if [ -e "$cred_path" ]; then if [ -e "$cred_path" ]; then
@ -23,7 +24,7 @@ while [ -z "$token" ]; do
done done
echo "Change username(email)" 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) 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 if [ $? -eq 0 ]; then
echo "Set username successful" echo "Set username successful"
@ -31,11 +32,15 @@ while true; do
else else
echo "Set username failed, retrying..." echo "Set username failed, retrying..."
sleep 5 sleep 5
if [ $attempt -eq $max_attempts ]; then
echo "Failed to set username after $max_attempts attempts. Exiting."
exit 1
fi
fi fi
done done
echo "Update password" 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) 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 if [ $? -eq 0 ]; then
echo "Set password successful" echo "Set password successful"
@ -46,6 +51,10 @@ while true; do
else else
echo "Set password failed, retrying..." echo "Set password failed, retrying..."
sleep 5 sleep 5
if [ $attempt -eq $max_attempts ]; then
echo "Failed to set password after $max_attempts attempts. Exiting."
exit 1
fi
fi fi
done done

View File

@ -1,5 +1,5 @@
{ {
"version": "0.8.26-rc81", "version": "0.8.26-rc82",
"plugins": { "plugins": {
"portainer": "0.0.7", "portainer": "0.0.7",
"nginx": "0.0.5", "nginx": "0.0.5",