Update scripts for new location

This commit is contained in:
Daniel Mason 2021-12-25 13:30:55 +13:00
parent d268d939eb
commit ef66e1c8df
8 changed files with 26 additions and 20 deletions

View File

@ -22,4 +22,6 @@ MAIL_FROM_NAME=
DEV_MODE=false
GOSCROBBLE_DOMAIN=""
STATIC_DIR="web"
DATA_DIR="/var/www/goscrobble-data"
FRONTEND_DIRECTORY="/var/www/goscrobble-web"

View File

@ -5,7 +5,7 @@ variables:
VERSION: 0.1.001
build-go:
image: golang:1.16.7
image: golang:1.16
stage: build
only:
- master

View File

@ -51,10 +51,14 @@ func main() {
goscrobble.RefereshExpiry = time.Duration(i) * time.Second
}
goscrobble.StaticDirectory = "web"
staticDirectoryStr := os.Getenv("STATIC_DIR")
if staticDirectoryStr != "" {
goscrobble.StaticDirectory = staticDirectoryStr
goscrobble.DataDirectory = os.Getenv("DATA_DIRECTORY")
if goscrobble.DataDirectory == "" {
panic("DATA_DIRECTORY required in .env")
}
goscrobble.FrontendDirectory = os.Getenv("FRONTEND_DIRECTORY")
if goscrobble.FrontendDirectory == "" {
panic("FRONTEND_DIRECTORY required in .env")
}
// Ignore reverse proxies

View File

@ -32,4 +32,7 @@ These are stored in `web/.env.production` and `web/.env.development`
DEV_MODE=false // true|false - Defaults false
GOSCROBBLE_DOMAIN="" // Full domain for email links (https://goscrobble.com))
STATIC_DIR="web" // Location to store images (This will serve from web/static)
DATA_DIRECTORY="/var/www/goscrobble-data"
FRONTEND_DIRECTORY="/var/www/goscrobble-web"

View File

@ -2,12 +2,13 @@
# Easy deploy script..
echo 'Fetching latest git commit'
cd /var/www/goscrobble-api
git pull
echo 'Building backend'
go build -o goscrobble cmd/go-scrobble/*.go
cd web
cd /var/www/goscrobble-web
echo 'Installing frontend packages'
npm install --production

View File

@ -5,7 +5,7 @@ After=network.target
[Service]
Type=simple
User=root
ExecStart=/bin/bash -c 'cd /root/go-scrobble && ./goscrobble'
ExecStart=/bin/bash -c 'cd /var/www/goscrobble-api && ./goscrobble'
Restart=on-failure
[Install]

View File

@ -8,13 +8,8 @@ import (
)
func importImage(uuid string, url string) error {
// Create the file
path, err := os.Getwd()
if err != nil {
return err
}
out, err := os.Create(path + string(os.PathSeparator) + StaticDirectory + string(os.PathSeparator) + "img" + string(os.PathSeparator) + uuid + "_full.jpg")
// Create image
out, err := os.Create(DataDirectory + string(os.PathSeparator) + "img" + string(os.PathSeparator) + uuid + "_full.jpg")
if err != nil {
return err
}

View File

@ -22,8 +22,9 @@ type jsonResponse struct {
// List of Reverse proxies
var ReverseProxies []string
// Static image directory
var StaticDirectory string
// Directories
var FrontendDirectory string
var DataDirectory string
// RequestRequest - Incoming JSON!
type RequestRequest struct {
@ -96,14 +97,14 @@ func HandleRequests(port string) {
r.PathPrefix("/api")
// SERVE STATIC FILES - NO AUTH
spaStatic := spaStaticHandler{staticPath: StaticDirectory}
spaStatic := spaStaticHandler{staticPath: DataDirectory}
r.PathPrefix("/img").Handler(spaStatic)
apiDocs := spaStaticHandler{staticPath: "docs/api/build"}
r.PathPrefix("/docs").Handler(apiDocs)
// SERVE FRONTEND - NO AUTH
spa := spaHandler{staticPath: "web/build", indexPath: "index.html"}
spa := spaHandler{staticPath: FrontendDirectory + string(os.PathSeparator) + "build", indexPath: "index.html"}
r.PathPrefix("/").Handler(spa)
c := cors.New(cors.Options{