portainer updatge

This commit is contained in:
qiaofeng1227 2023-09-06 11:47:18 +08:00
parent bdf13191b3
commit 04b3bec8e9
3 changed files with 78 additions and 6 deletions

View File

@ -1,4 +1,4 @@
APP_NAME=websoft9-portainer
APP_VERSION=2.18.3
APP_VERSION=2.19.0
APP_HTTP_PORT=9091
APP_NETWORK=websoft9

View File

@ -1,11 +1,22 @@
version: "3.8"
services:
portainer:
image: portainer/portainer-ce:${APP_VERSION}
container_name: ${APP_NAME}
restart: unless-stopped
env_file: .env
build:
context: .
dockerfile_inline: |
# step1: build entrypoint execute program init_portainer by golang
FROM golang:latest AS builder
WORKDIR /
COPY init_portainer.go /init_portainer.go
RUN go build -o init_portainer init_portainer.go
RUN chmod +x ./init_portainer
# step2: copy build go program to portainer
FROM portainer/portainer-ce:${APP_VERSION}
COPY --from=builder /init_portainer /
entrypoint: ["/init_portainer"]
restart: unless-stopped
volumes:
- portainer:/data
- /var/run/docker.sock:/var/run/docker.sock
@ -18,4 +29,4 @@ networks:
external: true
volumes:
portainer:
portainer:

View File

@ -0,0 +1,61 @@
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"time"
)
func main() {
filePath := "/portainer_password"
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
password := generatePassword(16)
err := writeToFile(filePath, password)
if err != nil {
fmt.Println("write file error:", err)
return
}
}
content, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Println("read file error:", err)
return
}
fmt.Println("-----portainer_admin_user: admin, portainer_admin_password: " + string(content) + " ------")
// call portainer
cmd := exec.Command("./portainer", "--admin-password-file", "/portainer_password")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
fmt.Println("error running compiled_program:", err)
return
}
}
func generatePassword(length int) string {
rand.Seed(time.Now().UnixNano())
charset := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+{}[]:;?.,<>"
password := make([]byte, length)
for i := range password {
password[i] = charset[rand.Intn(len(charset))]
}
return string(password)
}
func writeToFile(filename, content string) error {
return ioutil.WriteFile(filename, []byte(content), 0755)
}