Skip to content

Commit

Permalink
Merge pull request zorchenhimer#189 from zorchenhimer/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
joeyak authored Dec 28, 2022
2 parents b72bb36 + 8ab7507 commit 5c5a1ba
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 70 deletions.
28 changes: 8 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
#
# ------ building mmovienight from source ------
#

FROM golang:1.16-alpine AS build
FROM golang:1.18 AS build

WORKDIR /app

RUN apk add alpine-sdk

COPY . .

RUN make docker



#
# ------ creating image to run movienight ------
#
RUN go build

FROM alpine:latest
FROM photon

WORKDIR /app

VOLUME /config
VOLUME /data

COPY --from=build /app /app
COPY --from=build /app/settings_example.json /config/settings.json
RUN mkdir -p /data/emotes & mkdir -p /data/static

RUN chmod +x /app/docker/start.sh
COPY --from=build /app/MovieNight /app
COPY --from=build /app/settings_example.json /data/config/settings.json

EXPOSE 8089
EXPOSE 1935

CMD ["/app/docker/start.sh"]
CMD ["/app/MovieNight", "--config", "/data/config/settings.json", "--static", "/data/static", "--emotes", "/data/emotes"]
6 changes: 3 additions & 3 deletions docker/docker-compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ services:
movienight:
image: movienight:latest
build:
context: ../
context: .
dockerfile: Dockerfile
ports:
- 8089:8089
- 1935:1935
volumes:
- movienight-config:/config
- movienight-data:/data

volumes:
movienight-config:
movienight-data:
7 changes: 0 additions & 7 deletions docker/start.sh

This file was deleted.

17 changes: 4 additions & 13 deletions emotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"strings"

"github.com/zorchenhimer/MovieNight/common"
"github.com/zorchenhimer/MovieNight/files"
"golang.org/x/exp/slices"
)

var emotesDir string

func loadEmotes() error {
var err error
common.Emotes, err = processEmoteDir(files.JoinRunPath("emotes"))
common.Emotes, err = processEmoteDir(emotesDir)
if err != nil {
return fmt.Errorf("could not process emote dir: %w", err)
}
Expand All @@ -24,22 +25,12 @@ func loadEmotes() error {

func processEmoteDir(dir string) (common.EmotesMap, error) {
em := make(common.EmotesMap)
dirInfo, err := os.ReadDir(dir)
_, err := os.ReadDir(dir)
if err != nil {
common.LogErrorf("could not open emote dir: %v\n", err)
return em, nil
}

subDirs := []string{}

for _, item := range dirInfo {
// Get first level subdirs (eg, "twitch", "discord", etc)
if item.IsDir() {
subDirs = append(subDirs, item.Name())
continue
}
}

filepath.WalkDir(dir, func(fpath string, d fs.DirEntry, err error) error {
if d.IsDir() || err != nil {
return nil
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
Expand All @@ -15,7 +14,6 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down
45 changes: 21 additions & 24 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,31 @@ func (w writeFlusher) Flush() error {
func wsEmotes(w http.ResponseWriter, r *http.Request) {
file := strings.TrimPrefix(r.URL.Path, "/")

body, err := os.ReadFile(file)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
common.LogErrorf("Could not read emote file %s: %v\n", file, err)
w.WriteHeader(http.StatusNotFound)
return
}

err = filepath.WalkDir(filepath.Dir(file), func(path string, d fs.DirEntry, err error) error {
if d.IsDir() || err != nil || len(body) > 0 {
return nil
}
emoteDirSuffix := filepath.Base(emotesDir)
if emoteDirSuffix == filepath.SplitList(file)[0] {
file = strings.TrimPrefix(file, emoteDirSuffix+"/")
}

if filepath.Base(path) != filepath.Base(file) {
return nil
}
var body []byte
err := filepath.WalkDir(emotesDir, func(path string, d fs.DirEntry, err error) error {
if d.IsDir() || err != nil || len(body) > 0 {
return nil
}

body, err = os.ReadFile(path)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
if filepath.Base(path) != filepath.Base(file) {
return nil
})
if err != nil {
common.LogErrorf("Subdir emote could not be read %s: %v\n", file, err)
w.WriteHeader(http.StatusNotFound)
return
}

body, err = os.ReadFile(path)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
return nil
})
if err != nil {
common.LogErrorf("Emote could not be read %s: %v\n", file, err)
w.WriteHeader(http.StatusNotFound)
return
}

if len(body) == 0 {
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ type args struct {
Addr string `arg:"-l,--addr" help:"host:port of the HTTP server"`
RtmpAddr string `arg:"-r,--rtmp" help:"host:port of the RTMP server"`
StreamKey string `arg:"-k,--key" help:"Stream key, to protect your stream"`
AdminPass string `arg:"-a,--admin" help:"Set admin password. Overrides configuration in settings.json. This will not write the password to settings.json."`
AdminPass string `arg:"-a,--admin" help:"Set admin password. Overrides configuration in settings.json. This will not write the password to settings.json."`
ConfigFile string `arg:"-f,--config" help:"URI of the conf file"`
StaticDir string `arg:"-s,--static" help:"Directory to read static files from by default"`
EmotesDir string `arg:"-e,--emotes" help:"Directory to read emotes. By default it uses the executable directory"`
WriteStatic bool `arg:"--write-static" help:"write static files to the static dir"`
}

Expand All @@ -73,6 +74,11 @@ func run(args args) {
var err error
start := time.Now()

emotesDir = args.EmotesDir
if emotesDir == "" {
emotesDir = files.JoinRunPath("emotes")
}

staticFsys, err := files.FS(staticFS, args.StaticDir, "static")
if err != nil {
log.Fatalf("Error creating static FS: %v\n", err)
Expand Down

0 comments on commit 5c5a1ba

Please sign in to comment.