Drop dependency on npm (downloading required js modules via soundcloakctl)

This commit is contained in:
Laptop
2024-12-28 22:10:23 +02:00
parent 737658f286
commit 08f9bc18aa
7 changed files with 35 additions and 21 deletions

View File

@@ -1,7 +1,6 @@
Dockerfile Dockerfile
*.yaml *.yaml
build build
.github
.gitignore .gitignore
soundcloak.example.json soundcloak.example.json

4
.gitignore vendored
View File

@@ -16,4 +16,6 @@ package-lock.json
regexp2_codegen.go regexp2_codegen.go
# built binary # built binary
main main
!.gitkeep

View File

@@ -15,22 +15,19 @@ RUN go generate ./lib/*
RUN go install git.maid.zone/stuff/soundcloakctl@master RUN go install git.maid.zone/stuff/soundcloakctl@master
RUN soundcloakctl config codegen RUN soundcloakctl config codegen
RUN soundcloakctl js download
RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -ldflags "-s -w -extldflags '-static' -X main.commit=`git rev-parse HEAD | head -c 7` -X main.repo=`git remote get-url origin`" -o ./app RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -ldflags "-s -w -extldflags '-static' -X main.commit=`git rev-parse HEAD | head -c 7` -X main.repo=`git remote get-url origin`" -o ./app
RUN echo "soundcloak:x:5000:5000:Soundcloak user:/:/sbin/nologin" > /etc/minimal-passwd && \ RUN echo "soundcloak:x:5000:5000:Soundcloak user:/:/sbin/nologin" > /etc/minimal-passwd && \
echo "soundcloak:x:5000:" > /etc/minimal-group echo "soundcloak:x:5000:" > /etc/minimal-group
FROM node:${NODE_VERSION} AS node
WORKDIR /hls.js
COPY --from=build /build/package.json ./
RUN npm i
FROM scratch FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /build/assets /assets COPY --from=build /build/assets /assets
COPY --from=build /build/instance /instance
COPY --from=build /build/external /external
COPY --from=build /build/app /app COPY --from=build /build/app /app
COPY --from=node /hls.js/node_modules/hls.js/dist/hls.light.min.js /node_modules/hls.js/dist/hls.light.min.js
COPY --from=build /etc/minimal-passwd /etc/passwd COPY --from=build /etc/minimal-passwd /etc/passwd
COPY --from=build /etc/minimal-group /etc/group COPY --from=build /etc/minimal-group /etc/group

View File

@@ -1,8 +1,7 @@
# Setup # Setup
## Prerequisites ## Prerequisites
1. [node.js + npm](https://nodejs.org) (any recent enough version should do, it's just used for getting hls.js builds) 1. [golang](https://go.dev) (I recommend version 1.22.10. Technically, you need 1.21.4 or higher)
2. [golang](https://go.dev) (I recommend version 1.22.10. Technically, you need 1.21.4 or higher) 2. [git](https://git-scm.com)
3. [git](https://git-scm.com)
## The setup ## The setup
1. Clone this repository: 1. Clone this repository:
@@ -29,6 +28,12 @@ npm i
go install github.com/a-h/templ/cmd/templ@latest go install github.com/a-h/templ/cmd/templ@latest
``` ```
*You might need to add go binaries to your PATH (add this line to your .bashrc / .zshrc / whatever)*
```sh
export PATH=${PATH}:`go env GOPATH`/bin
```
5. Download regexp2cg: 5. Download regexp2cg:
Not really required, but helps speed up some parts of the code that use regular expressions by generating code for them instead of compiling in runtime. Not really required, but helps speed up some parts of the code that use regular expressions by generating code for them instead of compiling in runtime.
@@ -37,12 +42,21 @@ Not really required, but helps speed up some parts of the code that use regular
go install github.com/dlclark/regexp2cg@main go install github.com/dlclark/regexp2cg@main
``` ```
*You might need to add go binaries to your PATH (add this line to your .bashrc / .zshrc / whatever)* 6. Download soundcloakctl:
Soundcloakctl is helper for soundcloak.
```sh ```sh
export PATH=${PATH}:`go env GOPATH`/bin go install git.maid.zone/stuff/soundcloakctl@master
``` ```
6. Build binary:
7. Download requried JS modules:
```sh
soundcloakctl js download
```
8. Build binary:
This uses the `build` script, which generates code from templates, generates code for regular expiressions, and then builds the binary. This uses the `build` script, which generates code from templates, generates code for regular expiressions, and then builds the binary.
@@ -61,13 +75,15 @@ git pull
2. Update dependencies/tools: 2. Update dependencies/tools:
```sh ```sh
npm i # for hls.js go get # for go packages
go get # for other go packages
go install github.com/a-h/templ/cmd/templ@latest # templ cli go install github.com/a-h/templ/cmd/templ@latest # templ cli
go install github.com/dlclark/regexp2cg@main # regexp2 codegen cli. not required unless you've installed it go install github.com/dlclark/regexp2cg@main # regexp2 codegen cli. not required unless you've installed it
go install git.maid.zone/stuff/soundcloakctl@master # soundcloakctl
soundcloakctl js download # re-download JS modules
``` ```
3. Clean precompressed static files 3. Clean precompressed static files

0
instance/.gitkeep Normal file
View File

View File

@@ -41,9 +41,9 @@ func main() {
} }
app.Use(compress.New(compress.Config{Level: compress.LevelBestSpeed})) app.Use(compress.New(compress.Config{Level: compress.LevelBestSpeed}))
app.Static("/", "instance", fiber.Static{Compress: true, MaxAge: 7200}) // 2 hours app.Static("/", "instance", fiber.Static{Compress: true, MaxAge: 7200}) // 2 hours
app.Static("/", "assets", fiber.Static{Compress: true, MaxAge: 14400}) // 4 hours app.Static("/", "assets", fiber.Static{Compress: true, MaxAge: 14400}) // 4 hours
app.Static("/js/hls.js/", "node_modules/hls.js/dist", fiber.Static{Compress: true, MaxAge: 28800}) // 8 hours app.Static("/js/", "external", fiber.Static{Compress: true, MaxAge: 28800}) // 8 hours
// Just for easy inspection of cache in development. Since debug is constant, the compiler will just remove the code below if it's set to false, so this has no runtime overhead. // Just for easy inspection of cache in development. Since debug is constant, the compiler will just remove the code below if it's set to false, so this has no runtime overhead.
if cfg.Debug { if cfg.Debug {

View File

@@ -48,7 +48,7 @@ templ TrackHeader(prefs cfg.Preferences, t sc.Track, needPlayer bool) {
<meta name="og:image" content={ t.Artwork }/> <meta name="og:image" content={ t.Artwork }/>
<link rel="icon" type="image/x-icon" href={ t.Artwork }/> <link rel="icon" type="image/x-icon" href={ t.Artwork }/>
if needPlayer && *prefs.Player == cfg.HLSPlayer { if needPlayer && *prefs.Player == cfg.HLSPlayer {
<script src="/js/hls.js/hls.light.min.js"></script> <script src="/js/hls.light.min.js"></script>
} }
} }