1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 15:20:06 +02:00

chore(frontend): move docker artificats into docker folder

This commit is contained in:
geek 2017-06-23 15:22:06 -05:00 committed by Sérgio Ramos
parent dfe3b66f53
commit 892c5a4575
12 changed files with 114 additions and 53 deletions

View File

@ -13,7 +13,7 @@ memory() {
# 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"
/bin/containerpilot -putmetric "api_memory_percent=$memory"
}
# cpu load
@ -21,17 +21,17 @@ 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"
/bin/containerpilot -putmetric "api_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"
/bin/containerpilot -putmetric "api_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"
/bin/containerpilot -putmetric "api_disk_capacity=$capacity"
}
cmd=$1

View File

@ -0,0 +1,51 @@
FROM node:8-alpine
# Built in context of root folder in repo
# Install dependencies
RUN set -x \
&& apk update \
&& apk add --update curl bash build-base git nginx python \
&& 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 ./ /opt/app/
COPY ./docker/frontend/bin /bin
COPY ./docker/frontend/etc/nginx.conf.tmpl /etc/nginx/nginx.conf.tmpl
COPY ./docker/frontend/etc/containerpilot.json5 /etc/containerpilot.json5
ENV CONTAINERPILOT /etc/containerpilot.json5
WORKDIR /opt/app/
ENV BUILD=production
ENV NODE_ENV=production
RUN npm install -g yarn
RUN yarn add lerna
RUN ./node_modules/.bin/lerna clean --yes --scope joyent-cp-frontend --include-filtered-dependencies \
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-frontend --include-filtered-dependencies
WORKDIR /opt/app/packages/cp-frontend
RUN yarn build
CMD ["/bin/containerpilot"]

44
docker/frontend/bin/sensors.sh Executable file
View 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

View File

@ -38,21 +38,9 @@
'-retry-interval', '10s'],
restarts: 'unlimited'
},
{
name: 'is-built',
exec: '[ -d /opt/app/packages/cp-frontend/build/static ]'
},
{
name: 'build',
exec: 'yarn run build',
when: {
source: 'is-built',
once: 'exitFailed'
}
},
{
name: 'sensor_memory_usage',
exec: '/bin/sensors memory',
exec: '/bin/sensors.sh memory',
timeout: '5s',
when: {
interval: '5s'
@ -61,7 +49,7 @@
},
{
name: 'sensor_cpu_load',
exec: '/bin/sensors cpu',
exec: '/bin/sensors.sh cpu',
timeout: '5s',
when: {
interval: '5s'
@ -70,7 +58,7 @@
},
{
name: 'sensor_disk_capacity',
exec: '/bin/sensors diskcapacity',
exec: '/bin/sensors.sh diskcapacity',
timeout: '5s',
when: {
interval: '60s'
@ -79,7 +67,7 @@
},
{
name: 'sensor_disk_usage',
exec: '/bin/sensors diskusage',
exec: '/bin/sensors.sh diskusage',
timeout: '5s',
when: {
interval: '60s'
@ -92,28 +80,28 @@
tags: ['op'],
metrics: [
{
namespace: 'cp_frontend',
namespace: 'frontend',
subsystem: 'memory',
name: 'percent',
help: 'Percentage of memory used',
type: 'gauge'
},
{
namespace: 'cp_frontend',
namespace: 'frontend',
subsystem: 'cpu',
name: 'load',
help: 'CPU load',
type: 'gauge'
},
{
namespace: 'cp_frontend',
namespace: 'frontend',
subsystem: 'disk',
name: 'capacity',
help: 'Disk capacity',
type: 'gauge'
},
{
namespace: 'cp_frontend',
namespace: 'frontend',
subsystem: 'disk',
name: 'usage',
help: 'Disk usage',

View File

@ -71,7 +71,7 @@ traefik:
#############################################################################
frontend:
build: ./
dockerfile: packages/cp-frontend/Dockerfile
dockerfile: docker/frontend/Dockerfile
mem_limit: 512m
links:
- consul:consul

View File

@ -1,19 +0,0 @@
FROM quay.io/yldio/alpine-node-containerpilot:latest
RUN apk add --update nginx
ENV CONTAINERPILOT /etc/containerpilot.json5
RUN npm install -g npm@^4
RUN npm config set loglevel info \
&& yarn add lerna@^2.0.0-rc.5
RUN ./node_modules/.bin/lerna clean --yes --scope joyent-cp-frontend --include-filtered-dependencies \
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-frontend --include-filtered-dependencies
COPY packages/cp-frontend/etc/containerpilot.json5 ${CONTAINERPILOT}
COPY packages/cp-frontend/etc/nginx.conf.tmpl /etc/nginx/nginx.conf.tmpl
WORKDIR /opt/app/packages/cp-frontend
CMD ["/bin/containerpilot"]

View File

@ -11,7 +11,7 @@ const ConnectedMenu = connect(
const deploymentGroupSlug = params.deploymentGroup;
const serviceSlug = params.service;
if ((deploymentGroupSlug || '').match(/^\~/)) {
if ((deploymentGroupSlug || '').match(/^~/)) {
return {};
}

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose, graphql, gql } from 'react-apollo';
import { compose, graphql } from 'react-apollo';
import ServicesDeleteMutation from '@graphql/ServicesDeleteMutation.gql';
import { Loader, ErrorMessage } from '@components/messaging';
import { ServiceDelete as ServiceDeleteComponent } from '@components/service';

View File

@ -176,6 +176,7 @@ const ServicesStartGql = graphql(ServicesStartMutation, {
const ServiceListWithData = compose(
ServicesGql,
ServicesRestartGql,
ServicesStopGql,
ServicesStartGql,
ServicesGql,

View File

@ -54,10 +54,6 @@ const instancesByServiceId = serviceId =>
: null
);
const serviceWidthInstancesBySlug = serviceSlug => {
const service = serviceBySlug(serviceSlug);
};
// Apollo gql utils //
const findService = (services, uuid) =>
@ -108,5 +104,6 @@ const processServices = (services, datacenter) => {
export {
deploymentGroupBySlug as deploymentGroupBySlugSelector,
serviceBySlug as serviceBySlugSelector,
processServices
processServices,
instancesByServiceId
};

View File

@ -1,6 +1,5 @@
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { reducer as formReducer } from 'redux-form';
import { enableBatching } from 'redux-batched-actions';
import { ApolloClient, createNetworkInterface } from 'react-apollo';
import state from './state';
import { ui } from './reducers';
@ -13,7 +12,7 @@ const GLOBAL = typeof window === 'object'
}
};
const GQL_PORT = process.env.REACT_APP_GQL_PORT || 3000;
const GQL_PORT = process.env.REACT_APP_GQL_PORT || 80;
const GQL_HOSTNAME =
process.env.REACT_APP_GQL_HOSTNAME || GLOBAL.location.hostname;