Merge pull request 'Docker-based deployment scripts.' (#12) from deploy_docker into master
Reviewed-on: #12pull/16/head
commit
7b1b8e0fee
23 changed files with 18936 additions and 2380 deletions
@ -0,0 +1,4 @@ |
||||
node_modules |
||||
client/node_modules |
||||
server/node_modules |
||||
server/dev.sqlite3 |
@ -1,13 +1,18 @@ |
||||
Started from: https://www.freecodecamp.org/news/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0/ |
||||
# MuDBase |
||||
|
||||
MuDBase is a self-hosted database for music. |
||||
|
||||
TODO: |
||||
It is made for those who use streaming services such as Spotify for keeping track of their music library and tastes, but don't want to rely solely on them for storing this information. |
||||
It is also for power users who would like to organize their music tastes with more powerful tools than only a storage of playlists, albums, artists and songs. MuDBase will offer more rich power features such as tagging and ranking music, and a powerful music querying system. |
||||
|
||||
- Ranking system |
||||
- Have "ranking contexts". These can be stored in the database. |
||||
- Per artist (this removes need for "per album", which can be a subset) |
||||
- Per tag |
||||
- Per playlist |
||||
- Have a linking table between contexts <-> artists/songs. This linking table should include an optional ranking score. |
||||
- The ranking score allows ranking songs per query or per query element. It is a floating point so we can always insert stuff in between. |
||||
- Visually, the system shows ranked items in a table and unranked items in another. User can drag to rank. |
||||
# Deployment |
||||
|
||||
The easiest deployment is by getting it off of Docker Hub. |
||||
The following env variables need to be set for MuDBase to work: |
||||
|
||||
- MUDBASE_DB_CONFIG: This env variable should contain a JSON struct with MuDBase's database configuration. The JSON should hold a valid Knex.js config struct. In principle, all dialects supported by Knex are supported (postgresql, mysql, mssql, sqlite3, oracledb), but only sqlite3 and postgresql are tested. |
||||
|
||||
# Architecture |
||||
|
||||
A Node.js Express back-end with a React front-end. |
||||
Started from: https://www.freecodecamp.org/news/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0/ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,52 @@ |
||||
# Note: this Dockerfile is written to be executed with the whole source |
||||
# as its context. |
||||
|
||||
# TODO remove client source |
||||
# TODO material UI (and other libs) from CSN |
||||
|
||||
FROM node:12-alpine as frontend_builder |
||||
|
||||
# Make a static build of the front-end only. |
||||
WORKDIR /usr/src/ |
||||
COPY client/package*.json ./ |
||||
RUN npm install --only=production |
||||
COPY client/ ./ |
||||
# Prime the front-end build to find the back-end at /api. |
||||
ENV REACT_APP_BACKEND "/api" |
||||
RUN npm run-script build |
||||
|
||||
FROM node:12-alpine |
||||
|
||||
# Some useful tools for servicing |
||||
RUN apk update && apk upgrade && apk add bash |
||||
|
||||
# Install back-end dependencies |
||||
WORKDIR /opt/mudbase/server |
||||
COPY server/package*.json ./ |
||||
RUN npm install --only=production |
||||
|
||||
# Install back-end source code |
||||
WORKDIR /opt/mudbase/server |
||||
COPY server/ ./ |
||||
|
||||
# Install static front-end build |
||||
COPY --from=frontend_builder /usr/src/build /opt/mudbase/frontend |
||||
|
||||
# Install the API where the back-end expects |
||||
# to find it. |
||||
# TODO: can we move it somewhere else? |
||||
COPY client/src/api.ts /opt/mudbase/client/src/api.ts |
||||
|
||||
# Install the runner script |
||||
COPY deploy/run.sh /opt/mudbase/run.sh |
||||
|
||||
# Start |
||||
WORKDIR /opt/mudbase |
||||
EXPOSE 8080 |
||||
ENV PORT 8080 |
||||
ENV API "/api" |
||||
ENV FRONTEND_PREFIX "/" |
||||
ENV FRONTEND "/opt/mudbase/frontend" |
||||
ENV NODE_ENV "production" |
||||
ENV ENVIRONMENT "production" |
||||
ENTRYPOINT './run.sh' |
@ -0,0 +1,10 @@ |
||||
#!/bin/bash |
||||
|
||||
SCRIPT=`realpath $0` |
||||
SCRIPTPATH=`dirname $SCRIPT` |
||||
|
||||
pushd "$SCRIPTPATH/.." |
||||
|
||||
docker build . -f deploy/Dockerfile -t mudbase:latest |
||||
|
||||
popd |
@ -0,0 +1,12 @@ |
||||
#!/bin/bash |
||||
|
||||
MUDBASE_DB_CONFIG=$(printenv MUDBASE_DB_CONFIG) |
||||
if [ -z "$MUDBASE_DB_CONFIG" ]; then |
||||
echo "Cannot start MuDBase without a database configuration." >&2 |
||||
echo "Please set the MUDBASE_DB_CONFIG env variable to a valid" >&2 |
||||
echo "Knex.js config JSON object." >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
echo "Starting MuDBase..." |
||||
cd server && npm start |
@ -0,0 +1,23 @@ |
||||
const environment = process.env.ENVIRONMENT || 'development' |
||||
import config from '../knexfile'; |
||||
|
||||
export default function get_knex() { |
||||
if (!Object.keys(config).includes(environment)) { |
||||
throw "No Knex database configuration was found for environment '" + |
||||
environment + "'. Please check your configuration."; |
||||
} |
||||
|
||||
var _knex = undefined; |
||||
console.log("Using Knex config: ", config[environment]) |
||||
|
||||
try { |
||||
_knex = require('knex')(config[environment]); |
||||
} catch (e) { |
||||
throw [ |
||||
"Failed to initialize Knex database connection with config: " |
||||
+ JSON.stringify(config[environment]), |
||||
e |
||||
]; |
||||
} |
||||
return _knex; |
||||
} |
@ -1,3 +0,0 @@ |
||||
const environment = process.env.ENVIRONMENT || 'development' |
||||
import config from '../knexfile'; |
||||
export default require('knex')(config[environment]); |
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,24 @@ |
||||
const express = require('express'); |
||||
|
||||
import knex from './knex/knex'; |
||||
import get_knex from './knex/get_knex'; |
||||
import { SetupApp } from './app'; |
||||
|
||||
const app = express(); |
||||
|
||||
const knex = get_knex(); |
||||
knex.migrate.latest().then(() => { |
||||
SetupApp(app, knex); |
||||
|
||||
const port = process.env.PORT || 5000; |
||||
const apiBase = process.env.API || ""; |
||||
const frontEndPrefix = process.env.FRONTEND_PREFIX || undefined; |
||||
const frontEnd = process.env.FRONTEND || undefined; |
||||
|
||||
SetupApp(app, knex, apiBase); |
||||
|
||||
if(frontEnd && frontEndPrefix) { |
||||
console.log(`Hosting front-end ${frontEnd} at ${frontEndPrefix}.`) |
||||
app.use(frontEndPrefix, express.static(frontEnd)) |
||||
} |
||||
|
||||
app.listen(port, () => console.log(`Listening on port ${port}`)); |
||||
}) |
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue