Skip to content

Commit

Permalink
Merge branch 'zorchenhimer:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zorglube authored Mar 28, 2024
2 parents e4fbdf7 + 75854ce commit 8459f36
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ name: Build

on:
push:
branches: [master]
branches:
- master
tags:
- v*.*.*
pull_request:
branches: []

workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
pre-build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -53,7 +60,43 @@ jobs:
run: go build

- uses: actions/upload-artifact@v3
if: github.event_name != 'pull_request'
with:
name: MovieNight-${{ matrix.os }}-${{ matrix.arch }}
if-no-files-found: error
path: MovieNight*

docker:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'

needs: pre-build

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func setupSettings(adminPass string, confFile string) error {
if err != nil {
return fmt.Errorf("unable to load settings: %w", err)
}
if len(settings.StreamKey) == 0 {
if !settings.NewStreamKey && len(settings.StreamKey) == 0 {
return fmt.Errorf("missing stream key is settings.json")
}

Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ $ (make|gmake) TARGET=windows ARCH=386
$ ./MovieNight
```

### Docker Packages

The image can be pulled using the command below. View tagged versions at [ghcr](https://github.com/zorchenhimer/MovieNight/pkgs/container/movienight)

```bash
docker pull ghcr.io/zorchenhimer/movienight:master
```

### Docker build
MovieNight provides a Dockerfile and a docker-compose file to run MovieNight using Docker.

Expand Down Expand Up @@ -182,6 +190,7 @@ MovieNight’s configuration is controlled by `settings.json`:
- `LogLevel`: the log level, defaults to `debug`.
- `MaxMessageCount`: the number of messages displayed in the chat window.
- `NewPin`: if true, regenerates `RoomAccessPin` when the server starts.
- `NewStreamKey`: if true, uses a random `StreamKey` when the server starts. The command line option takes precedence, and will be used if it is set.
- `PageTitle`: The base string used in the `<title>` element of the page. When the stream title is set with `/playing`, it is appended; e.g., `Movie Night | The Man Who Killed Hitler and Then the Bigfoot`
- `RegenAdminPass`: if true, regenerates `AdminPassword` when the server starts.
- `RoomAccess`: the access policy of the chat room; this is managed by the application and should not be edited manually.
Expand Down
28 changes: 26 additions & 2 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ var sstore *sessions.CookieStore

type Settings struct {
// Non-Saved settings
filename string
cmdLineKey string // stream key from the command line
filename string
cmdLineKey string // stream key from the command line
rndStreamKey string // random stream key; only used if NewStreamKey is set

// Saved settings
AdminPassword string
Expand All @@ -33,6 +34,7 @@ type Settings struct {
LogLevel common.LogLevel
MaxMessageCount int
NewPin bool // Auto generate a new pin on start. Overwrites RoomAccessPin if set.
NewStreamKey bool // Auto generate a new stream key on start. Used instead of StreamKey if set.
PageTitle string // primary value for the page <title> element
RegenAdminPass bool // regenerate admin password on start?
RoomAccess AccessMode
Expand Down Expand Up @@ -172,6 +174,11 @@ func LoadSettings(filename string) (*Settings, error) {
s.TitleLength = 50
}

// Set a random stream key
if s.NewStreamKey {
s.rndStreamKey = randStringRunes(20)
}

// Is this a good way to do this? Probably not...
if len(s.SessionKey) == 0 {
out := ""
Expand Down Expand Up @@ -294,6 +301,10 @@ func (s *Settings) GetStreamKey() string {
if len(s.cmdLineKey) > 0 {
return s.cmdLineKey
}
if s.NewStreamKey {
return s.rndStreamKey
}

return s.StreamKey
}

Expand All @@ -311,3 +322,16 @@ func (s *Settings) generateNewPin() (string, error) {
}
return s.RoomAccessPin, nil
}

// Adapted from: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go/22892986#22892986
var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randStringRunes(n int) string {
length := big.NewInt(int64(len(letterRunes)))
b := make([]rune, n)
for i := range b {
letter_idx, _ := rand.Int(rand.Reader, length)
b[i] = letterRunes[letter_idx.Int64()]
}
return string(b)
}

0 comments on commit 8459f36

Please sign in to comment.