From 5d38c3a20638818ab6131cbc6d940768569c1628 Mon Sep 17 00:00:00 2001 From: rrequero Date: Thu, 16 Nov 2017 09:48:06 +0100 Subject: [PATCH] first commit --- .dockerignore | 1 + .editorconfig | 23 ++++ .eslintrc.yml | 48 ++++++++ .gitignore | 5 + Dockerfile | 28 +++++ Jenkinsfile | 137 +++++++++++++++++++++++ LICENSE | 21 ++++ README.md | 36 ++++++ app/Gruntfile.js | 72 ++++++++++++ app/index.js | 1 + app/microservice/public-swagger.json | 1 + app/microservice/register.json | 11 ++ app/microservice/swagger.json | 1 + app/src/app.js | 2 + app/src/logger.js | 25 +++++ app/test/e2e/service.spec.js | 34 ++++++ app/test/e2e/test.constants.js | 6 + base.yml | 6 + config/custom-environment-variables.json | 5 + config/default.json | 11 ++ config/dev.json | 1 + config/prod.json | 8 ++ config/staging.json | 8 ++ config/test.json | 8 ++ doc-writter.sh | 27 +++++ docker-compose-develop.yml | 7 ++ docker-compose-test.yml | 8 ++ entrypoint.sh | 19 ++++ k8s/production/deployment.yaml | 60 ++++++++++ k8s/production/hpa.yaml | 13 +++ k8s/services/service.yaml | 11 ++ k8s/staging/.gitkeep | 0 k8s/staging/deployment.yaml | 59 ++++++++++ package.json | 42 +++++++ 34 files changed, 745 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .eslintrc.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 app/Gruntfile.js create mode 100644 app/index.js create mode 100644 app/microservice/public-swagger.json create mode 100644 app/microservice/register.json create mode 100644 app/microservice/swagger.json create mode 100644 app/src/app.js create mode 100644 app/src/logger.js create mode 100644 app/test/e2e/service.spec.js create mode 100644 app/test/e2e/test.constants.js create mode 100644 base.yml create mode 100644 config/custom-environment-variables.json create mode 100644 config/default.json create mode 100644 config/dev.json create mode 100644 config/prod.json create mode 100644 config/staging.json create mode 100644 config/test.json create mode 100755 doc-writter.sh create mode 100644 docker-compose-develop.yml create mode 100644 docker-compose-test.yml create mode 100755 entrypoint.sh create mode 100644 k8s/production/deployment.yaml create mode 100644 k8s/production/hpa.yaml create mode 100644 k8s/services/service.yaml create mode 100644 k8s/staging/.gitkeep create mode 100644 k8s/staging/deployment.yaml create mode 100644 package.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a1e4212 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# Matches multiple files with brace expansion notation +# Set default charset +[*.js] +charset = utf-8 + +# 2 space indentation +[**/*.js] +indent_style = space +indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..c2c0e71 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,48 @@ +--- +extends: airbnb +env: + node: true + es6: true +parser: babel-eslint +parserOptions: + sourceType: module + ecmaVersion: 6 +globals: + describe: true + it: true + before: true + after: true +rules: + max-len: [1, 200, 2, {"ignoreUrls":true}] + curly: [2, "multi-line"] + comma-dangle: [0, always-multiline] + no-underscore-dangle: 0 + eqeqeq: [2, "allow-null"] + global-require: 0 + no-shadow: 1 + no-param-reassign: [2, { "props": false }] + indent: [2, 4] + padded-blocks: [2, { "switches": "always", "classes": "always" }] + quotes: + - 2 + - single + - allowTemplateLiterals: true +settings: + import/resolver: + node: + extensions: + # if unset, default is just '.js', but it must be re-added explicitly if set + - .js + - .jsx + - .es6 + - .coffee + + paths: + # an array of absolute paths which will also be searched + # think NODE_PATH + - /usr/local/share/global_modules + + # this is technically for identifying `node_modules` alternate names + moduleDirectory: + - node_modules # defaults to 'node_modules', but... + - app/src diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8e8274 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +.env +/.vscode +npm-debug.log + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..911cc7f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM node:9.1-alpine +MAINTAINER raul.requero@vizzuality.com + +ENV NAME doc-writter +ENV USER doc-writter + +RUN apk update && apk upgrade && \ + apk add --no-cache --update bash git openssh python alpine-sdk + +RUN addgroup $USER && adduser -s /bin/bash -D -G $USER $USER + +RUN npm install -g grunt-cli bunyan + +RUN mkdir -p /opt/$NAME +COPY package.json /opt/$NAME/package.json +RUN cd /opt/$NAME && npm install + +COPY entrypoint.sh /opt/$NAME/entrypoint.sh +COPY config /opt/$NAME/config + +WORKDIR /opt/$NAME + +COPY ./app /opt/$NAME/app +RUN chown $USER:$USER /opt/$NAME + +USER $USER + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..05699d8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,137 @@ +#!groovy + +node { + + // Actions + def forceCompleteDeploy = false + try { + timeout(time: 15, unit: 'SECONDS') { + forceCompleteDeploy = input( + id: 'Proceed0', message: 'Force COMPLETE Deployment', parameters: [ + [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you want to recreate services and deployments'] + ]) + } + } + catch(err) { // timeout reached or input false + // nothing + } + + // Variables + def tokens = "${env.JOB_NAME}".tokenize('/') + def appName = tokens[0] + def dockerUsername = "${DOCKER_USERNAME}" + def imageTag = "${dockerUsername}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}" + + currentBuild.result = "SUCCESS" + + checkout scm + properties([pipelineTriggers([[$class: 'GitHubPushTrigger']])]) + + try { + + stage ('Build docker') { + sh("docker -H :2375 build -t ${imageTag} .") + sh("docker -H :2375 build -t ${dockerUsername}/${appName}:latest .") + } + + stage ('Run Tests') { + sh('docker-compose -H :2375 -f docker-compose-test.yml build') + sh('docker-compose -H :2375 -f docker-compose-test.yml run --rm test') + sh('docker-compose -H :2375 -f docker-compose-test.yml stop') + } + + stage('Push Docker') { + withCredentials([usernamePassword(credentialsId: 'Vizzuality Docker Hub', usernameVariable: 'DOCKER_HUB_USERNAME', passwordVariable: 'DOCKER_HUB_PASSWORD')]) { + sh("docker -H :2375 login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD}") + sh("docker -H :2375 push ${imageTag}") + sh("docker -H :2375 push ${dockerUsername}/${appName}:latest") + sh("docker -H :2375 rmi ${imageTag}") + } + } + + stage ("Deploy Application") { + switch ("${env.BRANCH_NAME}") { + + // Roll out to staging + case "develop": + sh("echo Deploying to STAGING cluster") + sh("kubectl config use-context gke_${GCLOUD_PROJECT}_${GCLOUD_GCE_ZONE}_${KUBE_STAGING_CLUSTER}") + def service = sh([returnStdout: true, script: "kubectl get deploy ${appName} || echo NotFound"]).trim() + if ((service && service.indexOf("NotFound") > -1) || (forceCompleteDeploy)){ + sh("sed -i -e 's/{name}/${appName}/g' k8s/services/*.yaml") + sh("sed -i -e 's/{name}/${appName}/g' k8s/staging/*.yaml") + sh("kubectl apply -f k8s/services/") + sh("kubectl apply -f k8s/staging/") + } + sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --record") + break + + // Roll out to production + case "master": + def userInput = true + def didTimeout = false + try { + timeout(time: 60, unit: 'SECONDS') { + userInput = input( + id: 'Proceed1', message: 'Confirm deployment', parameters: [ + [$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this deployment'] + ]) + } + } + catch(err) { // timeout reached or input false + sh("echo Aborted by user or timeout") + if('SYSTEM' == user.toString()) { // SYSTEM means timeout. + didTimeout = true + } else { + userInput = false + } + } + if (userInput == true && !didTimeout){ + sh("echo Deploying to PROD cluster") + sh("kubectl config use-context gke_${GCLOUD_PROJECT}_${GCLOUD_GCE_ZONE}_${KUBE_PROD_CLUSTER}") + def service = sh([returnStdout: true, script: "kubectl get deploy ${appName} || echo NotFound"]).trim() + if ((service && service.indexOf("NotFound") > -1) || (forceCompleteDeploy)){ + sh("sed -i -e 's/{name}/${appName}/g' k8s/services/*.yaml") + sh("sed -i -e 's/{name}/${appName}/g' k8s/production/*.yaml") + sh("kubectl apply -f k8s/services/") + sh("kubectl apply -f k8s/production/") + } + sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --record") + } else { + sh("echo NOT DEPLOYED") + currentBuild.result = 'SUCCESS' + } + break + + // Default behavior? + default: + echo "Default -> do nothing" + currentBuild.result = "SUCCESS" + } + } + + // Notify Success + slackSend (color: '#00FF00', channel: '#the-new-api', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + emailext ( + subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", + body: """

SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':

+

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", + recipientProviders: [[$class: 'DevelopersRecipientProvider']] + ) + + + } catch (err) { + + currentBuild.result = "FAILURE" + // Notify Error + slackSend (color: '#FF0000', channel: '#the-new-api', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + emailext ( + subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", + body: """

FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':

+

Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"

""", + recipientProviders: [[$class: 'DevelopersRecipientProvider']] + ) + throw err + } + +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4a4b40b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 control-tower + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4708557 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Node Skeleton Microservice + + +This repository is the node skeleton microservice to create node microservice for WRI API + +1. [Getting Started](#getting-started) + +## Getting Started + +### OS X + +**First, make sure that you have the [API gateway running +locally](https://github.com/control-tower/control-tower).** + +We're using Docker which, luckily for you, means that getting the +application running locally should be fairly painless. First, make sure +that you have [Docker Compose](https://docs.docker.com/compose/install/) +installed on your machine. + +``` +git clone https://github.com/Vizzuality/node-skeleton +cd node-skeleton +./service.sh develop +./service.sh test +```text + +You can now access the microservice through the CT gateway. + +``` + +### Configuration + +It is necessary to define these environment variables: + +* CT_URL => Control Tower URL +* NODE_ENV => Environment (prod, staging, dev) diff --git a/app/Gruntfile.js b/app/Gruntfile.js new file mode 100644 index 0000000..c8dc5ab --- /dev/null +++ b/app/Gruntfile.js @@ -0,0 +1,72 @@ + +module.exports = (grunt) => { + + grunt.file.setBase('..'); + require('load-grunt-tasks')(grunt); + + grunt.initConfig({ + + express: { + dev: { + options: { + script: 'app/index.js', + node_env: 'dev', + output: 'started' + } + }, + test: { + options: { + script: 'app/index.js', + node_env: 'test', + port: 5000, + output: 'started' + } + } + }, + + mochaTest: { + e2e: { + options: { + reporter: 'spec', + quiet: false, + clearRequireCache: true, + }, + src: ['app/test/e2e/**/*.spec.js'] + } + }, + + watch: { + options: { + livereload: 35730 + }, + jssrc: { + files: [ + 'app/src/**/*.js', + ], + tasks: ['express:dev'], + options: { + spawn: false + } + }, + e2eTest: { + files: [ + 'app/test/e2e/**/*.spec.js', + ], + tasks: ['express:test', 'mochaTest:e2e'], + options: { + spawn: true + } + }, + + } + }); + + grunt.registerTask('e2eTest', ['express:test', 'mochaTest:e2e']); + + grunt.registerTask('e2eTest-watch', ['watch:e2eTest']); + + grunt.registerTask('serve', ['express:dev', 'watch']); + + grunt.registerTask('default', 'serve'); + +}; diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..d0510b0 --- /dev/null +++ b/app/index.js @@ -0,0 +1 @@ +require('app'); diff --git a/app/microservice/public-swagger.json b/app/microservice/public-swagger.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/app/microservice/public-swagger.json @@ -0,0 +1 @@ +{} diff --git a/app/microservice/register.json b/app/microservice/register.json new file mode 100644 index 0000000..76f6fac --- /dev/null +++ b/app/microservice/register.json @@ -0,0 +1,11 @@ +{ + "name": "node-skeleton", + "endpoints": [{ + "path": "/v1/service/hi", + "method": "GET", + "redirect": { + "method": "GET", + "path": "/api/v1/service/hi" + } + }] +} diff --git a/app/microservice/swagger.json b/app/microservice/swagger.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/app/microservice/swagger.json @@ -0,0 +1 @@ +{} diff --git a/app/src/app.js b/app/src/app.js new file mode 100644 index 0000000..5957da1 --- /dev/null +++ b/app/src/app.js @@ -0,0 +1,2 @@ +const logger = require('logger'); +const config = require('config'); diff --git a/app/src/logger.js b/app/src/logger.js new file mode 100644 index 0000000..393704f --- /dev/null +++ b/app/src/logger.js @@ -0,0 +1,25 @@ +const config = require('config'); +const bunyan = require('bunyan'); + +/** + * Create Logger + */ +module.exports = (() => { + const streams = [{ + level: config.get('logger.level') || 'debug', + stream: process.stdout + }]; + if (config.get('logger.toFile')) { + streams.push({ + level: config.get('logger.level') || 'debug', + path: config.get('logger.dirLogFile') + }); + } + const logger = bunyan.createLogger({ + name: config.get('logger.name'), + src: true, + streams + }); + return logger; + +})(); diff --git a/app/test/e2e/service.spec.js b/app/test/e2e/service.spec.js new file mode 100644 index 0000000..368e69d --- /dev/null +++ b/app/test/e2e/service.spec.js @@ -0,0 +1,34 @@ +const logger = require('logger'); +const nock = require('nock'); +const request = require('superagent').agent(); +const BASE_URL = require('./test.constants').BASE_URL; +require('should'); + +describe('E2E test', () => { + + before(() => { + + // simulating gateway communications + nock(`${process.env.CT_URL}/v1`) + .post('/', () => true) + .reply(200, { + status: 200, + detail: 'Ok' + }); + }); + + /* Greeting Hi */ + it('Service Greeting Hi', async() => { + let response = null; + try { + response = await request.get(`${BASE_URL}/service/hi`).send(); + } catch (e) { + logger.error(e); + } + response.status.should.equal(200); + response.body.should.have.property('greeting').and.be.exactly('hi'); + }); + + after(() => { + }); +}); diff --git a/app/test/e2e/test.constants.js b/app/test/e2e/test.constants.js new file mode 100644 index 0000000..90468a2 --- /dev/null +++ b/app/test/e2e/test.constants.js @@ -0,0 +1,6 @@ + +const BASE_URL = 'http://localhost:5000/api/v1'; + +module.exports = { + BASE_URL +}; diff --git a/base.yml b/base.yml new file mode 100644 index 0000000..50bc469 --- /dev/null +++ b/base.yml @@ -0,0 +1,6 @@ +base: + build: . + container_name: doc-writter + environment: + NODE_PATH: app/src + diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json new file mode 100644 index 0000000..8d5502d --- /dev/null +++ b/config/custom-environment-variables.json @@ -0,0 +1,5 @@ +{ + "service": { + "port": "PORT" + } +} diff --git a/config/default.json b/config/default.json new file mode 100644 index 0000000..ef043f8 --- /dev/null +++ b/config/default.json @@ -0,0 +1,11 @@ +{ + "logger": { + "name": "doc-writter-DEV", + "level": "debug", + "toFile": false, + "dirLogFile": null + }, + "service": { + "name": "Doc Writter" + } +} diff --git a/config/dev.json b/config/dev.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/config/dev.json @@ -0,0 +1 @@ +{} diff --git a/config/prod.json b/config/prod.json new file mode 100644 index 0000000..b05a417 --- /dev/null +++ b/config/prod.json @@ -0,0 +1,8 @@ +{ + "logger": { + "name": "doc-writter", + "level": "warn", + "toFile": false, + "dirLogFile": null + } +} diff --git a/config/staging.json b/config/staging.json new file mode 100644 index 0000000..51963fd --- /dev/null +++ b/config/staging.json @@ -0,0 +1,8 @@ +{ + "logger": { + "name": "doc-writter-staging", + "level": "debug", + "toFile": false, + "dirLogFile": null + } +} diff --git a/config/test.json b/config/test.json new file mode 100644 index 0000000..0267519 --- /dev/null +++ b/config/test.json @@ -0,0 +1,8 @@ +{ + "logger": { + "name": "doc-writter-test", + "level": "debug", + "toFile": false, + "dirLogFile": null + } +} diff --git a/doc-writter.sh b/doc-writter.sh new file mode 100755 index 0000000..09d5b90 --- /dev/null +++ b/doc-writter.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +case "$1" in + test-e2e) + npm run test-e2e + ;; + test-unit) + npm run test-unit + ;; + start) + npm start + ;; + develop) + type docker-compose >/dev/null 2>&1 || { echo >&2 "docker-compose is required but it's not installed. Aborting."; exit 1; } + docker-compose -f docker-compose-develop.yml build && docker-compose -f docker-compose-develop.yml up + ;; + test) + type docker-compose >/dev/null 2>&1 || { echo >&2 "docker-compose is required but it's not installed. Aborting."; exit 1; } + docker-compose -f docker-compose-test.yml build && docker-compose -f docker-compose-test.yml up + ;; + *) + echo "Usage: service.sh {test-e2e|test-unit|start|develop|test}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/docker-compose-develop.yml b/docker-compose-develop.yml new file mode 100644 index 0000000..04db235 --- /dev/null +++ b/docker-compose-develop.yml @@ -0,0 +1,7 @@ +develop: + extends: + file: base.yml + service: base + command: develop + volumes: + - ./app:/opt/doc-writter/app diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 0000000..23c683a --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,8 @@ +test: + extends: + file: base.yml + service: base + container_name: doc-writter-test + environment: + NODE_ENV: test + command: test diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..e06a9b7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +case "$1" in + develop) + echo "Running Development Server" + exec grunt --gruntfile app/Gruntfile.js | bunyan + ;; + test) + echo "Running Test" + exec npm test + ;; + start) + echo "Running Start" + exec npm start + ;; + *) + exec "$@" +esac diff --git a/k8s/production/deployment.yaml b/k8s/production/deployment.yaml new file mode 100644 index 0000000..6767f1d --- /dev/null +++ b/k8s/production/deployment.yaml @@ -0,0 +1,60 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + name: {name} + name: {name} +spec: + revisionHistoryLimit: 2 + template: + metadata: + annotations: + chaos.alpha.kubernetes.io/enabled: "true" + labels: + name: {name} + spec: + containers: + - name: {name} + image: vizzuality/{name} + imagePullPolicy: Always + resources: + requests: + memory: "128Mi" + limits: + memory: "512Mi" + args: + - start + env: + - name: PORT + value: "3005" + - name: NODE_ENV + value: prod + - name: NODE_PATH + value: app/src + - name: LOCAL_URL + value: http://{name}.default.svc.cluster.local:3005 + - name: CT_URL + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_URL + - name: CT_TOKEN + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_TOKEN + - name: CT_REGISTER_MODE + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_REGISTER_MODE + - name: API_VERSION + valueFrom: + secretKeyRef: + name: mssecrets + key: API_VERSION + + ports: + - containerPort: 3005 + + restartPolicy: Always diff --git a/k8s/production/hpa.yaml b/k8s/production/hpa.yaml new file mode 100644 index 0000000..e7bcb74 --- /dev/null +++ b/k8s/production/hpa.yaml @@ -0,0 +1,13 @@ +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: {name} + namespace: default +spec: + scaleTargetRef: + apiVersion: apps/v1beta1 + kind: Deployment + name: {name} + minReplicas: 1 + maxReplicas: 3 + targetCPUUtilizationPercentage: 50 diff --git a/k8s/services/service.yaml b/k8s/services/service.yaml new file mode 100644 index 0000000..71b9c2f --- /dev/null +++ b/k8s/services/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: {name} + name: {name} +spec: + ports: + - port: 3005 + selector: + name: {name} diff --git a/k8s/staging/.gitkeep b/k8s/staging/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/k8s/staging/deployment.yaml b/k8s/staging/deployment.yaml new file mode 100644 index 0000000..eb2c787 --- /dev/null +++ b/k8s/staging/deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + name: {name} + name: {name} +spec: + revisionHistoryLimit: 0 + template: + metadata: + annotations: + chaos.alpha.kubernetes.io/enabled: "true" + labels: + name: {name} + spec: + containers: + - name: {name} + image: vizzuality/{name} + imagePullPolicy: Always + resources: + requests: + memory: "0Mi" + cpu: "0m" + args: + - start + env: + - name: PORT + value: "3005" + - name: NODE_ENV + value: staging + - name: NODE_PATH + value: app/src + - name: LOCAL_URL + value: http://{name}.default.svc.cluster.local:3005 + - name: CT_URL + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_URL + - name: CT_TOKEN + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_TOKEN + - name: CT_REGISTER_MODE + valueFrom: + secretKeyRef: + name: mssecrets + key: CT_REGISTER_MODE + - name: API_VERSION + valueFrom: + secretKeyRef: + name: mssecrets + key: API_VERSION + + ports: + - containerPort: 3005 + + restartPolicy: Always diff --git a/package.json b/package.json new file mode 100644 index 0000000..8b9d90b --- /dev/null +++ b/package.json @@ -0,0 +1,42 @@ +{ + "name": "node-skeleton", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "NODE_PATH=app/src node ./node_modules/.bin/grunt --gruntfile app/Gruntfile.js e2eTest", + "start": "NODE_PATH=app/src node app/index.js" + }, + "keywords": [], + "author": "Vizzuality", + "license": "MIT", + "devDependencies": { + "assert": "^1.4.1", + "babel-eslint": "^6.1.0", + "eslint": "^2.12.0", + "eslint-config-airbnb": "^9.0.1", + "eslint-plugin-import": "^1.8.1", + "eslint-plugin-jsx-a11y": "^1.5.3", + "eslint-plugin-react": "^5.2.2", + "grunt": "0.4.5", + "grunt-apidoc": "0.10.1", + "grunt-cli": "0.1.13", + "grunt-contrib-clean": "0.7.0", + "grunt-contrib-jshint": "0.12.0", + "grunt-contrib-watch": "0.6.1", + "grunt-express-server": "0.5.1", + "grunt-mocha-test": "0.12.7", + "grunt-notify": "0.4.3", + "load-grunt-tasks": "3.4.0", + "mocha": "^3.2.0", + "should": "^11.2.1", + "nock": "^9.0.2", + "superagent": "^3.3.1", + "supertest": "^3.0.0" + }, + "dependencies": { + "bluebird": "^3.4.7", + "bunyan": "^1.8.5", + "config": "^1.21.0" + } +}