diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deployment.yml similarity index 79% rename from .github/workflows/build_deploy.yml rename to .github/workflows/build_deployment.yml index c97586d5..d56e45ff 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deployment.yml @@ -4,7 +4,7 @@ on: push: branches: [main] paths: - - "docker/w9deploy/Dockerfile" + - "docker/w9deployment/Dockerfile" jobs: build: @@ -18,7 +18,7 @@ jobs: - name: Get version run: | - version=$(grep -Po '(?<=LABEL version=").*?(?=")' docker/w9deploy/Dockerfile) + version=$(grep -Po '(?<=LABEL version=").*?(?=")' docker/w9deployment/Dockerfile) echo $version echo "::set-output name=version::$version" echo "VERSION=$version" >> $GITHUB_ENV @@ -26,11 +26,11 @@ jobs: - uses: mr-smithers-excellent/docker-build-push@v5 name: Build & push Docker image with: - image: websoft9dev/deploy + image: websoft9dev/deployment tags: ${{ env.VERSION }} addLatest: True registry: docker.io - dockerfile: docker/w9deploy/Dockerfile - directory: docker/w9deploy + dockerfile: docker/w9deployment/Dockerfile + directory: docker/w9deployment username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} diff --git a/docker/w9deployment/Dockerfile b/docker/w9deployment/Dockerfile index d3427c12..c87af473 100644 --- a/docker/w9deployment/Dockerfile +++ b/docker/w9deployment/Dockerfile @@ -9,4 +9,5 @@ RUN chmod +x /init_portainer FROM portainer/portainer-ce:2.19.0 LABEL maintainer="websoft9" LABEL version="2.19.0" + COPY --from=builder /init_portainer / \ No newline at end of file diff --git a/docker/w9deployment/init_portainer.go b/docker/w9deployment/init_portainer.go index 9dbbaa18..a8dc096e 100644 --- a/docker/w9deployment/init_portainer.go +++ b/docker/w9deployment/init_portainer.go @@ -41,7 +41,7 @@ func main() { } } - content, err := ioutil.ReadFile(filePath) + content, err := readPasswordFromFile(filePath) if err != nil { fmt.Println("read file error:", err) return @@ -74,7 +74,26 @@ func generatePassword(length int) string { return string(password) } -func writeToFile(filePath , content string) error { +func readPasswordFromFile(filePath string) (string, error) { + data, err := ioutil.ReadFile(filePath) + if err != nil { + return "", err + } + var passwordMap map[string]string + err = json.Unmarshal(data, &passwordMap) + if err != nil { + return "", err + } + password := passwordMap["password"] + return password, nil +} - return ioutil.WriteFile(filePath , []byte(content), 0755) +func writeToFile(filePath, password string) error { + data := map[string]string{"username": "admin", "password": password} + jsonData, err := json.Marshal(data) + if err != nil { + return err + } + err = ioutil.WriteFile(filePath, jsonData, 0755) + return err } \ No newline at end of file