From 3be1bffd0145bcf497af77ac3200b3d6a0540234 Mon Sep 17 00:00:00 2001 From: Laptop Date: Mon, 10 Feb 2025 18:40:11 +0200 Subject: [PATCH] Network config option and bump go ver with deps --- Dockerfile | 2 +- docs/INSTANCE_GUIDE.md | 50 ++++++++++++++++++++++-------------------- go.mod | 8 +++---- go.sum | 12 +++++----- lib/cfg/init.go | 13 +++++++++++ main.go | 2 +- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea9ead6..46dcd31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG GO_VERSION=1.23.5 +ARG GO_VERSION=1.23.6 FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build ARG TARGETOS diff --git a/docs/INSTANCE_GUIDE.md b/docs/INSTANCE_GUIDE.md index 2345fd8..213a0aa 100644 --- a/docs/INSTANCE_GUIDE.md +++ b/docs/INSTANCE_GUIDE.md @@ -43,6 +43,7 @@ Soundcloak will now be up at `127.0.0.1:4664` (or the address you specified in y ## Regular method ** Not recommended for deployment. ** + Refer to the [developer guide](DEV_GUIDE.md#setup) # Updating your instance @@ -97,31 +98,32 @@ Some notes: - When specifying time, specify it in seconds. -| JSON key | Environment variable | Default value | Description | -| ------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| None | SOUNDCLOAK_CONFIG | soundcloak.json | File to load soundcloak config from. If set to `FROM_ENV`, soundcloak loads the config from environment variables. | -| GetWebProfiles | GET_WEB_PROFILES | true | Retrieve links users set in their profile (social media, website, etc) | -| DefaultPreferences | DEFAULT_PREFERENCES | {"Player": "hls", "ProxyStreams": false, "FullyPreloadTrack": false, "ProxyImages": false, "ParseDescriptions": true, "AutoplayNextTrack": false, "DefaultAutoplayMode": "normal", "HLSAudio": "mpeg", "RestreamAudio": "mpeg", "DownloadAudio": "mpeg"} | see /_/preferences page. [Read more](PREFERENCES.md) | -| ProxyImages | PROXY_IMAGES | false | Enables proxying of images (user avatars, track covers etc) | -| ImageCacheControl | IMAGE_CACHE_CONTROL | max-age=600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for proxied images. Cached for 10 minutes by default. | -| ProxyStreams | PROXY_STREAMS | false | Enables proxying of song parts and hls playlist files | -| Restream | RESTREAM | false | Enables Restream Player in settings and the /_/restream/:author/:track endpoint. This player can be used without JavaScript. Restream also enables the button for downloading songs. | -| RestreamCacheControl | RESTREAM_CACHE_CONTROL | max-age=3600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for restreamed songs. Cached for 1 hour by default. | -| ClientIDTTL | CLIENT_ID_TTL | 4 hours | Time until ClientID cache expires. ClientID is used for authenticating with SoundCloud API | -| UserTTL | USER_TTL | 20 minutes | Time until User profile cache expires | -| UserCacheCleanDelay | USER_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired users) | -| TrackTTL | TRACK_TTL | 20 minutes | Time until Track data cache expires | -| TrackCacheCleanDelay | TRACK_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired tracks) | -| PlaylistTTL | PLAYLIST_TTL | 20 minutes | Time until Playlist data cache expires | -| PlaylistCacheCleanDelay | PLAYLIST_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired playlists) | -| UserAgent | USER_AGENT | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.3 | User-Agent header used for requests to SoundCloud | -| DNSCacheTTL | DNS_CACHE_TTL | 60 minutes | Time until DNS cache expires | -| Addr | ADDR | :4664 | Address and port for soundcloak to listen on | -| Prefork | PREFORK | false | Run multiple instances of soundcloak locally to be able to handle more requests. Each one will be a separate process, so they will have separate cache. | -| TrustedProxyCheck | TRUSTED_PROXY_CHECK | true | Use X-Forwarded-* headers if IP is in TrustedProxies list. When disabled, those headers will blindly be used. | -| TrustedProxies | TRUSTED_PROXIES | [] | List of IPs or IP ranges of trusted proxies | +| JSON key | Environment variable | Default value | Description | +| ------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| None | SOUNDCLOAK_CONFIG | soundcloak.json | File to load soundcloak config from. If set to `FROM_ENV`, soundcloak loads the config from environment variables. | +| GetWebProfiles | GET_WEB_PROFILES | true | Retrieve links users set in their profile (social media, website, etc) | +| DefaultPreferences | DEFAULT_PREFERENCES | {"Player": "hls", "ProxyStreams": false, "FullyPreloadTrack": false, "ProxyImages": false, "ParseDescriptions": true, "AutoplayNextTrack": false, "DefaultAutoplayMode": "normal", "HLSAudio": "mpeg", "RestreamAudio": "mpeg", "DownloadAudio": "mpeg", "ShowAudio": false, "SearchSuggestions": false, "DynamicLoadComments": false} | see /_/preferences page. [Read more](PREFERENCES.md) | +| ProxyImages | PROXY_IMAGES | false | Enables proxying of images (user avatars, track covers etc) | +| ImageCacheControl | IMAGE_CACHE_CONTROL | max-age=600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for proxied images. Cached for 10 minutes by default. | +| ProxyStreams | PROXY_STREAMS | false | Enables proxying of song parts and hls playlist files | +| Restream | RESTREAM | false | Enables Restream Player in settings and the /_/restream/:author/:track endpoint. This player can be used without JavaScript. Restream also enables the button for downloading songs. | +| RestreamCacheControl | RESTREAM_CACHE_CONTROL | max-age=3600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for restreamed songs. Cached for 1 hour by default. | +| ClientIDTTL | CLIENT_ID_TTL | 4 hours | Time until ClientID cache expires. ClientID is used for authenticating with SoundCloud API | +| UserTTL | USER_TTL | 20 minutes | Time until User profile cache expires | +| UserCacheCleanDelay | USER_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired users) | +| TrackTTL | TRACK_TTL | 20 minutes | Time until Track data cache expires | +| TrackCacheCleanDelay | TRACK_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired tracks) | +| PlaylistTTL | PLAYLIST_TTL | 20 minutes | Time until Playlist data cache expires | +| PlaylistCacheCleanDelay | PLAYLIST_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired playlists) | +| UserAgent | USER_AGENT | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.3 | User-Agent header used for requests to SoundCloud | +| DNSCacheTTL | DNS_CACHE_TTL | 60 minutes | Time until DNS cache expires | +| Network | NETWORK | tcp4 | Network to listen on. Can be tcp4, tcp6 or unix | +| Addr | ADDR | :4664 | Address and port for soundcloak to listen on | +| Prefork | PREFORK | false | Run multiple instances of soundcloak locally to be able to handle more requests. Each one will be a separate process, so they will have separate cache. | +| TrustedProxyCheck | TRUSTED_PROXY_CHECK | true | Use X-Forwarded-* headers if IP is in TrustedProxies list. When disabled, those headers will blindly be used. | +| TrustedProxies | TRUSTED_PROXIES | [] | List of IPs or IP ranges of trusted proxies | | CodegenConfig | CODEGEN_CONFIG | false | Highly recommended to enable. Embeds the config into the binary, which helps reduce size if you aren't using certain features and generally optimize the binary better. Keep in mind that you will have to rebuild the image/binary each time you want to change config. (Note: you need to run `soundcloakctl config codegen` or use docker, as it runs it for you) | -| EmbedFiles | EMBED_FILES | false | Embed files into the binary. Keep in mind that you will have to rebuild the image/binary each time you update static files (e.g. custom instance files) | +| EmbedFiles | EMBED_FILES | false | Embed files into the binary. Keep in mind that you will have to rebuild the image/binary each time static files are changed (e.g. custom instance files) | diff --git a/go.mod b/go.mod index 2e4fcd7..d575e52 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.maid.zone/stuff/soundcloak -go 1.23.5 +go 1.23.6 require ( github.com/a-h/templ v0.3.833 @@ -30,8 +30,8 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect github.com/x448/float16 v0.8.4 // indirect - golang.org/x/crypto v0.32.0 // indirect + golang.org/x/crypto v0.33.0 // indirect golang.org/x/net v0.34.0 // indirect - golang.org/x/sys v0.29.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect ) diff --git a/go.sum b/go.sum index 67c3458..3ded508 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,8 @@ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3i github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= -golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -90,16 +90,16 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/lib/cfg/init.go b/lib/cfg/init.go index 6a32ca1..7c0d25b 100644 --- a/lib/cfg/init.go +++ b/lib/cfg/init.go @@ -76,6 +76,10 @@ var DNSCacheTTL = 60 * time.Minute // run soundcloak on this address (localhost:4664 by default) var Addr = ":4664" +// where to listen +// can be tcp4 (bind to ipv4 address), tcp6 (bind to ipv6 address) or unix (bind to unix socket) +var Network = "tcp4" + // run multiple instances of soundcloak locally to be able to handle more requests // each one will be a separate process, so they will have separate cache var Prefork = false @@ -376,6 +380,11 @@ func fromEnv() error { DNSCacheTTL = time.Duration(num) * time.Second } + env = os.Getenv("NETWORK") + if env != "" { + Network = env + } + env = os.Getenv("ADDR") if env != "" { Addr = env @@ -458,6 +467,7 @@ func init() { PlaylistCacheCleanDelay *time.Duration UserAgent *string DNSCacheTTL *time.Duration + Network *string Addr *string Prefork *bool TrustedProxyCheck *bool @@ -523,6 +533,9 @@ func init() { if config.DNSCacheTTL != nil { DNSCacheTTL = *config.DNSCacheTTL * time.Second } + if config.Network != nil { + Network = *config.Network + } if config.Addr != nil { Addr = *config.Addr } diff --git a/main.go b/main.go index aa1acc3..47af6c4 100644 --- a/main.go +++ b/main.go @@ -1036,5 +1036,5 @@ Disallow: /`) if cfg.CodegenConfig { log.Println("Warning: you have CodegenConfig enabled, but the config was loaded dynamically.") } - log.Fatal(app.Listen(cfg.Addr, fiber.ListenConfig{EnablePrefork: cfg.Prefork, DisableStartupMessage: true})) + log.Fatal(app.Listen(cfg.Addr, fiber.ListenConfig{EnablePrefork: cfg.Prefork, DisableStartupMessage: true, ListenerNetwork: cfg.Network})) }