From 892c5a45758f378752923b22337fa7ff7be66eaf Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 23 Jun 2017 15:22:06 -0500 Subject: [PATCH] chore(frontend): move docker artificats into docker folder --- docker/api/bin/sensors.sh | 8 +-- docker/frontend/Dockerfile | 51 +++++++++++++++++++ docker/frontend/bin/sensors.sh | 44 ++++++++++++++++ .../frontend}/etc/containerpilot.json5 | 28 +++------- .../frontend}/etc/nginx.conf.tmpl | 0 local-compose.yml | 2 +- packages/cp-frontend/Dockerfile | 19 ------- .../src/containers/navigation/menu.js | 2 +- .../src/containers/service/delete.js | 2 +- .../src/containers/services/list.js | 1 + packages/cp-frontend/src/state/selectors.js | 7 +-- packages/cp-frontend/src/state/store.js | 3 +- 12 files changed, 114 insertions(+), 53 deletions(-) create mode 100644 docker/frontend/Dockerfile create mode 100755 docker/frontend/bin/sensors.sh rename {packages/cp-frontend => docker/frontend}/etc/containerpilot.json5 (81%) rename {packages/cp-frontend => docker/frontend}/etc/nginx.conf.tmpl (100%) delete mode 100644 packages/cp-frontend/Dockerfile diff --git a/docker/api/bin/sensors.sh b/docker/api/bin/sensors.sh index 1a68bbd9..5c4774be 100755 --- a/docker/api/bin/sensors.sh +++ b/docker/api/bin/sensors.sh @@ -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 diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile new file mode 100644 index 00000000..11649b43 --- /dev/null +++ b/docker/frontend/Dockerfile @@ -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"] diff --git a/docker/frontend/bin/sensors.sh b/docker/frontend/bin/sensors.sh new file mode 100755 index 00000000..1a68bbd9 --- /dev/null +++ b/docker/frontend/bin/sensors.sh @@ -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 diff --git a/packages/cp-frontend/etc/containerpilot.json5 b/docker/frontend/etc/containerpilot.json5 similarity index 81% rename from packages/cp-frontend/etc/containerpilot.json5 rename to docker/frontend/etc/containerpilot.json5 index e39a0684..2cb07ea2 100644 --- a/packages/cp-frontend/etc/containerpilot.json5 +++ b/docker/frontend/etc/containerpilot.json5 @@ -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', diff --git a/packages/cp-frontend/etc/nginx.conf.tmpl b/docker/frontend/etc/nginx.conf.tmpl similarity index 100% rename from packages/cp-frontend/etc/nginx.conf.tmpl rename to docker/frontend/etc/nginx.conf.tmpl diff --git a/local-compose.yml b/local-compose.yml index 75173536..7081c63e 100644 --- a/local-compose.yml +++ b/local-compose.yml @@ -71,7 +71,7 @@ traefik: ############################################################################# frontend: build: ./ - dockerfile: packages/cp-frontend/Dockerfile + dockerfile: docker/frontend/Dockerfile mem_limit: 512m links: - consul:consul diff --git a/packages/cp-frontend/Dockerfile b/packages/cp-frontend/Dockerfile deleted file mode 100644 index 5cd184de..00000000 --- a/packages/cp-frontend/Dockerfile +++ /dev/null @@ -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"] diff --git a/packages/cp-frontend/src/containers/navigation/menu.js b/packages/cp-frontend/src/containers/navigation/menu.js index 860edb7d..2186bdf6 100644 --- a/packages/cp-frontend/src/containers/navigation/menu.js +++ b/packages/cp-frontend/src/containers/navigation/menu.js @@ -11,7 +11,7 @@ const ConnectedMenu = connect( const deploymentGroupSlug = params.deploymentGroup; const serviceSlug = params.service; - if ((deploymentGroupSlug || '').match(/^\~/)) { + if ((deploymentGroupSlug || '').match(/^~/)) { return {}; } diff --git a/packages/cp-frontend/src/containers/service/delete.js b/packages/cp-frontend/src/containers/service/delete.js index 2e138f0b..6b500576 100644 --- a/packages/cp-frontend/src/containers/service/delete.js +++ b/packages/cp-frontend/src/containers/service/delete.js @@ -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'; diff --git a/packages/cp-frontend/src/containers/services/list.js b/packages/cp-frontend/src/containers/services/list.js index a5885f5d..6f957aa4 100644 --- a/packages/cp-frontend/src/containers/services/list.js +++ b/packages/cp-frontend/src/containers/services/list.js @@ -176,6 +176,7 @@ const ServicesStartGql = graphql(ServicesStartMutation, { const ServiceListWithData = compose( ServicesGql, + ServicesRestartGql, ServicesStopGql, ServicesStartGql, ServicesGql, diff --git a/packages/cp-frontend/src/state/selectors.js b/packages/cp-frontend/src/state/selectors.js index ca307a99..2e37f471 100644 --- a/packages/cp-frontend/src/state/selectors.js +++ b/packages/cp-frontend/src/state/selectors.js @@ -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 }; diff --git a/packages/cp-frontend/src/state/store.js b/packages/cp-frontend/src/state/store.js index fef45b27..3d97e86b 100644 --- a/packages/cp-frontend/src/state/store.js +++ b/packages/cp-frontend/src/state/store.js @@ -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;