ソースを参照

d07 Начало сборки под скриптом

user 2 年 前
コミット
99e2d26d01

+ 1 - 0
app_serv/server/serv_web/serv_web.go

@@ -127,6 +127,7 @@ func (сам *СервВеб) Сервер() types.ИСервер {
 // Пуск -- запускае веб-сервер в работу
 func (сам *СервВеб) Пуск() {
 	фнПуск := func() {
+		log.Printf("СервВеб.Пуск().фнПуск(): порт=%q\n", сам.порт)
 		ош := сам.файбер.Listen(":" + сам.порт)
 		if ош != nil {
 			log.Printf("СервВеб.Пуск(): при работе веб-сервера, ош=\n\t%v\n", ош)

+ 6 - 0
app_serv/server/server_stat/server_stat.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"strings"
+	"sync"
 	"time"
 
 	"wartank/pkg/types"
@@ -16,6 +17,7 @@ type СерверСтат struct {
 	CчётСтарт_   int           `json:"count_start"`  // Количество запусков
 	ВремяВсего_  time.Duration `json:"time_total"`   // Общее время работы в секундах
 	ВремяСессия_ time.Duration `json:"time_session"` // Время сессии в секундах
+	блок         sync.RWMutex
 }
 
 // НовСерверСтат -- возвращает структуру статистики сервера
@@ -60,6 +62,8 @@ func (сам *СерверСтат) загр() error {
 // Работает в отдельном потоке, считает время работы и счетчик запусков
 func (сам *СерверСтат) пуск() {
 	фнПуск := func() {
+		сам.блок.Lock()
+		defer сам.блок.Unlock()
 		сам.ВремяВсего_ += time.Second
 		сам.ВремяСессия_ += time.Second
 		if ош := сам.сохр(); ош != nil {
@@ -104,5 +108,7 @@ func (сам *СерверСтат) ВремяСессия() string {
 
 // ВремяВсего -- возвращает общее время работы
 func (сам *СерверСтат) ВремяВсего() string {
+	сам.блок.RLock()
+	defer сам.блок.RUnlock()
 	return сам.ВремяВсего_.String()
 }

+ 68 - 5
app_work/make.py

@@ -27,6 +27,7 @@ class Build:
     def __init__(self) -> None:
         self.date_build: str = str(datetime.datetime.now())
         """Дата сборки"""
+        self.date_build = self.date_build.replace(" ", "_")
 
         cmd: list[str] = ['git', 'describe', '--tags', '--abbrev=0']
         output: bytes = subprocess.Popen(
@@ -39,7 +40,7 @@ class Build:
         cmd = ['go', 'version']
         output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
         go_version: str = output.decode("utf-8")
-        go_version = go_version[11:]
+        go_version = go_version[11:][:-1].replace(" ", "_")
         out: str = f"date={self.date_build}\t\t" +\
             f"tag={self.tag}\t\t" +\
             f"go_version={go_version}"
@@ -50,6 +51,7 @@ class Build:
 
     def run(self) -> None:
         """Запуск сборки"""
+        print("cleaning")
         try:
             shutil.rmtree('./bin')
         except OSError:
@@ -70,13 +72,71 @@ class Build:
             os.mkdir("bin/web/tmpl")
         except FileExistsError:
             pass
+        print("copying")
         os.system('cp -r ../app_serv/web ./bin')
         os.chdir("../app_serv")
-        # os.system("go build -o app_work")
+        print("format")
+        os.system("go fmt ./...")
+        print("build")
+        cmd: str = """go build -ldflags "-w -s -X """ +\
+            f"""main.GoVersion={self.go_version} -X """ +\
+            """main.Version=$TAG -X """ +\
+            """main.Date=$BUILD_DATE" -o """ +\
+            '../app_work/bin/server.exe ./cmd/server/main.go'
+        print(cmd)
+        os.system(cmd)
+        os.chdir("../app_work")
+        print('stripping')
+        os.system('strip -s ./bin/server.exe')
+        print('packing exe')
+        os.system('upx -f ./bin/server.exe')
+        exeSize: int = os.path.getsize("./bin/server.exe")
+        print(f'size exe={exeSize/1000**2:.2f} MB')
 
-        cmd: list[str] = ['go', 'fmt', './...']
-        subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
-        # go_version: str = output.decode("utf-8")
+
+class Dev:
+    """Класс разработки
+    """
+
+    def __init__(self) -> None:
+        pass
+
+    def run(self) -> None:
+        print("cleaning")
+        try:
+            shutil.rmtree('./bin')
+        except OSError:
+            pass
+        try:
+            os.mkdir("bin")
+        except FileExistsError:
+            pass
+        try:
+            os.mkdir("bin/web")
+        except FileExistsError:
+            pass
+        try:
+            os.mkdir("bin/web/static")
+        except FileExistsError:
+            pass
+        try:
+            os.mkdir("bin/web/tmpl")
+        except FileExistsError:
+            pass
+        print("copying")
+        os.system('cp -r ../app_serv/web ./bin')
+        os.chdir("../app_serv")
+        print("format")
+        os.system("go fmt ./...")
+        print("build")
+        cmd: str = """go build -race """ +\
+            '-o ../app_work/bin/server.exe ./cmd/server/main.go'
+        print(cmd)
+        os.system(cmd)
+        os.chdir("../app_work/bin")
+        os.unsetenv('STAGE')
+        os.putenv('STAGE', 'local')
+        os.system('./server.exe')
 
 
 if __name__ == '__main__':
@@ -92,6 +152,9 @@ if __name__ == '__main__':
         case"build":  # Сборка всей программы
             b: Build = Build()
             b.run()
+        case "dev":  # Разработка
+            d: Dev = Dev()
+            d.run()
         case "":
             help()
         case _: pass