package maker import ( "context" "fmt" "os" "path/filepath" "yizhisec.com/hsv2/forge/pkg/logger" "yizhisec.com/hsv2/forge/pkg/resource" ) func (m *maker) AppMie(ctx context.Context, version string, replica int) error { const ( _config = `Version: "3" BackupSeafile: Host: hs-resource-server Port: 19980 account_manager: address: http://user-service:9013 client_server: msg: http://client-service:9025 api: http://client-service:9024 web: http://client-service:9129 backend_queue_names: request: request_que web: web_que backup_database_server: host: hs-backup-server port: 9349 backup_seafile_server: host: hs-resource-server port: 19980 clientPKG: android: client_pkg_dir: /data/storage/client_pkg/android client_pkg_file_path: /data/storage/client_pkg/android/SecureApplication-Client-Android.apk client_pkg_name: SecureApplication-Client-Android.apk client_version_file_path: /data/storage/client_pkg/android/android_version.json dir: /data/storage/client_pkg ios: client_pkg_dir: /data/storage/client_pkg/ios client_pkg_file_path: '' client_pkg_name: '' client_version_file_path: /data/storage/client_pkg/ios/ios_version.json linux: client_pkg_dir: /data/storage/client_pkg/linux client_pkg_file_path: /data/storage/client_pkg/linux/hscore-ubuntu-22.04-amd64.deb client_pkg_name: hscore-ubuntu-22.04-amd64.deb client_version_file_path: /data/storage/client_pkg/linux/linux_version.json mac: client_pkg_beta_file_path: /yizhisec/hs_nginx/resource/hybridscope-client-mac-beta.pkg client_pkg_beta_name: hybridscope-client-mac-beta.pkg client_pkg_dir: /data/storage/client_pkg/mac client_pkg_file_path: /yizhisec/hs_nginx/resource/hybridscope-client-mac.pkg client_pkg_name: hybridscope-client-mac.pkg client_version_file_path: /data/storage/client_pkg/mac/mac_version.json oem_dir: /yizhisec/hs_nginx/data/443/oem oem_file_path: /yizhisec/hs_nginx/data/443/oem/data.json windows: client_main_zip_name: app.7z client_pkg_cfg_file_name: login.conf client_pkg_dir: /data/storage/client_pkg/windows client_pkg_unzip_dir: package client_pkg_zip: /data/storage/client_pkg/windows/dsclient.zip client_zip_version: version databases: elasticsearch: host: es-service.db-es port: 9200 ipdb: path: /etc/mie-server/ipdb/ip.ipdb mysql: db: mie host: mysql-cluster-mysql-master.db-mysql password: L0hMysql. port: 3306 username: root redis: host: redis-master.db-redis password: HybridScope0xRed1s. port: 6379 username: '' exe_root_license: path: /etc/mie-server/root.pem gateway_service: host: gateway-service.hsv2 port: 9012 host: 0.0.0.0 license: version: 3 license_init_conf: /etc/mie-server/server_license_init.conf public_key: /etc/mie-server/license/pub_key log_level: 20 mqtt_server: host: emqx-service.db-emqx port: 1883 port: 9002 resource_server: address: http://hs-resource-server:19980 secret_key: i345piuh48776lkjsdhfsdfljho sentry_dsn: null static_urlpath_prefix: network_app_icon: /user/avatar storage: avatar_dir: /data/storage/avatar mobile_app_dir: /yizhisec/hs_nginx network_app_icon: network_app patch_dir: /data/storage/patch public_folder_file_dir: /data/storage/public_folder_file share_file_storage: /data/storage/share_file sync_avatar_dir: sync tmp_dir: /data/storage/tmp upload_avatar_dir: local uploaded_files: /data/storage/uploaded_files token_key: TtKVnSzEHO3jRv/GWg3f5k3H1OVfMnPZ1Ke9E6MSCXk= translation_path: /etc/mie-server/translation.csv yosguard_service: host: 172.17.0.1 port: 7788 ElinkLogin: true export_with_blind_watermark: true` _upsert = `#!/bin/bash kubectl create configmap config-api --namespace hsv2 --from-file=conf.yml=./conf.yml --dry-run=client -o yaml | kubectl apply -f - kubectl apply -f deployment-api.yaml kubectl apply -f deployment-sweeper.yaml kubectl apply -f deployment-worker.yaml kubectl apply -f deployment-cron.yaml kubectl rollout restart deployment api-deployment -n hsv2` ) var ( err error workdir = filepath.Join(m.workdir, "app", "mie") ) logger.Info("☑️ maker.AppMie: 开始构建 mie ... version = %s, workdir = %s", version, workdir) _ = os.RemoveAll(workdir) logger.Debug("☑️ maker.AppMie: 开始创建工作目录 = %s", workdir) if err = os.MkdirAll(workdir, 0755); err != nil { logger.Debug("❌ maker.AppMie: 创建目录失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 创建工作目录成功 = %s", workdir) imgName := "hub.yizhisec.com/hybridscope/mie-server:latest" logger.Debug("☑️ maker.AppMie: start pull image = %s", imgName) if err = m.Image(ctx, imgName, WithImageForcePull(true), WithImageSave(filepath.Join(workdir, "mie.tar")), ); err != nil { logger.Debug("❌ maker.AppMie: 拉取镜像失败: %v", err) return err } logger.Debug("✅ maker.AppMie: pull image success = %s", imgName) if replica < 1 { replica = 1 } logger.Debug("☑️ maker.AppMie: 写入 conf.yml 文件..., dest = %s", filepath.Join(workdir, "conf.yml")) if err = os.WriteFile(filepath.Join(workdir, "conf.yml"), []byte(_config), 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 conf.yml 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 conf.yml 文件成功, dest = %s", filepath.Join(workdir, "conf.yml")) logger.Debug("☑️ maker.AppMie: 写入 deployment-api.yaml 文件..., dest = %s", filepath.Join(workdir, "deployment-api.yaml")) apiYaml := []byte(fmt.Sprintf(resource.YAMLAppMieAPI, replica)) if err = os.WriteFile(filepath.Join(workdir, "deployment-api.yaml"), apiYaml, 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 deployment-api.yaml 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 deployment-api.yaml 文件成功, dest = %s", filepath.Join(workdir, "deployment-api.yaml")) logger.Debug("☑️ maker.AppMie: 写入 deployment-sweeper.yaml 文件..., dest = %s", filepath.Join(workdir, "deployment-sweeper.yaml")) if err = os.WriteFile(filepath.Join(workdir, "deployment-sweeper.yaml"), resource.YAMLAppMieSweeper, 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 deployment-sweeper.yaml 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 deployment-sweeper.yaml 文件成功, dest = %s", filepath.Join(workdir, "deployment-sweeper.yaml")) logger.Debug("☑️ maker.AppMie: 写入 deployment-worker.yaml 文件..., dest = %s", filepath.Join(workdir, "deployment-worker.yaml")) if err = os.WriteFile(filepath.Join(workdir, "deployment-worker.yaml"), resource.YAMLAppMieWorker, 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 deployment-worker.yaml 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 deployment-worker.yaml 文件成功, dest = %s", filepath.Join(workdir, "deployment-worker.yaml")) logger.Debug("☑️ maker.AppMie: 写入 deployment-cron.yaml 文件..., dest = %s", filepath.Join(workdir, "deployment-cron.yaml")) if err = os.WriteFile(filepath.Join(workdir, "deployment-cron.yaml"), resource.YAMLAppMieCron, 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 deployment-cron.yaml 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 deployment-cron.yaml 文件成功, dest = %s", filepath.Join(workdir, "deployment-cron.yaml")) logger.Debug("☑️ maker.AppMie: 写入 upsert.sh 文件..., dest = %s", filepath.Join(workdir, "upsert.sh")) if err = os.WriteFile(filepath.Join(workdir, "upsert.sh"), []byte(_upsert), 0755); err != nil { logger.Debug("❌ maker.AppMie: 写入 upsert.sh 失败: %v", err) return err } logger.Debug("✅ maker.AppMie: 写入 upsert.sh 文件成功, dest = %s", filepath.Join(workdir, "upsert.sh")) if err = os.WriteFile(filepath.Join(workdir, "version.txt"), []byte(version), 0644); err != nil { logger.Debug("❌ maker.AppMie: 写入 version.txt 失败: %v", err) return err } logger.Info("✅ maker.AppMie: 构建 mie 成功!!! version = %s, workdir = %s", version, workdir) return nil }