Skip to content

Commit

Permalink
Docker (#146)
Browse files Browse the repository at this point in the history
* docker: initial config

* docker: add entrypoint for headless run

* docker: resolve path from env variable

* docker: initial config

* docker: rename preloaded data directories

* docker: update README

* docker: prevent issue with port mappings

* docker: update README.md

* docker: add docker-compose

* docker: cleanup logs

* docker: add CI

* docker: cleanup unused

* docker: use static port in development

* refactor: isolate tasks

* docker: add demo db

* fix: download db resolves according to OS

* docker: config build

* fix: ensure db path exists

* fix: add object type to block

* docker: config build

* docker: config build

* docker: env is production

* docker: preload db

* fix: remove test dir

* docker: graceful shutdown node app

* docker: env is production

* docker: add docker-compose

* docker: remove unused mappings

* docker: version bump
  • Loading branch information
cpvalente committed Jun 8, 2022
1 parent 94a7ef6 commit 9c5c7ee
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 188 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore config files
.prettier*

# Ignore install stuff
**/yarn.lock
**/yarn-error.log

# Ignore test files
**/__tests__/**
**/**.test.js

# Ignore git and cache folders
.git
.cache
103 changes: 0 additions & 103 deletions .github/workflows/autobuild.yml

This file was deleted.

62 changes: 54 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

# React
- name: React - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile
working-directory: ./client

- name: React - Build project
Expand All @@ -31,13 +31,13 @@ jobs:

# Node server
- name: Server - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile --production
working-directory: ./server/src

# App
- name: Electron - Install dependencies
shell: bash
run: yarn install && yarn setdb
run: yarn install --frozen-lockfile && yarn setdb
working-directory: ./server
- name: Electron - Build app
run: yarn dist-mac
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:

# React
- name: React - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile
working-directory: ./client

- name: React - Build project
Expand All @@ -74,13 +74,13 @@ jobs:

# Node server
- name: Server - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile --production
working-directory: ./server/src

# App
- name: Electron - Install dependencies
shell: bash
run: yarn install && yarn setdb
run: yarn install --frozen-lockfile && yarn setdb
working-directory: ./server
- name: Electron - Build app
run: yarn dist-win
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:

# React
- name: React - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile
working-directory: ./client

- name: React - Build project
Expand All @@ -117,7 +117,7 @@ jobs:

# Node server
- name: Server - Install dependencies
run: yarn install
run: yarn install --frozen-lockfile --production
working-directory: ./server/src

# App
Expand All @@ -136,3 +136,49 @@ jobs:
files: ./server/dist/ontime-linux.AppImage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish_docker:
runs-on: ubuntu-latest
env:
CI: ''

steps:
- uses: actions/checkout@v2
- name: Setup env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '14.x'

# React
- name: React - Install dependencies
run: yarn install
working-directory: ./client

- name: React - Build project
run: yarn build
working-directory: ./client

# Node server
- name: Server - Install dependencies
run: yarn install --frozen-lockfile --production
working-directory: ./server/src

# Login to docker
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Build and push
- name: Build and push
working-directory: ./
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ontime:${{ env.RELEASE_VERSION }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ yarn-error.log*
# working stuff
_SS/
db backup.json
server/src/data/db.json
server/src/preloaded-db/db.json
server/src/models/db.json
TODO.md
ontime-db/

# vscode stuff
.vscode/*
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:14-alpine

WORKDIR /app/server

# Prepare UI
COPY /client/build ../client/build

# Prepare Backend
COPY /server/src ./

# Export default ports Main - OSC IN
EXPOSE 4001/tcp 8888/udp
ENV NODE_ENV=production
ENV ONTIME_DATA=/server/

CMD ["yarn", "start:headless"]

# Build an run commandsN
# docker build -t getontime/ontime .
# docker run -p 4001:4001 -p 10.0.0.12:8888:8888/udp --mount type=bind,source="$(pwd)/ontime-db",target=/server/preloaded-db getontime/ontime
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ More documentation available [here](https://cpvalente.gitbook.io/ontime/)
- [x] Logging view
- [x] Edit anywhere: run ontime in your local network and use any machine to reach the editor page (
same as app)
- [x] Multi platform (available on Windows, MacOS and Linux)
- [x] [Headless run](#headless-run) (run server only, configure from a browser locally)

## Unopinionated

Expand Down Expand Up @@ -115,6 +117,29 @@ See [this repository](https://github.com/cpvalente/ontime-viewer-template) with
how to get you started and read the docs about
the [Websocket API](https://app.gitbook.com/s/-Mc0giSOToAhq0ROd0CR/control-and-feedback/websocket-api)

### Headless run️
You can self host and run ontime in a docker image, the run command should:
- expose the necessary ports (listen in Dockerfile)
- mount a local file to persist your data (in the example: ````$(pwd)/local-data````)
- the image name __getontime/ontime__

The docker image is in [available Docker Hub at getontime/ontime](https://hub.docker.com/r/getontime/ontime)
```bash
docker pull getontime/ontime
```

```bash
# Port 4001 - ontime server port
# Port 8888 - OSC input, bound to localhost IP Address
docker run -p 4001:4001 -p 127.0.0.1:8888:8888/udp --mount type=bind,source="$(pwd)/ontime-db",target=/server/preloaded-db getontime/ontime
```

or if running from the docker compose

```bash
docker-compose up
```

## Roadmap

### Continued development
Expand All @@ -126,7 +151,6 @@ friendly order unless there is user demand to bump any of them.
- [ ] Improvement with event component design
- [ ] New playback mode
for [cumulative time keeping](https://github.com/cpvalente/ontime/issues/100)
- [ ] Headless version (run server only anywhere, configure from a browser locally)
- [ ] Companion module
- [ ] Lower Third Manager
- [ ] Note only event
Expand Down
17 changes: 10 additions & 7 deletions client/src/app/api/apiConstants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const NODE_PORT = 4001;
export const STATIC_PORT = 4001;
export const EVENT_TABLE = 'event';
export const ALIASES = 'aliases';
export const USERFIELDS = 'userFields';
Expand All @@ -8,15 +8,18 @@ export const OSC_SETTINGS = 'oscSettings';
export const APP_SETTINGS = 'appSettings';

/**
* @description finds server path given the current location
* @description finds server path given the current location, it
* @return {*}
*/
const calculateServer = () => {
return window.location.origin.replace(window.location.port, `${NODE_PORT}/`);
if (process.env?.NODE_ENV === 'development') {
return `http://localhost:${STATIC_PORT}`;
}
return window.location.origin;
};

export const serverURL = calculateServer();
export const eventURL = serverURL + EVENT_TABLE;
export const eventsURL = serverURL + EVENTS_TABLE;
export const playbackURL = `${serverURL}playback`;
export const ontimeURL = `${serverURL}ontime`;
export const eventURL = `${serverURL}/${EVENT_TABLE}`;
export const eventsURL = `${serverURL}/${EVENTS_TABLE}`;
export const playbackURL = `${serverURL}/playback`;
export const ontimeURL = `${serverURL}/ontime`;
4 changes: 3 additions & 1 deletion client/src/app/api/ontimeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ export const downloadEvents = async () => {
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
}

const url = window.URL.createObjectURL(new Blob([response.data]));
const url = window.URL.createObjectURL(
new Blob([response.data], { type: 'application/json' })
);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
Expand Down

0 comments on commit 9c5c7ee

Please sign in to comment.