Compare commits

..

2 Commits

Author SHA1 Message Date
56abe1dee4 fix(docker): fix Dockerfile
Some checks failed
build / Go-Build (push) Failing after 11m3s
build / Go-Build (pull_request) Successful in 28s
2026-02-09 23:23:44 +01:00
7c5d319043 fix(database): move database file to storage dir 2026-02-09 23:23:24 +01:00
6 changed files with 26 additions and 16 deletions

View File

@@ -1,11 +1,16 @@
# Build stage
FROM golang:latest AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -v -o svg-templater ./...
RUN CGO_ENABLED=0 GOOS=linux go build -v -o svg-templater ./cmd/svg-templater
# Final stage
FROM alpine:latest
WORKDIR /root/
EXPOSE 3000
VOLUME ["/var/lib/svg-templater"]
RUN apk add inkscape fontconfig
COPY --from=builder /app/svg-templater /usr/local/bin/svg-templater
CMD ["svg-templater"]

View File

@@ -1,10 +1,7 @@
package main
import (
"log"
"tomatentum.net/svg-templater/internal/command"
"tomatentum.net/svg-templater/internal/database"
"tomatentum.net/svg-templater/pkg/format"
)
@@ -12,12 +9,6 @@ func main() {
if !format.CheckInkscape() {
panic("Inkscape not found")
}
if err := database.OpenSQLite(); err != nil {
log.Fatal("Failed opening DB:\n", err)
return
}
defer database.Close()
database.InitDB()
command.PrepareCommandLine()
command.HandleCommandline()
}

2
go.mod
View File

@@ -7,7 +7,7 @@ require github.com/glebarez/go-sqlite v1.22.0
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hymkor/exregexp-go v0.2.0 // indirect
github.com/hymkor/exregexp-go v0.2.0
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/sys v0.15.0 // indirect

View File

@@ -2,7 +2,9 @@ package command
import (
"flag"
"log"
"tomatentum.net/svg-templater/internal/database"
"tomatentum.net/svg-templater/internal/server"
"tomatentum.net/svg-templater/pkg/svg"
)
@@ -23,6 +25,17 @@ func PrepareCommandLine() {
func HandleCommandline() {
flag.Parse()
if !help {
svg.Storage = svg.NewFileStorage(datapath, "public")
if err := database.OpenSQLite(datapath); err != nil {
log.Fatal("Failed opening DB:\n", err)
return
}
database.InitDB()
}
defer database.Close()
if generateTokenFlag {
GenerateTokenCommand()
} else if deleteTokenFlag {
@@ -30,7 +43,6 @@ func HandleCommandline() {
} else if help {
flag.PrintDefaults()
} else {
svg.Storage = svg.NewFileStorage(datapath, "public")
server.PrepareHTTP()
server.Start()
}

View File

@@ -3,6 +3,7 @@ package database
import (
"database/sql"
"log"
"path/filepath"
_ "github.com/glebarez/go-sqlite"
)
@@ -11,8 +12,8 @@ const FILENAME string = "storage.db"
var database *sql.DB
func OpenSQLite() error {
db, err := sql.Open("sqlite", FILENAME)
func OpenSQLite(basepath string) error {
db, err := sql.Open("sqlite", filepath.Join(basepath, FILENAME))
if err != nil {
return err
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
@@ -74,11 +75,11 @@ func runCommand(input string, param ConversionParameters) (io.ReadCloser, error)
args = append(args, "-o", outFile)
args = append(args, input)
cmd := exec.Command("/opt/homebrew/bin/inkscape", args...)
cmd := exec.Command("inkscape", args...)
cmd.Dir = svg.TempDir
out, err := cmd.CombinedOutput()
log.Println(string(out))
if err != nil {
return nil, fmt.Errorf("inkscape failed: %w: %s", err, string(out))
}