Skip to content

Commit

Permalink
[FEAT] Kubernates Auto Scaling (bitwave-tv#95)
Browse files Browse the repository at this point in the history
* Create Dockerfile

* Add docker commands to npm package

* v1.9.0 - Kubernates Autoscaling

* Create kubernates files

* add dotenv

* move dotenv out of dev dep

* always pull latest image

* sync ports

* add protocol

* Update bitwave-deployment.yaml

* Update bitwave-deployment.yaml

* Update bitwave-deployment.yaml

* use port 5000

* Add docker-compose file

* Add host env & don't prune npm

* ignore certs

* Change port in example service yaml

* fix version detection

* fix version check

* Add timeouts to SSR async data API calls

Add 1.5 second timeouts to API calls to prevent front server hanging
  • Loading branch information
DispatchCommit authored Feb 21, 2020
1 parent 30cea71 commit 6c3b31c
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 100 deletions.
170 changes: 86 additions & 84 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,84 +1,86 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# Nuxt generate
dist

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# IDE
.idea

# Service worker
sw.*
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# Nuxt generate
dist

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# IDE
.idea

# Service worker
sw.*

certs
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:12

MAINTAINER dispatch <[email protected]>

# Install global npm packages
RUN npm install -g typescript

# Install npm packages
COPY package.json package-lock.json /bitwave/
RUN cd /bitwave && \
npm ci && \
npm cache verify

# Copy source code
COPY . /bitwave
WORKDIR /bitwave

# Build server
RUN cd /bitwave && \
npm run build && \
npm prune --production --dry-run

# Expose port
EXPOSE 3000

ENV HOST 0.0.0.0

# Start server
CMD [ "npm", "start" ]
23 changes: 23 additions & 0 deletions bitwave-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bitwave-dep
labels:
app: bitwave
spec:
replicas: 2
selector:
matchLabels:
app: bitwave
template:
metadata:
labels:
app: bitwave
spec:
containers:
- name: bitwave-node
image: bitwavetv/bitwave:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
protocol: TCP
13 changes: 13 additions & 0 deletions bitwave-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: bitwave-pod
labels:
app: bitwave
spec:
containers:
- name: bitwave-node
image: bitwavetv/bitwave:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
15 changes: 15 additions & 0 deletions bitwave-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: bitwave-svc
labels:
app: bitwave
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 3000
name: nodejs
selector:
app: bitwave
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'

# Microservices
services:

# API Server Configuration
api-server:
container_name: bitwave
image: bitwavetv/bitwave:latest

ports:
- "5000:3000"

environment:
- BMS_ENV=dev

deploy:
replicas: 2
restart_policy:
condition: any
delay: 5s
window: 10s
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitwave.tv",
"version": "1.8.61",
"version": "1.9.0",
"description": "An open platform live streaming service for creators to freely express themselves.",
"author": "Dispatch",
"scripts": {
Expand All @@ -11,11 +11,14 @@
"start": "cross-env NODE_ENV=production nuxt start",
"start:express": "cross-env NODE_ENV=production node server/index.js",
"start:nuxt": "cross-env NODE_ENV=production nuxt start",
"generate": "nuxt generate"
"generate": "nuxt generate",
"docker:build": "docker build -t bitwavetv/bitwave:latest .",
"docker:push": "docker push bitwavetv/bitwave:latest"
},
"dependencies": {
"@nuxtjs/axios": "^5.9.5",
"@nuxtjs/device": "^1.2.6",
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/google-analytics": "^2.2.3",
"@nuxtjs/manifest": "^3.0.0-beta.16",
"@nuxtjs/pwa": "^3.0.0-beta.20",
Expand Down Expand Up @@ -44,7 +47,6 @@
"vue-virtual-scroller": "^1.0.0-rc.2"
},
"devDependencies": {
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/vuetify": "^1.9.1",
"node-sass": "^4.13.1",
"nodemon": "^2.0.1",
Expand Down
6 changes: 3 additions & 3 deletions pages/_watch/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
// Attempt to load via API server
try {
const { data } = await $axios.get( `https://api.bitwave.tv/api/channel/${channel}` );
const { data } = await $axios.get( `https://api.bitwave.tv/api/channel/${channel}`, { timeout: 1500 } );
// Simple response validation
if ( data && data.hasOwnProperty( 'name' ) ) {
channelData = data;
Expand Down Expand Up @@ -742,7 +742,7 @@
// Fallback to bump if offline
if ( live === false ) {
try {
const { data } = await $axios.get( 'https://api.bitwave.tv/api/bump' );
const { data } = await $axios.get( 'https://api.bitwave.tv/api/bump', { timeout: 1500 } );
url = data.url;
type = 'video/mp4';
} catch ( error ) {
Expand Down Expand Up @@ -784,7 +784,7 @@
try {
const global = store.state[ChatStore.namespace][ChatStore.$states.global];
if ( global === null ) return null;
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }` );
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }`, { timeout: 1500 } );
if ( data && data.success ) return data.data;
} catch ( error ) {
console.log( `Chat hydration request failed` );
Expand Down
2 changes: 1 addition & 1 deletion pages/chat/_room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
const getChatHydration = async () => {
try {
const global = store.state[ChatStore.namespace][ChatStore.$states.global];
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }` );
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }`, { timeout: 1500 } );
if ( data.success ) return data.data;
} catch ( error ) {
console.log( error );
Expand Down
4 changes: 2 additions & 2 deletions pages/embed/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
async asyncData ( { $axios, params } ) {
const user = params.id;
try {
const { data } = await $axios.get( `https://api.bitwave.tv/api/channel/${user}` );
const { data } = await $axios.get( `https://api.bitwave.tv/api/channel/${user}`, { timeout: 1500 } );
const name = data.name;
const avatar = data.avatar;
Expand All @@ -88,7 +88,7 @@
if ( data.thumbnail ) poster = live ? thumb : poster;
if ( !live ) {
const { data } = await $axios.get( 'https://api.bitwave.tv/api/bump' );
const { data } = await $axios.get( 'https://api.bitwave.tv/api/bump', { timeout: 1500 } );
url = data.url;
type = 'video/mp4';
}
Expand Down
4 changes: 2 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
try {
const getStreams = async () => {
try {
const { data } = await $axios.get( 'https://api.bitwave.tv/v1/channels/live' );
const { data } = await $axios.get( 'https://api.bitwave.tv/v1/channels/live', { timeout: 1500 } );
if ( data && data.success ) {
return {
live: data.live,
Expand All @@ -280,7 +280,7 @@
try {
const global = store.state[ChatStore.namespace][ChatStore.$states.global];
if ( global === null ) return null;
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }` );
const { data } = await $axios.get( `https://chat.bitwave.tv/v1/messages${ global ? '' : `/${channel}` }`, { timeout: 1500 } );
if ( data.success ) return data.data;
} catch ( error ) {
console.error( error );
Expand Down
2 changes: 1 addition & 1 deletion pages/overlay/chat/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
async asyncData ( { $axios } ) {
const getChatHydration = async () => {
try {
const { data } = await $axios.get( 'https://chat.bitwave.tv/v1/messages' );
const { data } = await $axios.get( 'https://chat.bitwave.tv/v1/messages', { timeout: 1500 } );
if ( data.success ) return data.data;
} catch ( error ) {
console.log( error );
Expand Down
2 changes: 1 addition & 1 deletion pages/streamers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
async asyncData ({ $axios }) {
try {
let { data } = await $axios.get( 'https://api.bitwave.tv/api/channels/list' );
let { data } = await $axios.get( 'https://api.bitwave.tv/api/channels/list', { timeout: 1500 } );
return {
streamers: data.users,
Expand Down
Loading

0 comments on commit 6c3b31c

Please sign in to comment.