Skip to content

Commit

Permalink
Merge pull request #233 from kenellorando/reverse-proxy
Browse files Browse the repository at this point in the history
Cadence Stack Reverse Proxy
  • Loading branch information
kenellorando authored Feb 23, 2023
2 parents 6df69a3 + c0bd20e commit c223d92
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ build-init:
docker buildx create --platform linux/arm/v7,linux/amd64 --use --name multiarch

build-cadence:
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence:latest --tag kenellorando/cadence:$(VERSION) --file ./cadence/Dockerfile.multiarch ./cadence/
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence:latest --tag kenellorando/cadence:$(VERSION) --file ./cadence/server/Dockerfile.multiarch ./cadence/

build-cadence_icecast2:
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence_icecast2:latest --tag kenellorando/cadence_icecast2:$(VERSION) --file ./cadence_icecast2/Dockerfile ./cadence_icecast2/
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence_icecast2:latest --tag kenellorando/cadence_icecast2:$(VERSION) --file ./cadence/stream/Dockerfile.icecast2 ./cadence/stream/

build-cadence_liquidsoap:
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence_liquidsoap:latest --tag kenellorando/cadence_liquidsoap:$(VERSION) --file ./cadence_liquidsoap/Dockerfile ./cadence_liquidsoap/
docker buildx build --push --platform linux/arm/v7,linux/amd64 --tag kenellorando/cadence_liquidsoap:latest --tag kenellorando/cadence_liquidsoap:$(VERSION) --file ./cadence/stream/Dockerfile.liquidsoap ./cadence/stream/

build-all: build-cadence build-cadence_icecast2 build-cadence_liquidsoap
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# CadenceRadio

**Cadence** is an all-in-one web radio suite, allowing you to start a self-hosted internet radio website in minutes.
**Cadence** is an all-in-one web radio suite that you can use to start a self-hosted radio website in minutes.

The project ships with _Icecast_ and _Liquidsoap_ built-in, complemented by a _Cadence_ API server providing music search, song request, artwork, a UI, and real-time stream information.

Cadence ships all components mostly pre-configured with each each other so there is hardly any configuration required. Simply set a target directory containing your music files, set a few service passwords and hostnames, and you're done! The Cadence stack can be deployed in a single command.
Cadence ships all components mostly pre-configured with each each other so there is hardly any configuration required. Simply set a target directory containing your music files, set a few service passwords and hostnames, and deploy!

**Try the live demo! [cadenceradio.com](https://cadenceradio.com/)**
**[Try the live demo!](https://cadenceradio.com/)**

## 🖼️ Image Gallery
<details>
Expand All @@ -19,7 +19,7 @@ Cadence ships all components mostly pre-configured with each each other so there
<details>
<summary>Cadence Architecture</summary>

![cadence5 architecture](https://user-images.githubusercontent.com/17265041/185465196-66fc2249-e43a-46f7-a12f-dbde9aaf8172.png)
![cadence5.3 architecture](https://user-images.githubusercontent.com/17265041/220829527-411f76ca-884f-4bf4-8b44-3afeaca158fa.png)

</details>

Expand All @@ -29,38 +29,38 @@ Cadence ships all components mostly pre-configured with each each other so there
1. You must have Docker installed. If you are on a Linux server, install the [Compose plugin](https://docs.docker.com/compose/install/linux/).

### Installation
1. Edit `cadence/config/cadence.env`.
1. Set the `POSTGRES_PASSWORD` from `hackme` to a new password.
2. Set `CSERVER_MUSIC_DIR` to an absolute path of a directory on your system which contains music files (`.mp3`, `.flac`) to play. The target is not recursively searched. The default value is `/music/`.
3. Set `CSERVER_REQRATELIMIT` to an integer value that represents a song request cooldown period in seconds. Set this value to `0` to disable request rate limiting. The default value is `180`.
2. Edit `cadence_icecast2/config/cadence.xml`.
1. Fork or clone the repository.
2. Edit `config/cadence.env`
1. Change all instances of `hackme` to a new password.
2. Set the `<hostname>` value to a URL you expect your audience to connect to. Cadence uses this value to set the stream source in the UI. This may be a DNS name or a public or internal IP address. You can leave the default value `localhost` if your radio is meant to be accessible locally only.
3. Edit `cadence_liquidsoap/config/cadence.liq`:
2. Set `CSERVER_MUSIC_DIR` to an absolute path which contains music files (`.mp3`, `.flac`) for play. The target is not recursively searched. The default value is `/music/`.
3. Set `CSERVER_REQRATELIMIT` to an integer that sets the song request cooldown period in seconds. Set this value to `0` to disable rate limiting. The default value is `180`.
3. Edit `config/icecast.xml`
1. Change all instances of `hackme` to a new password.
2. If you changed the `CSERVER_MUSIC_DIR` value in step 1, change any instances of the default value `/music/` to match it here.
4. `docker compose up`
1. On older versions of Docker, use `docker-compose up` instead.
2. Set the `<hostname>` value to a URL you expect your audience to connect to. This value is what is set in the UI's stream source. This may be a DNS name or a public or private IP address. You can leave the default value `localhost` if your radio is meant to be accessible locally only.
4. Edit `config/liquidsoap.liq`
1. Change all instances of `hackme` to a new password.
2. If you changed `CSERVER_MUSIC_DIR` in step 1, change any instances of the default value `/music/` to match it here.
5. (_Optional_) Edit `config/nginx.conf`
1. For advanced users deploying Cadence to a server with DNS, Cadence ships with a reverse proxy which will forward requests based on domain-name to backend services. Simply configure the `server_name` values with your domain names.
6. `docker compose up`

### Accessing Services
Assuming no changes were made to port numbers or the hostnames during installation:

- The UI is accessible in a browser at `localhost:8080`
- API server requests may also be sent to the `localhost:8080` path. See the API Reference for more details.
- The audio stream is accessible at `localhost:8000/cadence1`.
- Assuming you kept the default values above, Cadence will become accessible in a browser at `localhost:8080`.
- If you optionally followed step 5 to make Cadence publicly accessible, open firewall port `80` and point DNS to your server.

## 👩‍💻 Developing

### Building the Stack
If you are changing code and need to rebuild exactly what you have, use the `--build` flag.
If you changed code or updated a container image, and need to rebuild exactly what you have, use the `--build` flag.

1. `docker compose down; docker compose up --build`
`docker compose down; docker compose up --build`

### Development Mode
Cadence provides special administrative control that may be useful for testing though an API that may be optionally enabled. As the name implies, don't enable development mode on a production server.
### Enable Development API
Cadence provides special administrative controls that may be useful for testing though an optionally enabled API. Don't enable development mode on a production server. See the API reference for more details.

1. Edit `cadence/config/cadence.env`.
1. Set `CSERVER_DEVMODE` from `0` (disabled) to `1` (enabled).
1. Edit `config/cadence.env`.
1. Set `CSERVER_DEVMODE` to `1` (enabled).

### API Reference
[Cadence's API Reference](https://github.com/kenellorando/cadence/wiki/API-Reference) provides usage details and complete request/response examples.
Interested in developing custom scripts or clients for your Cadence Radio? [Cadence's API Reference](https://github.com/kenellorando/cadence/wiki/API-Reference) provides usage details and complete request/response examples.
File renamed without changes.
File renamed without changes.
8 changes: 1 addition & 7 deletions cadence/server/db_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ func postgresInit() (err error) {
if err != nil {
if err.(*pq.Error).Code == "42710" {
// 42710 also indicates an existing Postgres instance configured by another Cadence instance is still running.
clog.Debug("postgresInit", "fuzzystrmatch already enabled on metadata database.")
clog.Info("postgresInit", "fuzzystrmatch already enabled on metadata database.")
} else {
clog.Error("postgresInit", "Failed to enable fuzzystrmatch. Search may be degraded.", err)
return err
}
}
// We start an initial population now regardless if we know the database already exists
// in case there are no other running Cadence instances already running.
postgresPopulate()
if err != nil {
clog.Error("postgresConfig", "Failed to complete initial metadata population.", err)
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion cadence/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ func main() {
clog.Level(c.LogLevel)
clog.Debug("init", fmt.Sprintf("Cadence Logger initialized to level <%v>.", c.LogLevel))

redisInit()
postgresInit()
postgresPopulate()
go redisInit()
go filesystemMonitor()
go icecastMonitor()

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cadence/config/cadence.env → config/cadence.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ POSTGRES_PASSWORD=hackme

# Development
CSERVER_DEVMODE=0
CSERVER_VERSION=5.2.0
CSERVER_VERSION=5.3.0
CSERVER_LOGLEVEL=4
CSERVER_ROOTPATH=/cadence/server/

Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
events {
worker_connections 1024;
}

http {
# This server forwards requests to the Icecast service.
server {
listen 80;
server_name stream.cadenceradio.com;
access_log off;
location / {
proxy_pass http://icecast2:8000/;
}
}

# This server forwards requests to the API/UI server.
server {
listen 80;
server_name cadenceradio.com;
access_log off;
location / {
proxy_pass http://cadence:8080/;
}
}
}
43 changes: 28 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ services:
redis:
image: redis/redis-stack-server:latest
container_name: redis
ports:
- 6379:6379
expose:
- 6379
networks:
internal_services:

postgres:
image: postgres:15-alpine
container_name: postgres
ports:
- 5432:5432
expose:
- 5432
env_file:
- ./cadence/config/cadence.env
- ./config/cadence.env
networks:
internal_services:

icecast2:
build:
context: ./cadence_icecast2/
image: kenellorando/cadence_icecast2
build:
dockerfile: ./cadence/stream/Dockerfile.icecast2
image: kenellorando/cadence_icecast2:latest
container_name: icecast2
restart: always
ports:
- 8000:8000
volumes:
- ./cadence_icecast2/config/cadence.xml:/etc/icecast/cadence.xml
- ./config/icecast.xml:/etc/icecast/cadence.xml
networks:
external_services:
stream_delivery:

liquidsoap:
build:
context: ./cadence_liquidsoap/
image: kenellorando/cadence_liquidsoap
build:
dockerfile: ./cadence/stream/Dockerfile.liquidsoap
image: kenellorando/cadence_liquidsoap:latest
container_name: liquidsoap
restart: always
volumes:
- ./cadence_liquidsoap/config/cadence.liq:/etc/liquidsoap/cadence.liq
- ./config/liquidsoap.liq:/etc/liquidsoap/cadence.liq
- /music:/music
depends_on:
- icecast2
Expand All @@ -52,14 +52,14 @@ services:

cadence:
build:
context: ./cadence/
context: ./cadence/server/
image: kenellorando/cadence
container_name: cadence
restart: always
ports:
- 8080:8080
env_file:
- ./cadence/config/cadence.env
- ./config/cadence.env
volumes:
- /music:/music
depends_on:
Expand All @@ -71,6 +71,19 @@ services:
internal_services:
external_services:

nginx:
image: nginx:latest
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
container_name: nginx
restart: on-failure
ports:
- 80:80
depends_on:
- cadence
networks:
external_services:

networks:
external_services:
driver: bridge
Expand Down

0 comments on commit c223d92

Please sign in to comment.