This commit is contained in:
2026-02-13 15:56:01 +03:00
parent 03d6c61587
commit 5a249ab510
7 changed files with 209 additions and 8 deletions

View File

@@ -3,3 +3,9 @@
rsync -azP /opt/baggib2b/ root@46.224.33.150:/opt/b2b --delete rsync -azP /opt/baggib2b/ root@46.224.33.150:/opt/b2b --delete
cd /tmp && sudo -u postgres pg_dump baggib2b -Fc > /tmp/baggib2b.backup cd /tmp && sudo -u postgres pg_dump baggib2b -Fc > /tmp/baggib2b.backup
scp /tmp/baggib2b.backup root@46.224.33.150:/tmp/ 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

49
scripts/publish.sh Normal file → Executable file
View File

@@ -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

93
scripts/svc_install.sh Normal file
View File

@@ -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}

View File

@@ -11,7 +11,8 @@ import (
var MssqlDB *sql.DB var MssqlDB *sql.DB
func ConnectMSSQL() { 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 var err error
MssqlDB, err = sql.Open("sqlserver", connString) MssqlDB, err = sql.Open("sqlserver", connString)

View File

@@ -18,7 +18,8 @@ func ConnectPostgres() (*sql.DB, error) {
connStr := os.Getenv("POSTGRES_CONN") connStr := os.Getenv("POSTGRES_CONN")
if connStr == "" { if connStr == "" {
// fallback → sabit tanımlı bağlantı // 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) db, err := sql.Open("postgres", connStr)

View File

@@ -143,6 +143,7 @@ InitRoutes — FULL V3 (Method-aware) PERMISSION EDITION
func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router { func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router {
r := mux.NewRouter() r := mux.NewRouter()
mountSPA(r)
/* /*
=========================================================== ===========================================================
@@ -592,3 +593,53 @@ func main() {
log.Println("✅ Server çalışıyor: http://localhost:8080") log.Println("✅ Server çalışıyor: http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", handler)) 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)
}

View File

@@ -64,19 +64,19 @@
"./../src/stores/*" "./../src/stores/*"
], ],
"#q-app": [ "#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": [ "#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": [ "#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": [ "#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": [ "#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"
] ]
} }
}, },