Skip to content

Commit

Permalink
Set user home when running in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
laenzlinger committed Mar 30, 2024
1 parent b285d38 commit d315d11
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ RUN apt-get update \
&& apt-get install -y libreoffice-writer \
&& rm -rf /var/lib/apt/lists/*

COPY setlist /setlist

RUN mkdir /home/user \
&& chmod 777 /home/user

Expand All @@ -16,4 +14,6 @@ RUN mkdir /repertoire

WORKDIR /repertoire

COPY setlist /setlist

ENTRYPOINT [ "/setlist" ]
11 changes: 11 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package config

import "os"

func RunningInContainer() bool {
return os.Getenv("OS_ENV") == "container"
}

func UserHome() string {
return os.Getenv("HOME")
}
3 changes: 2 additions & 1 deletion internal/html/pdf/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
"github.com/laenzlinger/setlist/internal/config"
)

func HTMLToPDF(in, out string) error {
Expand All @@ -16,7 +17,7 @@ func HTMLToPDF(in, out string) error {
}
url := fmt.Sprintf("file://%s/%s", wd, in)
opts := []chromedp.ExecAllocatorOption{}
if os.Getenv("OS_ENV") == "container" {
if config.RunningInContainer() {
// when running inside a container, we don't use sandbox
opts = append(opts, chromedp.NoSandbox)
}
Expand Down
9 changes: 7 additions & 2 deletions internal/sheet/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"
"strings"

"github.com/laenzlinger/setlist/internal/config"
"github.com/laenzlinger/setlist/internal/gig"
convert "github.com/laenzlinger/setlist/internal/html/pdf"
tmpl "github.com/laenzlinger/setlist/internal/html/template"
Expand Down Expand Up @@ -111,8 +112,12 @@ func (s *Sheet) verifySheetPdf() error {
func (s *Sheet) generateFromSource() error {
log.Printf("generate from source for `%s`", s.song)
buf := bytes.NewBuffer([]byte{})
//nolint:gosec // FIXME validate input
cmd := exec.Command("libreoffice", "--headless", "--convert-to", "pdf", "--outdir", s.sourceDir(), s.sourceName())
args := []string{"--headless", "--convert-to", "pdf", "--outdir", s.sourceDir(), s.sourceName()}
if config.RunningInContainer() {
args = append(args, fmt.Sprintf("-env:UserInstallation=file:///%s", config.UserHome()))
}

cmd := exec.Command("libreoffice", args...)
cmd.Stdout = buf
cmd.Stderr = buf
err := cmd.Run()
Expand Down

0 comments on commit d315d11

Please sign in to comment.