Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cadence Stack Reverse Proxy (Redo) #235

Merged
merged 11 commits into from
Feb 26, 2023
Merged

Cadence Stack Reverse Proxy (Redo) #235

merged 11 commits into from
Feb 26, 2023

Conversation

kenellorando
Copy link
Owner

@kenellorando kenellorando commented Feb 24, 2023

This PR is a redo of #233. #233 originally introduced the reverse proxy service, but broke the rate limiter and SSE, so I'm back again with a more thoughtful approach.

Reverse Proxy Service

The main feature of this PR is a built-in Reverse Proxy service provided by an nginx container which routes inbound connections to the API server and Icecast stream.

Cadence users can now easily serve their radios publicly by simply providing the reverse proxy service with their own domain names.

This naturally forced about some improvements to other parts of Cadence, as you will see.

cadenceradio.com demo deployed using Compose

In order to actually test the reverse proxy service in a production environment, I've moved the demo site, CadenceRadio.com, off my Kubernetes cluster and onto a "traditional" Linux Server using Cadence's Docker Compose.

I had it on my Kubernetes cluster mostly for personal interest reasons, but I may actually keep it deployed through Compose for the foreseeable future since it's how I expect users to actually run their Cadence stacks anyway.

I opened #236 to hopefully make installation for the user even easier.

Rate Limiter Updated

We introduce a better rate limiter IP checker that works with or without the new reverse proxy.

func checkIP(r *http.Request) (ip string, err error) {
// We look at the remote address and check the IP.
// If for some reason no remote IP is there, we error to reject.
if r.RemoteAddr != "" {
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil || ip == "" {
return "", err
}
return ip, nil
}
return "", err
}

Reliable SSE

The default reverse proxy configuration provided also reliably handles SSE connections.

location /api/radiodata/sse {
proxy_read_timeout 86400;
proxy_send_timeout 86400;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
proxy_pass http://cadence:8080/api/radiodata/sse;
}

UI code is also modified so it will try to close its current SSE connection when it encounters an error before trying to create a new connection.

Error Handling

We added some handling for specific errors related to Postgres DB startup. If a Cadence replica is launched and the metadata database or table already exist, it won't skip repopulation.

_, err = dbp.Exec(createTable)
if err != nil {
if err.(*pq.Error).Code == "42P07" {
// 42P10 indicates an existing metadata table configured by another Cadence instance is still running.
clog.Info("postgresInit", "Metadata database already exists")
} else {
clog.Error("postgresPopulate", "Failed to build database table!", err)
return err
}
}

Reorganization

The repository has been reorganized so there is no longer a top-level directory for Icecast or Liquidsoap. Their Dockerfiles have been moved within a new stream/ directory.

All config files meant for the user to configure have been moved to a new top-level config/ directory. With everything in one place now and renamed with clarity, it should be simpler for someone to set up a stack.

Minor Code Updates

  • We do a handful of other things in the Docker Compose, such as correcting usage of expose vs ports, and correcting context to a more accurate dockerfile.
  • The Compose and Makefile have been updated to support the newly reorganized repository.
  • The Icecast monitor is slightly reorganized.
  • Fixed incorrect logging names.
  • Trimmed whitespace from search API input.
  • New architecture diagram.

This fixes #227.

@kenellorando kenellorando added the domain: all Relates to project meta or repository label Feb 24, 2023
@kenellorando kenellorando self-assigned this Feb 24, 2023
@kenellorando kenellorando added domain: cadence-icecast2 Relates to cadence-icecast2 stream service domain: cadence-liquidsoap Relates to cadence-liquidsoap audio service domain: cadence-api Relates to cadence API and removed domain: all Relates to project meta or repository labels Feb 24, 2023
@kenellorando kenellorando marked this pull request as ready for review February 25, 2023 06:33
@kenellorando kenellorando merged commit db0be45 into master Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: cadence-api Relates to cadence API domain: cadence-icecast2 Relates to cadence-icecast2 stream service domain: cadence-liquidsoap Relates to cadence-liquidsoap audio service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cadence stack reverse proxy
1 participant