mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 05:39:38 +05:00
Drop dependency on npm (downloading required js modules via soundcloakctl)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
Dockerfile
|
||||
*.yaml
|
||||
build
|
||||
.github
|
||||
.gitignore
|
||||
soundcloak.example.json
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -17,3 +17,5 @@ regexp2_codegen.go
|
||||
|
||||
# built binary
|
||||
main
|
||||
|
||||
!.gitkeep
|
||||
@@ -15,22 +15,19 @@ RUN go generate ./lib/*
|
||||
|
||||
RUN go install git.maid.zone/stuff/soundcloakctl@master
|
||||
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 echo "soundcloak:x:5000:5000:Soundcloak user:/:/sbin/nologin" > /etc/minimal-passwd && \
|
||||
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
|
||||
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
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=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-group /etc/group
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# Setup
|
||||
## Prerequisites
|
||||
1. [node.js + npm](https://nodejs.org) (any recent enough version should do, it's just used for getting hls.js builds)
|
||||
2. [golang](https://go.dev) (I recommend version 1.22.10. Technically, you need 1.21.4 or higher)
|
||||
3. [git](https://git-scm.com)
|
||||
1. [golang](https://go.dev) (I recommend version 1.22.10. Technically, you need 1.21.4 or higher)
|
||||
2. [git](https://git-scm.com)
|
||||
|
||||
## The setup
|
||||
1. Clone this repository:
|
||||
@@ -29,6 +28,12 @@ npm i
|
||||
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:
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
*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
|
||||
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.
|
||||
|
||||
@@ -61,13 +75,15 @@ git pull
|
||||
|
||||
2. Update dependencies/tools:
|
||||
```sh
|
||||
npm i # for hls.js
|
||||
|
||||
go get # for other go packages
|
||||
go get # for go packages
|
||||
|
||||
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 git.maid.zone/stuff/soundcloakctl@master # soundcloakctl
|
||||
|
||||
soundcloakctl js download # re-download JS modules
|
||||
```
|
||||
|
||||
3. Clean precompressed static files
|
||||
|
||||
0
instance/.gitkeep
Normal file
0
instance/.gitkeep
Normal file
2
main.go
2
main.go
@@ -43,7 +43,7 @@ func main() {
|
||||
|
||||
app.Static("/", "instance", fiber.Static{Compress: true, MaxAge: 7200}) // 2 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.
|
||||
if cfg.Debug {
|
||||
|
||||
@@ -48,7 +48,7 @@ templ TrackHeader(prefs cfg.Preferences, t sc.Track, needPlayer bool) {
|
||||
<meta name="og:image" content={ t.Artwork }/>
|
||||
<link rel="icon" type="image/x-icon" href={ t.Artwork }/>
|
||||
if needPlayer && *prefs.Player == cfg.HLSPlayer {
|
||||
<script src="/js/hls.js/hls.light.min.js"></script>
|
||||
<script src="/js/hls.light.min.js"></script>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user