config codegen

This commit is contained in:
Laptop
2024-12-24 12:05:57 +02:00
parent f79bf02635
commit b5b231dca7
3 changed files with 51 additions and 29 deletions

View File

@@ -13,6 +13,9 @@ RUN templ generate
RUN go install github.com/dlclark/regexp2cg@main
RUN go generate ./lib/*
RUN go install github.com/maid-zone/soundcloakctl@master
RUN soundcloakctl config codegen
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

View File

@@ -1,19 +1,23 @@
# Setup
## Docker
You need to have [Docker](https://docker.com) and [Git](https://git-scm.com) installed.
1. Clone this repository:
```sh
git clone https://github.com/maid-zone/soundcloak
```
2. Go into the cloned repository:
```sh
cd soundcloak
```
3. Make a copy of the example compose.yaml file:
```sh
cp compose.example.yaml compose.yaml
```
@@ -22,8 +26,8 @@ Make adjustments as needed.
4. *Optional.* Edit config:
Refer to [Configuration guide](#configuration-guide) for configuration information. Can be configured from environment variables or JSON file.
5. Run the container:
```sh
docker compose up -d
```
@@ -32,32 +36,37 @@ You might need to use `sudo` if you aren't running as root.
Use `docker-compose` instead of `docker compose` if that fails.
Soundcloak will now be up at `127.0.0.1:4664` (or the address you specified in your config). I recommend you run it through a reverse proxy (caddy, nginx, etc.)
## Regular method
Refer to the [developer guide](DEV_GUIDE.md#setup)
# Updating your instance
## Docker
1. Retrieve the latest code:
```sh
git fetch origin
git pull
```
2. Stop the container:
```sh
docker container stop soundcloak
```
3. Build the container with updated source code:
```sh
docker compose build
```
4. Start the container:
```sh
docker compose up -d
```
@@ -65,11 +74,13 @@ docker compose up -d
Use `docker-compose` instead of `docker compose` if that fails.
## Regular method
Refer to the [developer guide](DEV_GUIDE.md#updating-your-local-setup)
# Configuration/customization
## Configuration guide
<details>
<summary>Click to view</summary>
@@ -84,7 +95,7 @@ Some notes:
| 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) |
@@ -106,6 +117,7 @@ Some notes:
| 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 | Mainly needed for the dockerfile. If you enable this, and build the container (or run `soundcloakctl config codegen`) - your current config will be parsed and embedded in the code, which allows the compiler to do some more optimizations. Keep in mind that you won't be able to change the config dynamically, you will have to rebuild the container / binary |
</details>
@@ -128,6 +140,7 @@ The static files are stored in `assets` folder
1. Create `instance.css` file in the `instance` folder
2. Put your CSS rules there:
```css
/* Some basic CSS to change colors of the frontend. Put your own colors here as this one probably looks horrible (I did not test it) */
:root {
@@ -148,6 +161,7 @@ Refer to `assets/global.css` file for existing rules.
To get listed on [the instance list](https://maid.zone/soundcloak/instances.html), create a discussion with some information about your instance, or [reach out privately](https://laptopc.at)
Basic rules:
1. Do not collect user information (either yourself, or by including 3rd party tooling which does that)
2. If you are modifying the source code, publish those changes somewhere. Even if it's just static files, it would be best to publish those changes somewhere.

View File

@@ -37,7 +37,9 @@ func main() {
TrustedProxies: cfg.TrustedProxies,
})
if !cfg.Debug {
app.Use(recover.New())
}
app.Use(compress.New(compress.Config{Level: compress.LevelBestSpeed}))
app.Static("/", "instance", fiber.Static{Compress: true, MaxAge: 7200}) // 2 hours
@@ -811,5 +813,8 @@ func main() {
return templates.Base(track.Title+" by "+track.Author.Username, templates.TrackInAlbums(track, p), templates.TrackHeader(prefs, track, false)).Render(context.Background(), c)
})
if cfg.CodegenConfig {
log.Println("Warning: you have CodegenConfig enabled, but the config was loaded dynamically.")
}
log.Fatal(app.Listen(cfg.Addr))
}