From 5a249ab510614395125d6fa9fcdba35d3ee7185f Mon Sep 17 00:00:00 2001 From: ctengiz Date: Fri, 13 Feb 2026 15:56:01 +0300 Subject: [PATCH] publish --- scripts/eskidb_transfer.sh | 8 +++- scripts/publish.sh | 49 ++++++++++++++++++++ scripts/svc_install.sh | 93 ++++++++++++++++++++++++++++++++++++++ svc/db/mssql.go | 3 +- svc/db/postgres.go | 3 +- svc/main.go | 51 +++++++++++++++++++++ ui/.quasar/tsconfig.json | 10 ++-- 7 files changed, 209 insertions(+), 8 deletions(-) mode change 100644 => 100755 scripts/publish.sh create mode 100644 scripts/svc_install.sh diff --git a/scripts/eskidb_transfer.sh b/scripts/eskidb_transfer.sh index 235db92..d78fde4 100644 --- a/scripts/eskidb_transfer.sh +++ b/scripts/eskidb_transfer.sh @@ -2,4 +2,10 @@ rsync -azP /opt/baggib2b/ root@46.224.33.150:/opt/b2b --delete cd /tmp && sudo -u postgres pg_dump baggib2b -Fc > /tmp/baggib2b.backup -scp /tmp/baggib2b.backup root@46.224.33.150:/tmp/ \ No newline at end of file +scp /tmp/baggib2b.backup root@46.224.33.150:/tmp/ + +# öbür makinada +export PGPASSWORD=tayitkan +dropdb baggib2b -U postgres -h 127.0.0.1 +createdb -h 127.0.0.1 -U postgres baggib2b --encoding=UTF8 --locale=tr_TR.utf8 -T template0 +pg_restore -h 127.0.0.1 -U postgres -d baggib2b /tmp/baggib2b.backup \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh old mode 100644 new mode 100755 index e69de29..e143339 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -0,0 +1,49 @@ +#!/bin/bash +APP=bssapp +PRJ_ROOT=../ +SVC_ROOT=${PRJ_ROOT}/svc +UI_ROOT=${PRJ_ROOT}/ui +DEST_IP=46.224.33.150 + +echo "Building ${APP} executable" +cd ${SVC_ROOT} +if [[ $OSTYPE == 'darwin'* ]]; then + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./$APP ./main.go +else + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./$APP ./main.go +fi + + +echo "Building SPA" +cd ${UI_ROOT} + +quasar build + +echo "Copying executables" +scp ${SVC_ROOT}/${APP} root@${DEST_IP}:/opt/${APP}/${APP}.new +scp ${SVC_ROOT}/.env root@${DEST_IP}:/opt/${APP}/.env +scp ${SVC_ROOT}/mail.env root@${DEST_IP}:/opt/${APP}/mail.env +# scp ${SVC_ROOT}/upgrader/upgrader root@${DEST_IP}:/opt/${APP}/upgrader + +echo "Transferring additional files" +#rsync -azP ${PRJ_ROOT}/templates/ root@${DEST_IP}:/opt/${APP}/templates --delete +#rsync -azP ${PRJ_ROOT}/db/sqls root@${DEST_IP}:/opt/${APP} --delete +#rsync -azP ${SVC_ROOT}/fonts/ root@${DEST_IP}:/opt/${APP}/fonts --delete +#rsync -azP ${PRJ_ROOT}/db/migration/base root@${DEST_IP}:/opt/${APP}/migrate --delete +rsync -azP ${UI_ROOT}/dist/spa/ root@${DEST_IP}:/opt/${APP}/ui --delete + +#echo "Migrating database" +#ssh root@${DEST_IP} "/opt/migrater -folder /opt/${APP}/migrate/base -db ${APP} -host 10.0.0.2 -tracker base -migrate-table symigrate -password tesnos.+ed" + +echo "Updating system" +ssh root@${DEST_IP} "sudo systemctl stop ${APP}.service" +ssh root@${DEST_IP} "sudo rm /opt/${APP}/${APP}" +ssh root@${DEST_IP} "sudo mv /opt/${APP}/${APP}.new /opt/${APP}/${APP}" + +ssh root@${DEST_IP} "chown -R ${APP}:${APP} /opt/${APP}" + +ssh root@${DEST_IP} "sudo systemctl start ${APP}.service" + +# remove compiled binary +cd ${SVC_ROOT} +rm -rf ./$APP diff --git a/scripts/svc_install.sh b/scripts/svc_install.sh new file mode 100644 index 0000000..ebf38d4 --- /dev/null +++ b/scripts/svc_install.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +APP=bssapp +PORT=43201 +DOMAIN=ss.baggi.com.tr + +apt update && apt upgrade +apt -y install mc rsync curl nginx +apt install certbot python3-certbot-nginx +dpkg-reconfigure tzdata + +useradd --system --shell=/usr/sbin/nologin ${APP} + +mkdir -p /opt/${APP}/sqls +mkdir -p /opt/${APP}/migrate +mkdir -p /opt/${APP}/ui +mkdir -p /opt/${APP}/files + +echo "Creating application service" +read -d '' sservice << EOF +[Unit] +Description=${APP} +After=syslog.target +After=network.target +#Requires=postgresql.service +#Requires=memcached.service +#Requires=redis.service + +[Service] +# Modify these two values and uncomment them if you have +# repos with lots of files and get an HTTP error 500 because +# of that +### +LimitMEMLOCK=infinity +LimitNOFILE=1048576 + +RestartSec=2s +Type=simple +User=${APP} +Group=${APP} +WorkingDirectory=/opt/${APP}/ +ExecStart=/opt/${APP}/nerp +Restart=always + +Environment=HTTPPORT=${PORT} SQLSDIR=./sqls DBHOST=10.0.0.2 DBNAME=${APP} DBPASS=tesnos.+ed + +# enable to bind to a port below 1024 uncomment +### +#CapabilityBoundingSet=CAP_NET_BIND_SERVICE +#AmbientCapabilities=CAP_NET_BIND_SERVICE + +# Prevent writes to /usr, /boot, and /etc +ProtectSystem=full + +# Prevent accessing /home, /root and /run/user +ProtectHome=true + +# Execute pre and post scripts as root, otherwise it does it as User= +PermissionsStartOnly=true + +[Install] +WantedBy=multi-user.target +EOF +echo "$sservice" > /etc/systemd/system/${APP}.service + + +echo "Creating nginx conf" +read -d '' ngconf << EOF +server { + server_name ${DOMAIN} + listen 80; + client_max_body_size 100M; + + location / { + proxy_pass http://localhost:${PORT}; + + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + proxy_http_version 1.1; + proxy_set_header Connection ""; + } +} +EOF +echo "$ngconf" > /etc/nginx/sites-available/${DOMAIN} +ln -s /etc/nginx/sites-available/${DOMAIN} /etc/nginx/sites-enabled +systemctl restart nginx +certbot --nginx -d ${DOMAIN} + +systemctl daemon-reload +systemctl enable ${APP} + diff --git a/svc/db/mssql.go b/svc/db/mssql.go index 1917147..7e7ea8f 100644 --- a/svc/db/mssql.go +++ b/svc/db/mssql.go @@ -11,7 +11,8 @@ import ( var MssqlDB *sql.DB func ConnectMSSQL() { - connString := "sqlserver://sa:Gil_0150@10.0.0.9:1433?databaseName=BAGGI_V3" + //connString := "sqlserver://sa:Gil_0150@10.0.0.9:1433?databaseName=BAGGI_V3" + connString := "sqlserver://sa:Gil_0150@100.127.221.13:1433?databaseName=BAGGI_V3" var err error MssqlDB, err = sql.Open("sqlserver", connString) diff --git a/svc/db/postgres.go b/svc/db/postgres.go index b24cfa8..91caa71 100644 --- a/svc/db/postgres.go +++ b/svc/db/postgres.go @@ -18,7 +18,8 @@ func ConnectPostgres() (*sql.DB, error) { connStr := os.Getenv("POSTGRES_CONN") if connStr == "" { // fallback → sabit tanımlı bağlantı - connStr = "host=172.16.0.3 port=5432 user=postgres password=tayitkan dbname=baggib2b sslmode=disable" + connStr = "host=127.0.0.1 port=5432 user=postgres password=tayitkan dbname=baggib2b sslmode=disable" + //connStr = "host=172.16.0.3 port=5432 user=postgres password=tayitkan dbname=baggib2b sslmode=disable" } db, err := sql.Open("postgres", connStr) diff --git a/svc/main.go b/svc/main.go index 0894815..9cdf219 100644 --- a/svc/main.go +++ b/svc/main.go @@ -143,6 +143,7 @@ InitRoutes — FULL V3 (Method-aware) PERMISSION EDITION func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router { r := mux.NewRouter() + mountSPA(r) /* =========================================================== @@ -592,3 +593,53 @@ func main() { log.Println("✅ Server çalışıyor: http://localhost:8080") log.Fatal(http.ListenAndServe(":8080", handler)) } + +func mountSPA(m gorilla.Mux) { + m.Group(func(r chi.Router) { + r.NotFound(spaIndex) + r.Get("/", spaIndex) + }) +} + +func spaIndex(w http.ResponseWriter, r *http.Request) { + p := r.URL.Path + + if r.URL.Path == "/logo.png" { + _, err := os.Stat("./logo.png") + if err == nil { + http.ServeFile(w, r, "./logo.png") + return + } + } + + if !strings.HasPrefix(p, "/") { + p = "/" + p + r.URL.Path = p + } + p = path.Clean(p) + if p == "/" { + p = "index.html" + } + + if strings.HasPrefix(p, "/api") { + http.NotFound(w, r) + return + } + + name := path.Join(app.RUN.UiDir, filepath.FromSlash(p)) + + f, err := os.Stat(name) + if err != nil { + if os.IsNotExist(err) { + http.ServeFile(w, r, fmt.Sprintf("%s/index.html", app.RUN.UiDir)) + return + } + } + + if f.IsDir() { + Forbidden(w, nil) + return + } + + http.ServeFile(w, r, name) +} diff --git a/ui/.quasar/tsconfig.json b/ui/.quasar/tsconfig.json index 99f52b3..6721662 100644 --- a/ui/.quasar/tsconfig.json +++ b/ui/.quasar/tsconfig.json @@ -64,19 +64,19 @@ "./../src/stores/*" ], "#q-app": [ - "./../node_modules/@quasar/app-webpack/types/index.d.ts" + "./../node_modules/.pnpm/@quasar+app-webpack@4.3.2_pinia@3.0.4_vue@3.5.20__quasar@2.18.6_sass@1.97.3_tslib@2.8.1_ea0679f3401f6e63bbfdc4dae8ab5531/node_modules/@quasar/app-webpack/types/index.d.ts" ], "#q-app/wrappers": [ - "./../node_modules/@quasar/app-webpack/types/app-wrappers.d.ts" + "./../node_modules/.pnpm/@quasar+app-webpack@4.3.2_pinia@3.0.4_vue@3.5.20__quasar@2.18.6_sass@1.97.3_tslib@2.8.1_ea0679f3401f6e63bbfdc4dae8ab5531/node_modules/@quasar/app-webpack/types/app-wrappers.d.ts" ], "#q-app/bex/background": [ - "./../node_modules/@quasar/app-webpack/types/bex/entrypoints/background.d.ts" + "./../node_modules/.pnpm/@quasar+app-webpack@4.3.2_pinia@3.0.4_vue@3.5.20__quasar@2.18.6_sass@1.97.3_tslib@2.8.1_ea0679f3401f6e63bbfdc4dae8ab5531/node_modules/@quasar/app-webpack/types/bex/entrypoints/background.d.ts" ], "#q-app/bex/content": [ - "./../node_modules/@quasar/app-webpack/types/bex/entrypoints/content.d.ts" + "./../node_modules/.pnpm/@quasar+app-webpack@4.3.2_pinia@3.0.4_vue@3.5.20__quasar@2.18.6_sass@1.97.3_tslib@2.8.1_ea0679f3401f6e63bbfdc4dae8ab5531/node_modules/@quasar/app-webpack/types/bex/entrypoints/content.d.ts" ], "#q-app/bex/private/bex-bridge": [ - "./../node_modules/@quasar/app-webpack/types/bex/bex-bridge.d.ts" + "./../node_modules/.pnpm/@quasar+app-webpack@4.3.2_pinia@3.0.4_vue@3.5.20__quasar@2.18.6_sass@1.97.3_tslib@2.8.1_ea0679f3401f6e63bbfdc4dae8ab5531/node_modules/@quasar/app-webpack/types/bex/bex-bridge.d.ts" ] } },