mirror of
https://github.com/yldio/copilot.git
synced 2024-11-10 21:30:06 +02:00
initial implementation of a simple bff
This commit is contained in:
parent
c4376ecbcb
commit
27adabd4f2
6
Makefile
6
Makefile
@ -21,5 +21,9 @@ install-cloudapi-graphql:
|
|||||||
install-frontend:
|
install-frontend:
|
||||||
$(MAKE) -C frontend install
|
$(MAKE) -C frontend install
|
||||||
|
|
||||||
|
.PHONY: install-backend
|
||||||
|
install-backend:
|
||||||
|
$(MAKE) -C backend install
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: install-cloudapi-graphql install-frontend
|
install: install-cloudapi-graphql install-frontend install-backend
|
||||||
|
@ -12,6 +12,7 @@ We will also include multiple PoC's of various bits of functionality from UI's p
|
|||||||
```
|
```
|
||||||
.
|
.
|
||||||
├── frontend
|
├── frontend
|
||||||
|
├── backend
|
||||||
├── cloudapi-graphql
|
├── cloudapi-graphql
|
||||||
└── spikes
|
└── spikes
|
||||||
```
|
```
|
||||||
@ -24,6 +25,10 @@ An implementation of the [Joyent CloudAPI](https://apidocs.joyent.com/cloudapi/)
|
|||||||
|
|
||||||
The client side code with a dev-server.
|
The client side code with a dev-server.
|
||||||
|
|
||||||
|
### backend
|
||||||
|
|
||||||
|
A simple backend for frontend that serves the static files and fallbacks to `/static/index.html`. To be used in production.
|
||||||
|
|
||||||
## spikes
|
## spikes
|
||||||
|
|
||||||
Implementation examples from spikes.
|
Implementation examples from spikes.
|
||||||
|
4
backend/.eslintignore
Normal file
4
backend/.eslintignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/node_modules
|
||||||
|
coverage
|
||||||
|
.nyc_output
|
||||||
|
static
|
12
backend/.eslintrc
Normal file
12
backend/.eslintrc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "semistandard",
|
||||||
|
"rules": {
|
||||||
|
"space-before-function-paren": [2, "never"],
|
||||||
|
"object-curly-newline": ["error", {
|
||||||
|
"minProperties": 1
|
||||||
|
}],
|
||||||
|
"sort-vars": ["error", {
|
||||||
|
"ignoreCase": true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
10
backend/.tern-project
Normal file
10
backend/.tern-project
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"libs": [
|
||||||
|
"ecmascript"
|
||||||
|
],
|
||||||
|
"plugins": {
|
||||||
|
"doc_comment": true,
|
||||||
|
"local-scope": true,
|
||||||
|
"node": true
|
||||||
|
}
|
||||||
|
}
|
32
backend/Dockerfile
Normal file
32
backend/Dockerfile
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
FROM node:slim
|
||||||
|
|
||||||
|
RUN set -x \
|
||||||
|
&& apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3 \
|
||||||
|
&& echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
|
||||||
|
&& apt-get update && apt-get install -y git yarn --no-install-recommends \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& groupadd -g 433 -r nodejs \
|
||||||
|
&& useradd -u 431 -r -g nodejs -d /home/nodejs -s /sbin/nologin -c "Docker image user" nodejs \
|
||||||
|
&& mkdir -p /home/nodejs/ \
|
||||||
|
&& chown -R nodejs:nodejs /home/nodejs/
|
||||||
|
|
||||||
|
# Get and configure containerpilot
|
||||||
|
ENV CONTAINERPILOT_VERSION 2.4.1
|
||||||
|
ENV CONTAINERPILOT file:///etc/containerpilot.json
|
||||||
|
|
||||||
|
RUN export CP_SHA1=198d96c8d7bfafb1ab6df96653c29701510b833c \
|
||||||
|
&& curl -Lso /tmp/containerpilot.tar.gz \
|
||||||
|
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/containerpilot-${CONTAINERPILOT_VERSION}.tar.gz" \
|
||||||
|
&& echo "${CP_SHA1} /tmp/containerpilot.tar.gz" | sha1sum -c \
|
||||||
|
&& tar zxf /tmp/containerpilot.tar.gz -C /bin \
|
||||||
|
&& rm /tmp/containerpilot.tar.gz
|
||||||
|
|
||||||
|
COPY ./etc/containerpilot.json /etc/
|
||||||
|
|
||||||
|
USER nodejs
|
||||||
|
WORKDIR /home/nodejs/
|
||||||
|
ADD package.json .
|
||||||
|
RUN npm install # yarn
|
||||||
|
ADD . .
|
||||||
|
|
||||||
|
CMD [ "/bin/containerpilot", "node", "src/index.js" ]
|
15
backend/Makefile
Normal file
15
backend/Makefile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
./node_modules/.bin/ava
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install:
|
||||||
|
npm install --quiet --no-spin
|
||||||
|
$(MAKE) compile-frontent
|
||||||
|
|
||||||
|
# I'm not sure this is the best idea, let's see how this works out for us
|
||||||
|
# and then go with something better once we find pain points
|
||||||
|
.PHONY: compile-frontent
|
||||||
|
compile-frontent:
|
||||||
|
$(MAKE) -C ../frontend compile
|
||||||
|
cp -r ../frontend/static/* ./static
|
13
backend/README.md
Normal file
13
backend/README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Joyent Dashboard Backend
|
||||||
|
|
||||||
|
## start
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run start
|
||||||
|
```
|
||||||
|
|
||||||
|
## test
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run test
|
||||||
|
```
|
14
backend/etc/containerpilot.json
Normal file
14
backend/etc/containerpilot.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"consul": "{{ .CONSUL }}:8500",
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"name": "joyent-dashboard-backend",
|
||||||
|
"port": 8000,
|
||||||
|
"health": "/usr/bin/curl -o /dev/null --fail -s http://localhost:8000/",
|
||||||
|
"poll": 3,
|
||||||
|
"ttl": 10
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"backends": [
|
||||||
|
]
|
||||||
|
}
|
24
backend/package.json
Normal file
24
backend/package.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "joyent-dashboard-backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"license": "private",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node .",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"open": "nyc report --reporter=html & open coverage/index.html",
|
||||||
|
"coverage": "nyc check-coverage --statements 100 --functions 100 --lines 100 --branches 100"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.14.0",
|
||||||
|
"st": "^1.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^3.8.1",
|
||||||
|
"eslint-config-semistandard": "^7.0.0",
|
||||||
|
"eslint-config-standard": "^6.2.0",
|
||||||
|
"eslint-plugin-promise": "^3.3.0",
|
||||||
|
"eslint-plugin-standard": "^2.0.1"
|
||||||
|
}
|
||||||
|
}
|
31
backend/src/index.js
Normal file
31
backend/src/index.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const express = require('express');
|
||||||
|
const st = require('st');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
var mount = st({
|
||||||
|
path: path.join(__dirname, '../static'),
|
||||||
|
url: 'static/',
|
||||||
|
index: 'index.html',
|
||||||
|
dot: false,
|
||||||
|
passthrough: false,
|
||||||
|
gzip: true,
|
||||||
|
cors: false
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(mount);
|
||||||
|
|
||||||
|
app.get('/*', (req, res, next) => {
|
||||||
|
mount(Object.assign(req, {
|
||||||
|
sturl: '/static/index.html'
|
||||||
|
}), res, next);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(8000, (err, address) => {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Server running at: http://localhost:8000');
|
||||||
|
});
|
@ -31,3 +31,16 @@ cloudapi:
|
|||||||
- PORT=3000
|
- PORT=3000
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 3000:3000
|
||||||
|
#############################################################################
|
||||||
|
# Frontend
|
||||||
|
#############################################################################
|
||||||
|
cloudapi:
|
||||||
|
build: ./backend
|
||||||
|
mem_limit: 128m
|
||||||
|
labels:
|
||||||
|
- triton.cns.services=backend
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
- PORT=8000
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
@ -5,3 +5,7 @@ test:
|
|||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
npm install --quiet --no-spin
|
npm install --quiet --no-spin
|
||||||
|
|
||||||
|
.PHONY: compile
|
||||||
|
compile: install
|
||||||
|
NODE_ENV=production webpack --config webpack/index.js
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "joyent-dashboard",
|
"name": "joyent-dashboard-frontend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "private",
|
"license": "private",
|
||||||
|
@ -14,3 +14,13 @@ cloudapi:
|
|||||||
- PORT=3000
|
- PORT=3000
|
||||||
- ROOT_URL=http://localhost:3000
|
- ROOT_URL=http://localhost:3000
|
||||||
- CONSUL=consul
|
- CONSUL=consul
|
||||||
|
backend:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yml
|
||||||
|
service: backend
|
||||||
|
links:
|
||||||
|
- consul:consul
|
||||||
|
environment:
|
||||||
|
- PORT=8000
|
||||||
|
- ROOT_URL=http://localhost:8000
|
||||||
|
- CONSUL=consul
|
||||||
|
Loading…
Reference in New Issue
Block a user