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

Proxy backend with caddy #192

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ yarn-debug.log*
yarn-error.log
mongodb-data
mopidy-data
caddy_*
node_modules
.pnp.*
.yarn/*
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,38 @@ You can also just ignore `make` and run everything manual if that's your thing.

### Running the app

When running the app locally you get to run a Docker instance of Mopidy on your machine. You don't get any sound but it's by far the easiest way. You just need to run:
When running the app locally you can use Docker to run the services required along side:

Build the dependencies MongoDB and Mopidy
```
make build
```
- `mongodb`
- `mopidy` (NOTE: You don't get any sound)
- `caddy` Webserver (optional if you want everything running over HTTPS)

Note: If you are using an M1 Macbook, the above command may fail. To fix this, you will need to set the following environment variable in your shell:
You will need to build the Mopidy Image
```
DOCKER_DEFAULT_PLATFORM=linux/amd64
# If you are on an M1 mac you will need
$ DOCKER_DEFAULT_PLATFORM=linux/amd64 make build

# otherwise you can just run
$ make build
```

Start the dependencies MongoDB and Mopidy
You can now start the dependencies:
```
make start
make start args=-D # run in the background
# start just mongodb and mongodb
$ make start services=mongodb mopidy # caddy (optional)

# all service in the background
$ make start args=-D
```

Now you can just open a new terminal for the FE and the BE and run:

```
make fe-server
$ make be-server
```
and
```
make be-server
$ make fe-server
```

This will give you a working FE and BE plus the persistence layer. The Jukebox is available
Expand Down
3 changes: 3 additions & 0 deletions backend/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:443 {
reverse_proxy 127.0.0.1:8080
}
13 changes: 13 additions & 0 deletions backend/jukebox-api-proxy.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Kyan Jukebox API Proxy using Caddy
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/caddy run -config /home/jukebox/app/current/backend/Caddyfile

Restart=always
# Restart service after 10 seconds if service crashes
RestartSec=10
User=jukebox
Group=jukebox
8 changes: 6 additions & 2 deletions backend/shipitfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')

module.exports = shipit => {
module.exports = (shipit) => {
require('shipit-deploy')(shipit)

shipit.initConfig({
Expand All @@ -20,7 +20,7 @@ module.exports = shipit => {
})

shipit.on('published', function () {
shipit.start(['restart_daemon', 'restart_api_service'])
shipit.start(['restart_daemon', 'restart_api_service', 'restart_api_proxy_service'])
})

shipit.on('updated', function () {
Expand All @@ -44,4 +44,8 @@ module.exports = shipit => {
shipit.blTask('restart_api_service', function () {
return shipit.remote('sudo /bin/systemctl restart jukebox-api.service')
})

shipit.blTask('restart_api_proxy_service', function () {
return shipit.remote('sudo /bin/systemctl restart jukebox-api-proxy.service')
})
}
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ services:
- MOPIDY_PASSWORD=${MOPIDY_PASSWORD}
- MOPIDY_CLIENT_ID=${MOPIDY_CLIENT_ID}
- MOPIDY_CLIENT_SECRET=${MOPIDY_CLIENT_SECRET}
caddy:
image: caddy:2.0.0-alpine
ports:
- 80:80
- 443:443
volumes:
- $PWD/frontend/Caddyfile:/etc/caddy/Caddyfile
- ./caddy_data:/data
- ./caddy_config:/config
2 changes: 1 addition & 1 deletion frontend/src/middleware/jukebox-middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ActionInterface extends Action {
}

const JukeboxMiddleware: Middleware = (() => {
const url = `http://${process.env.REACT_APP_WS_URL}:${process.env.REACT_APP_WS_PORT}`
const url = `${process.env.REACT_APP_WS_URL}:${process.env.REACT_APP_WS_PORT}`
let socket: Socket
let progressTimer: any = null

Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build:
docker-compose build

start:
docker-compose $(args) up
docker-compose $(args) up $(services)

fe-serve:
make fe task=start
Expand Down