CategoriesUncategorized

Vue.js with RedHat Node Image — using Express Server

FROM registry.redhat.io/ubi8/nodejs-10:latest

LABEL maintainer="Joseph Shinaberry <joseph.shinaberry@spathesystems.com>"

WORKDIR /app

COPY . /app

USER root

RUN yum install npm \
    python2 -y && \
    cd /app && \
    npm install --unsafe-perm && \
    npm run build && \
    chown -R 1001:0 /app

USER 1001

EXPOSE 8080

CMD [ "node", "server.js" ]

Add this into the package.json under dependencies.

        "connect-history-api-fallback": "^1.6.0",
        "express": "^4.15.2",

Create server.js file in project root and add the following code:

const express = require('express');
const path = require('path');
const history = require('connect-history-api-fallback');

const app = express();

const staticFileMiddleware = express.static(path.join(__dirname + '/dist'));

app.use(staticFileMiddleware);
app.use(history({
  disableDotRule: true,
  verbose: true
}));
app.use(staticFileMiddleware);

app.get('/', function (req, res) {
  res.render(path.join(__dirname + '/dist/index.html'));
});

var server = app.listen(process.env.PORT || 8080, function () {
  var port = server.address().port;
  console.log("App now running on port", port);
});
CategoriesUncategorized

Using Node.js, to serve Vue.js full breakdown

Dockerfile:

FROM node:alpine

MAINTAINER Joseph Shinaberry <joseph.shinaberry@spathesystems.com>

WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY . /app

USER root
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install \
        npm install @vue/cli -g \
    && apk del .gyp \
    && vue-cli-service build

RUN chown -R 1001:0 /app
USER 1001

# OPEN PORT
EXPOSE 8080

# start app
CMD [ "node", "server.js" ]

Dependencies add to package.json

        "connect-history-api-fallback": "^1.6.0",
        "express": "^4.15.2",

Server.js file

const express = require('express');
const path = require('path');
const history = require('connect-history-api-fallback');

const app = express();

const staticFileMiddleware = express.static(path.join(__dirname + '/dist'));

app.use(staticFileMiddleware);
app.use(history({
  disableDotRule: true,
  verbose: true
}));
app.use(staticFileMiddleware);

app.get('/', function (req, res) {
  res.render(path.join(__dirname + '/dist/index.html'));
});

var server = app.listen(process.env.PORT || 8080, function () {
  var port = server.address().port;
  console.log("App now running on port", port);
});

CategoriesUncategorized

Docker Helpers

Start Docker – Postgres Advanced run

docker run -d -v /home/user/Data/someplace:/var/lib/postgresql/data -e POSTGRES_USERNAME=coolusername -e POSTGRES_PASSWORD=mightypassword -e POSTGRES_DBNAME=databasename -p 55432:5432 postgres:latest

Docker running services

docker ps

Docker Run Simple example

docker run -p 8080:8080 <tag>

See Docker Images

docker images --all

Docker Build simple example

docker builder -t <tag> .

Resolve PV being full

docker-compose up --renew-anon-volumes --build db

CategoriesUncategorized

Convert Bytes to MB/KB/GB/TB

    bytesToSize(bytes) {
      const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
      const i = Number(Math.floor(Math.log(bytes) / Math.log(1024)));
      if (bytes === 0) return '0 Byte';
      return `${Math.round(bytes / (1024 ** i), 2)} ${sizes[i]}`;
    },