mirror of
https://github.com/yldio/copilot.git
synced 2024-11-30 23:20:06 +02:00
chore: build from published modules
This commit is contained in:
parent
a373e4efa2
commit
dfe3b66f53
44
docker/api/Dockerfile
Normal file
44
docker/api/Dockerfile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
FROM node:8-alpine
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN set -x \
|
||||||
|
&& apk update \
|
||||||
|
&& apk add --update curl bash build-base python zeromq-dev openssh \
|
||||||
|
&& apk upgrade \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# Install Consul agent
|
||||||
|
ENV CONSUL_VERSION 0.7.0
|
||||||
|
ENV CONSUL_CHECKSUM b350591af10d7d23514ebaa0565638539900cdb3aaa048f077217c4c46653dd8
|
||||||
|
RUN curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
|
||||||
|
&& echo "${CONSUL_CHECKSUM} /tmp/consul.zip" | sha256sum -c \
|
||||||
|
&& unzip /tmp/consul -d /usr/local/bin \
|
||||||
|
&& rm /tmp/consul.zip \
|
||||||
|
&& mkdir /config
|
||||||
|
|
||||||
|
# Install ContainerPilot
|
||||||
|
ENV CP_SHA1 d06e289e6e0ca82156d77cea36ff0f0246fcca60
|
||||||
|
ENV CONTAINERPILOT_VERSION 3.1.0
|
||||||
|
RUN curl -Lo /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 required files
|
||||||
|
RUN mkdir -p /opt/app/
|
||||||
|
COPY *.js /opt/app/
|
||||||
|
COPY package.json /opt/app/
|
||||||
|
COPY bin /bin
|
||||||
|
COPY etc /etc
|
||||||
|
ENV CONTAINERPILOT /etc/containerpilot.json5
|
||||||
|
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
|
||||||
|
WORKDIR /opt/app/
|
||||||
|
|
||||||
|
ENV BUILD=production
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
CMD ["/bin/containerpilot"]
|
44
docker/api/bin/sensors.sh
Executable file
44
docker/api/bin/sensors.sh
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo 'Uses cli tools free and top to determine current CPU and memory usage'
|
||||||
|
echo 'for the telemetry service.'
|
||||||
|
}
|
||||||
|
|
||||||
|
# memory usage in percent
|
||||||
|
memory() {
|
||||||
|
# awk oneliner to get memory usage
|
||||||
|
# free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
|
||||||
|
# output:
|
||||||
|
# Memory Usage: 15804/15959MB (99.03%)
|
||||||
|
local memory=$(free -m | awk 'NR==2{printf "%.2f", $3*100/$2 }')
|
||||||
|
/bin/containerpilot -putmetric "frontend_memory_percent=$memory"
|
||||||
|
}
|
||||||
|
|
||||||
|
# cpu load
|
||||||
|
cpu() {
|
||||||
|
# oneliner to display cpu load
|
||||||
|
# top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
|
||||||
|
local cpuload=$(uptime | awk '{printf "%.2f", $6}')
|
||||||
|
/bin/containerpilot -putmetric "frontend_cpu_load=$cpuload"
|
||||||
|
}
|
||||||
|
|
||||||
|
diskusage() {
|
||||||
|
local usage=$(df -P | grep '/$' | awk 'NR=2{print $3}' | sed 's/[^0-9\.]*//g')
|
||||||
|
/bin/containerpilot -putmetric "frontend_disk_usage=$usage"
|
||||||
|
}
|
||||||
|
|
||||||
|
diskcapacity() {
|
||||||
|
local capacity=$(df -P | grep '/$' | awk 'NR=2{print $2}' | sed 's/[^0-9\.]*//g')
|
||||||
|
/bin/containerpilot -putmetric "frontend_disk_capacity=$capacity"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd=$1
|
||||||
|
if [ ! -z "$cmd" ]; then
|
||||||
|
shift 1
|
||||||
|
$cmd "$@"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
help
|
57
docker/api/bootstrap-data.js
vendored
Normal file
57
docker/api/bootstrap-data.js
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Data = require('portal-data');
|
||||||
|
|
||||||
|
|
||||||
|
const ifError = function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const bootstrap = function () {
|
||||||
|
const data = new Data({
|
||||||
|
db: {
|
||||||
|
host: process.env.RETHINK_HOST || 'localhost'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const region = process.env.TRITON_DC || 'us-sw-1';
|
||||||
|
const login = process.env.TRITON_USER || 'nikola';
|
||||||
|
|
||||||
|
data.connect(() => {
|
||||||
|
data.createDatacenter({ region, name: region }, (err, datacenter) => {
|
||||||
|
ifError(err);
|
||||||
|
|
||||||
|
data.createUser({ firstName: 'Nikola', lastName: 'Tesla', email: 'nikola@tesla.com', login }, (err, user) => {
|
||||||
|
ifError(err);
|
||||||
|
|
||||||
|
data.createPortal({
|
||||||
|
user,
|
||||||
|
datacenter
|
||||||
|
}, (err, portal) => {
|
||||||
|
ifError(err);
|
||||||
|
console.log('data bootstrapped');
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
const main = function () {
|
||||||
|
const dropData = new Data({
|
||||||
|
db: {
|
||||||
|
host: process.env.RETHINK_HOST || 'localhost'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dropData.connect(() => {
|
||||||
|
dropData._db.r.dbDrop('portal').run(dropData._db._connection, () => {
|
||||||
|
bootstrap();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
bootstrap();
|
@ -47,7 +47,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'sensor_memory_usage',
|
name: 'sensor_memory_usage',
|
||||||
exec: '/bin/sensors memory',
|
exec: '/bin/sensors.sh memory',
|
||||||
timeout: '5s',
|
timeout: '5s',
|
||||||
when: {
|
when: {
|
||||||
interval: '5s'
|
interval: '5s'
|
||||||
@ -56,7 +56,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'sensor_cpu_load',
|
name: 'sensor_cpu_load',
|
||||||
exec: '/bin/sensors cpu',
|
exec: '/bin/sensors.sh cpu',
|
||||||
timeout: '5s',
|
timeout: '5s',
|
||||||
when: {
|
when: {
|
||||||
interval: '5s'
|
interval: '5s'
|
||||||
@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'sensor_disk_capacity',
|
name: 'sensor_disk_capacity',
|
||||||
exec: '/bin/sensors diskcapacity',
|
exec: '/bin/sensors.sh diskcapacity',
|
||||||
timeout: '5s',
|
timeout: '5s',
|
||||||
when: {
|
when: {
|
||||||
interval: '60s'
|
interval: '60s'
|
||||||
@ -74,7 +74,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'sensor_disk_usage',
|
name: 'sensor_disk_usage',
|
||||||
exec: '/bin/sensors diskusage',
|
exec: '/bin/sensors.sh diskusage',
|
||||||
timeout: '5s',
|
timeout: '5s',
|
||||||
when: {
|
when: {
|
||||||
interval: '60s'
|
interval: '60s'
|
||||||
@ -87,8 +87,7 @@
|
|||||||
when: {
|
when: {
|
||||||
source: 'watch.docker-compose-api',
|
source: 'watch.docker-compose-api',
|
||||||
each: 'changed'
|
each: 'changed'
|
||||||
},
|
}
|
||||||
restarts: 'unlimited'
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
watches: [
|
watches: [
|
29
docker/api/package.json
Normal file
29
docker/api/package.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "api",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "./server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "wyatt",
|
||||||
|
"license": "MPL-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"boom": "^5.1.0",
|
||||||
|
"brule": "^2.0.0",
|
||||||
|
"good": "^7.2.0",
|
||||||
|
"good-console": "^6.4.0",
|
||||||
|
"good-squeeze": "^5.0.2",
|
||||||
|
"graphi": "^2.2.1",
|
||||||
|
"hapi": "^16.1.0",
|
||||||
|
"hoek": "^4.1.1",
|
||||||
|
"joi": "^10.6.0",
|
||||||
|
"joyent-cp-gql-schema": "^1.0.4",
|
||||||
|
"piloted": "^3.1.1",
|
||||||
|
"portal-api": "^1.1.0",
|
||||||
|
"portal-data": "^1.1.0",
|
||||||
|
"portal-watch": "^1.0.0",
|
||||||
|
"toppsy": "^1.1.0"
|
||||||
|
}
|
||||||
|
}
|
95
docker/api/server.js
Normal file
95
docker/api/server.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Fs = require('fs');
|
||||||
|
const Path = require('path');
|
||||||
|
const Brule = require('brule');
|
||||||
|
const Good = require('good');
|
||||||
|
const Hapi = require('hapi');
|
||||||
|
const Toppsy = require('toppsy');
|
||||||
|
const Pack = require('./package');
|
||||||
|
const Portal = require('portal-api');
|
||||||
|
|
||||||
|
|
||||||
|
const server = new Hapi.Server();
|
||||||
|
server.connection({ port: process.env.PORT || 3000 });
|
||||||
|
|
||||||
|
const {
|
||||||
|
DOCKER_HOST,
|
||||||
|
DOCKER_CERT_PATH,
|
||||||
|
DOCKER_CLIENT_TIMEOUT,
|
||||||
|
SDC_URL,
|
||||||
|
SDC_ACCOUNT,
|
||||||
|
SDC_KEY_ID
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
const portalOptions = {
|
||||||
|
data: {
|
||||||
|
db: {
|
||||||
|
host: process.env.RETHINK_HOST || 'localhost'
|
||||||
|
},
|
||||||
|
docker: {
|
||||||
|
host: DOCKER_HOST,
|
||||||
|
ca: DOCKER_CERT_PATH ?
|
||||||
|
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'ca.pem')) :
|
||||||
|
undefined,
|
||||||
|
cert: DOCKER_CERT_PATH ?
|
||||||
|
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'cert.pem')) :
|
||||||
|
undefined,
|
||||||
|
key: DOCKER_CERT_PATH ?
|
||||||
|
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'key.pem')) :
|
||||||
|
undefined,
|
||||||
|
timeout: DOCKER_CLIENT_TIMEOUT
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
url: SDC_URL,
|
||||||
|
account: SDC_ACCOUNT,
|
||||||
|
keyId: SDC_KEY_ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const goodOptions = {
|
||||||
|
ops: {
|
||||||
|
interval: 1000
|
||||||
|
},
|
||||||
|
reporters: {
|
||||||
|
consoleReporter: [{
|
||||||
|
module: 'good-squeeze',
|
||||||
|
name: 'Squeeze',
|
||||||
|
args: [{ log: '*', response: '*', error: '*' }]
|
||||||
|
}, {
|
||||||
|
module: 'good-console'
|
||||||
|
}, 'stdout']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
server.register([
|
||||||
|
Brule,
|
||||||
|
{
|
||||||
|
register: Good,
|
||||||
|
options: goodOptions
|
||||||
|
},
|
||||||
|
{
|
||||||
|
register: Portal,
|
||||||
|
options: portalOptions
|
||||||
|
},
|
||||||
|
{
|
||||||
|
register: Toppsy,
|
||||||
|
options: { namespace: 'portal', subsystem: 'api' }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
(err) => {
|
||||||
|
handlerError(err);
|
||||||
|
server.start((err) => {
|
||||||
|
handlerError(err);
|
||||||
|
console.log(`server started at http://localhost:${server.info.port}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function handlerError (error) {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
FROM quay.io/yldio/docker-compose-api
|
FROM quay.io/yldio/docker-compose-api
|
||||||
|
|
||||||
|
|
||||||
RUN apk add --update bash
|
RUN apk add --update bash
|
||||||
|
|
||||||
|
|
||||||
RUN export CONSUL_VERSION=0.7.0 \
|
RUN export CONSUL_VERSION=0.7.0 \
|
||||||
&& export CONSUL_CHECKSUM=b350591af10d7d23514ebaa0565638539900cdb3aaa048f077217c4c46653dd8 \
|
&& export CONSUL_CHECKSUM=b350591af10d7d23514ebaa0565638539900cdb3aaa048f077217c4c46653dd8 \
|
||||||
&& curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
|
&& curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
|
||||||
@ -12,12 +10,11 @@ RUN export CONSUL_VERSION=0.7.0 \
|
|||||||
&& rm /tmp/consul.zip \
|
&& rm /tmp/consul.zip \
|
||||||
&& mkdir /config
|
&& mkdir /config
|
||||||
|
|
||||||
|
|
||||||
# Add Containerpilot and set its configuration
|
# Add Containerpilot and set its configuration
|
||||||
ENV CONTAINERPILOT_VERSION 3.0.0
|
ENV CONTAINERPILOT_VERSION 3.1.0
|
||||||
ENV CONTAINERPILOT /etc/containerpilot.json
|
ENV CONTAINERPILOT /etc/containerpilot.json
|
||||||
|
|
||||||
RUN export CONTAINERPILOT_CHECKSUM=6da4a4ab3dd92d8fd009cdb81a4d4002a90c8b7c \
|
RUN export CONTAINERPILOT_CHECKSUM=d06e289e6e0ca82156d77cea36ff0f0246fcca60 \
|
||||||
&& export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \
|
&& export archive=containerpilot-${CONTAINERPILOT_VERSION}.tar.gz \
|
||||||
&& curl -Lso /tmp/${archive} \
|
&& curl -Lso /tmp/${archive} \
|
||||||
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \
|
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VERSION}/${archive}" \
|
@ -43,8 +43,8 @@ prometheus:
|
|||||||
|
|
||||||
# Docker-compose wrapper
|
# Docker-compose wrapper
|
||||||
# Create _env file from running ./setup.sh
|
# Create _env file from running ./setup.sh
|
||||||
docker-compose-api:
|
compose-api:
|
||||||
build: ./docker-compose-api
|
build: ./docker/compose-api
|
||||||
links:
|
links:
|
||||||
- consul:consul
|
- consul:consul
|
||||||
expose:
|
expose:
|
||||||
@ -87,8 +87,7 @@ frontend:
|
|||||||
# BACKEND
|
# BACKEND
|
||||||
#############################################################################
|
#############################################################################
|
||||||
api:
|
api:
|
||||||
build: ./
|
build: docker/api
|
||||||
dockerfile: packages/portal-api/Dockerfile
|
|
||||||
mem_limit: 512m
|
mem_limit: 512m
|
||||||
links:
|
links:
|
||||||
- consul:consul
|
- consul:consul
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "joyent-cp-gql-schema",
|
"name": "joyent-cp-gql-schema",
|
||||||
"version": "1.0.4",
|
"version": "1.1.0",
|
||||||
"private": true,
|
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"repository": "github:yldio/joyent-portal",
|
"repository": "github:yldio/joyent-portal",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docker-compose-client",
|
"name": "docker-compose-client",
|
||||||
"version": "1.0.8",
|
"version": "1.0.9",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"repository": "github:yldio/joyent-portal",
|
"repository": "github:yldio/joyent-portal",
|
||||||
"main": "lib",
|
"main": "lib",
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
FROM quay.io/yldio/alpine-node-containerpilot:latest
|
|
||||||
|
|
||||||
ENV CONTAINERPILOT /etc/containerpilot.json5
|
|
||||||
|
|
||||||
RUN set -x \
|
|
||||||
&& apk update \
|
|
||||||
&& apk add curl bash build-base python zeromq-dev openssh \
|
|
||||||
&& rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
RUN npm install -g npm@^4 \
|
|
||||||
&& npm config set loglevel info \
|
|
||||||
&& yarn add lerna@^2.0.0-rc.5 \
|
|
||||||
&& ./node_modules/.bin/lerna clean --yes --scope portal-api --include-filtered-dependencies \
|
|
||||||
&& ./node_modules/.bin/lerna bootstrap --scope portal-api --include-filtered-dependencies
|
|
||||||
|
|
||||||
COPY packages/portal-api/etc/containerpilot.json5 ${CONTAINERPILOT}
|
|
||||||
COPY packages/portal-api/bin /bin
|
|
||||||
|
|
||||||
WORKDIR /opt/app/packages/portal-api
|
|
||||||
|
|
||||||
CMD ["/bin/containerpilot"]
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "portal-api",
|
"name": "portal-api",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "portal-data",
|
"name": "portal-data",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "portal data layer",
|
"description": "portal data layer",
|
||||||
"main": "lib",
|
"main": "lib",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "portal-watch",
|
"name": "portal-watch",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"description": "resolver of triton change events",
|
"description": "resolver of triton change events",
|
||||||
"repository": "github:yldio/joyent-portal",
|
"repository": "github:yldio/joyent-portal",
|
||||||
|
Loading…
Reference in New Issue
Block a user