From 4bf1637648cf3573ddfceb4070f9ff2638d1f51c Mon Sep 17 00:00:00 2001 From: Josh Jimenez Bedrock Date: Wed, 2 Feb 2022 16:51:10 +0000 Subject: [PATCH 1/8] Caddy config file for backend --- backend/Caddyfile | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backend/Caddyfile diff --git a/backend/Caddyfile b/backend/Caddyfile new file mode 100644 index 0000000..9e56f3d --- /dev/null +++ b/backend/Caddyfile @@ -0,0 +1,3 @@ +:443 { + reverse_proxy 127.0.0.1:8080 +} From 7729ac5c80950db1a7b786a3c16c5d2dbc4ad806 Mon Sep 17 00:00:00 2001 From: Josh Jimenez Bedrock Date: Wed, 2 Feb 2022 17:12:12 +0000 Subject: [PATCH 2/8] Caddy service file --- backend/jukebox-api-proxy.service | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 backend/jukebox-api-proxy.service diff --git a/backend/jukebox-api-proxy.service b/backend/jukebox-api-proxy.service new file mode 100644 index 0000000..e2f52f4 --- /dev/null +++ b/backend/jukebox-api-proxy.service @@ -0,0 +1,12 @@ +[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 From e23cedb42047ee14f47c50de16509160cb942dd0 Mon Sep 17 00:00:00 2001 From: Josh Jimenez Bedrock Date: Wed, 2 Feb 2022 17:12:40 +0000 Subject: [PATCH 3/8] Added proxy service task to shipit file --- backend/shipitfile.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/shipitfile.js b/backend/shipitfile.js index 1fb7a24..3aa0d94 100644 --- a/backend/shipitfile.js +++ b/backend/shipitfile.js @@ -1,6 +1,6 @@ const path = require('path') -module.exports = shipit => { +module.exports = (shipit) => { require('shipit-deploy')(shipit) shipit.initConfig({ @@ -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 () { @@ -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') + }) } From 5c96d4dfe89999a8c05559bf3d6bc1d9f78034c1 Mon Sep 17 00:00:00 2001 From: Josh Jimenez Bedrock Date: Wed, 2 Feb 2022 17:12:52 +0000 Subject: [PATCH 4/8] Removed protocol from URL --- frontend/src/middleware/jukebox-middleware/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/middleware/jukebox-middleware/index.ts b/frontend/src/middleware/jukebox-middleware/index.ts index 8ac3940..8a9362a 100644 --- a/frontend/src/middleware/jukebox-middleware/index.ts +++ b/frontend/src/middleware/jukebox-middleware/index.ts @@ -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 From 055b8a68d9f2252c31a04da117a05a8eb57c5e0e Mon Sep 17 00:00:00 2001 From: Duncan Robertson Date: Fri, 4 Feb 2022 10:59:01 +0000 Subject: [PATCH 5/8] update path to caddyfile --- backend/jukebox-api-proxy.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/jukebox-api-proxy.service b/backend/jukebox-api-proxy.service index e2f52f4..b99c93d 100644 --- a/backend/jukebox-api-proxy.service +++ b/backend/jukebox-api-proxy.service @@ -4,7 +4,8 @@ After=network.target [Service] Type=simple -ExecStart=/usr/bin/caddy run -config /home/jukebox/app/current/backend/Caddyfile +ExecStart=/usr/bin/caddy run -config /home/jukebox/app/current/backend/dist/Caddyfile + Restart=always # Restart service after 10 seconds if service crashes RestartSec=10 From aa8d7ed21fa969d2fdb055f7947d8e0091759b75 Mon Sep 17 00:00:00 2001 From: Duncan Robertson Date: Fri, 4 Feb 2022 10:59:22 +0000 Subject: [PATCH 6/8] allow us to start with params --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index a2658d7..f7936af 100644 --- a/makefile +++ b/makefile @@ -21,7 +21,7 @@ build: docker-compose build start: - docker-compose $(args) up + docker-compose $(args) up $(params) fe-serve: make fe task=start From ee5dbaedabed250d183d5bb82cc7ae6351464712 Mon Sep 17 00:00:00 2001 From: Duncan Robertson Date: Fri, 4 Feb 2022 12:23:47 +0000 Subject: [PATCH 7/8] Add optional caddy support --- .gitignore | 1 + README.md | 30 ++++++++++++++++++------------ docker-compose.yml | 9 +++++++++ makefile | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 53dfcbd..c5757ef 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ yarn-debug.log* yarn-error.log mongodb-data mopidy-data +caddy_* node_modules .pnp.* .yarn/* diff --git a/README.md b/README.md index 8d837fc..7a9059c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 5edaf08..7644a33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/makefile b/makefile index f7936af..b9647fa 100644 --- a/makefile +++ b/makefile @@ -21,7 +21,7 @@ build: docker-compose build start: - docker-compose $(args) up $(params) + docker-compose $(args) up $(services) fe-serve: make fe task=start From ee0b50bf1e4033030dc45e51225e01f8dab4ef5b Mon Sep 17 00:00:00 2001 From: Duncan Robertson Date: Fri, 4 Feb 2022 12:38:06 +0000 Subject: [PATCH 8/8] Josh was right the first time --- backend/jukebox-api-proxy.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/jukebox-api-proxy.service b/backend/jukebox-api-proxy.service index b99c93d..775d1fb 100644 --- a/backend/jukebox-api-proxy.service +++ b/backend/jukebox-api-proxy.service @@ -4,7 +4,7 @@ After=network.target [Service] Type=simple -ExecStart=/usr/bin/caddy run -config /home/jukebox/app/current/backend/dist/Caddyfile +ExecStart=/usr/bin/caddy run -config /home/jukebox/app/current/backend/Caddyfile Restart=always # Restart service after 10 seconds if service crashes