diff --git a/.dockerignore b/.dockerignore index 3c3629e64..8b1378917 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1 @@ -node_modules + diff --git a/.gitignore b/.gitignore index c24579337..f58108964 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ settings.yml settings.js + node_modules -bower_components npm-debug.log .DS_Store .idea diff --git a/Dockerfile b/Dockerfile index 1f71686e5..dc1fc376e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,11 @@ -FROM node:0.10-slim +# Change latest to your desired node version (https://hub.docker.com/r/library/node/tags/) +FROM kkarczmarczyk/node-yarn:8.0 +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app -COPY ./package.json /src/package.json -RUN cd /src && npm install -COPY ./ /src -RUN npm install -g mocha -RUN npm install -g istanbul -RUN npm install -g gulp +COPY package.json /usr/src/app/ +RUN yarn install +COPY . /usr/src/app -WORKDIR /src -#ENV DEBUG=* - -EXPOSE 8080 5222 - -CMD ["npm", "start"] +CMD [ "npm", "start" ] diff --git a/Dockerfile.latest b/Dockerfile.latest new file mode 100644 index 000000000..44a681c47 --- /dev/null +++ b/Dockerfile.latest @@ -0,0 +1,11 @@ +# Change latest to your desired node version (https://hub.docker.com/r/library/node/tags/) +FROM node:latest + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY package.json /usr/src/app/ +RUN npm install --silent +COPY . /usr/src/app + +CMD [ "npm", "start" ] diff --git a/Dockerfile_prod b/Dockerfile_prod new file mode 100644 index 000000000..49e3ae6a7 --- /dev/null +++ b/Dockerfile_prod @@ -0,0 +1,12 @@ +FROM node:0.10-slim + +COPY ./package.json /src/package.json +RUN cd /src && npm install +COPY ./ /src + +WORKDIR /src +#ENV DEBUG=* + + +CMD ["npm", "start"] + diff --git a/README.md b/README.md index 8e485467e..da43071ee 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,10 @@ +Build status: [![Codefresh build status]( https://g.codefresh.io/api/badges/build?repoOwner=containers101&repoName=demochat&branch=master&pipelineName=demochatdfdf&accountName=Razielt77_github&type=cf-1)]( https://g.codefresh.io/repositories/containers101/demochat/builds?filter=trigger:build;branch:master;service:58543cb490a3f40100db408f~demochatdfdf) +Demo for Axway ![Let's Chat Greylock](http://i.imgur.com/0a3l5VF.png) -#test1 -#test2 ![Screenshot](http://i.imgur.com/C4uMD67.png) -Test Test A self-hosted chat app for small teams or big Gal by [Security Compass][seccom]. -[![Build Status](https://travis-ci.org/sdelements/lets-chat.svg?branch=master)](https://travis-ci.org/sdelements/lets-chat) -[![Dependency Status](https://david-dm.org/sdelements/lets-chat.svg)](https://david-dm.org/sdelements/lets-chat) -[![devDependency Status](https://david-dm.org/sdelements/lets-chat/dev-status.svg)](https://david-dm.org/sdelements/lets-chat#info=devDependencies) + ## Features and Stuff @@ -91,3 +88,159 @@ Released under [the MIT license][license]. [install-docker]: https://registry.hub.docker.com/u/sdelements/lets-chat/ [install-heroku]: https://github.com/sdelements/lets-chat/wiki/Heroku [install-vagrant]: https://github.com/sdelements/lets-chat/wiki/Vagrant + + + + + +![Let's Chat Greylock](https://codefresh.io/wp-content/uploads/2017/03/lets-chat.png) + + +Use this tutorial to familiarize yourself with codefresh.yml file and Codefresh functionality. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/11.png) + + +This tutorial is based on Let’s Chat [app]. + +https://github.com/containers101/demochat + +### Let’s Chat is self-hosted chat app for small teams or big + +This tutorial will walk you through the process of adding the following : + + +* Build step - that will build Docker image for your Let’s Chat app + +* Push to registry step - that will push your image to Docker Hub + +* Unit Test step - A freestyle step that runs the unit test of the demo chat after the build + +* Composition step - This step will create and launch a composition. + +So, the first thing you need to do is : + +## Fork our repo + +Enter the following link and fork Let’s Chat app!: ```https://github.com/containers101/demochat``` + + +## Add a service +Now enter Codefresh and add your Let’s Chat app as a Codefresh service. + +Click on ___Add Repository___ + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/add-repo.png) + + +Now add your forked demochat repo. You can search for it by typing "demochat" to search. You can also Add by URL here. + +Also, choose the branch for your first build (in this case ```master```) + +When you finish press ___Next___. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/select-repo2.png) + + +Select how you would like to setup your repository. In this case, our repo has a ___Dockerfile___, so we'll select the middle option. + + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/15.png) + +By default, Codefresh searches for your Dockerfile at the root level of your repository, by the name "Dockerfile". The demo-chat example includes a Dockerfile in the root level. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/16.png) + + +Review your Dockerfile, and click ___Create___ to add your repository. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/17.png) + +Clicking on ___Build___ button will trigger a regular build. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/18.png) + +Great, you are running your build for the first time! + +## Push your image to Docker registry +In Codefresh the build images will be automatically pushed to Codefresh registry and there’s no need to specify the [Codefresh Docker Registry](https://docs.codefresh.io/v1.0/docs/codefresh-registry) for the block __Push to Docker Registry__ in the pipeline of repository and you can just skip this step. + +Click on ___Repositories___, and then click on the ___Pipelines___ gear. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/19.png) + +Scroll down to ___Workflow___, and you will see a ___Push to Docker___ button. If you have set up your credentials, click ___Save___ at the bottom of the screen. Otherwise- click on the ___integration page___ link. + +Write your User/Password info, and click ___Save___ to connect. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/20.png) + + +## Unit test your image +Let's head over to ___Piplines___ again. +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/19.png) + +Scroll down to Workflow under ___Build and Unit Test___ + +We'll type in ```echo $(date)``` in the Unit Test Script area. This will print the date, and we'll be able to see our test in action. + +Let's click ___Save___, and ___Build___ to see it in action. + +Great- the date has been printed! + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/22.png) + + +Now let's add a full composition that also contains mongo db. + + +## Add composition + +Our Let's Chat app needs mongo in order to work, so let's add it! + +You can read more about compositions in our docs, but we will also walk through the process here : +https://docs.codefresh.io/docs/create-composition + + +Click the ___Composition___ view icon in the left pane, and click the ___Add Composition___. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/1.png) + +Choose a name for your composition + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/2.png) + +We are going to build our comp from scrath, so click ___Empty Composition___ + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/04/empty_comp.png) + +Now we will click ___Add Service___ and add demochat, the port (50000), and mongo. +Everything looks good here- so let's go ahead and launch by clicking the rocket ship... + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/04/savelaunch_final.png) + + +Once it has completed, a link to our app will be displayed. Let's click it to see if it worked. + + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/04/completed_in.png) + +Success! We have successfully launched a composition. + +![Screenshot](https://codefresh.io/wp-content/uploads/2017/03/10.png) + + + + + + +[app]: https://github.com/containers101/demochat + +## About Containers 101 + +[Containers 101](https://www.meetup.com/Containers-101-meetup/) is online/offline meetup group based in Mountain View that provides guides and helps developers work with Containers. Created by [Codefresh](https://codefresh.io/) which provides environments for every commit, Docker CI and CD, and an embedded registry. + +[Join Containers 101](https://www.meetup.com/Containers-101-meetup/) +Learn more about [Codefresh](https://codefresh.io/) + + diff --git a/annotation.yml b/annotation.yml new file mode 100644 index 000000000..38f9c3a9d --- /dev/null +++ b/annotation.yml @@ -0,0 +1,46 @@ +version: '1.0' +steps: + BuildingDockerImage: + title: Building Docker Image + type: build + image_name: demochat + working_directory: ./ + dockerfile: Dockerfile + metadata: # Declare the metadata attribute + set: # Specify the set operation + - Unit_Test: true + - API_Test: true + - Ave_Res_Time: 2 msec + - Packet_Loss: 0 + - Security: true + # RunningUnitTests: + # title: Running Unit Tests + # type: composition + # composition: 5959cfa8e82afd0001bb2f1c + # composition_candidates: + # demochat: + # image: '${{BuildingDockerImage}}' + # entrypoint: sh /codefresh/volume/cf-generated/unit_test_script + # volumes: + # - '${{CF_VOLUME_NAME}}:/codefresh/volume' + # add_flow_volume_to_composition: true + # create_file: + # path: /codefresh/volume/cf-generated + # name: unit_test_script + # content: npm test + # on_success: + # metadata: + # set: + # - '${{BuildingDockerImage.imageId}}': + # - CF_QUALITY: true +# - Unit Test: true +# - API Test: true +# - Performance: Average Response Time 2msec +# - Performance: 0 Packet Loss +# - Security: true +# on_fail: +# metadata: +# set: +# - '${{BuildingDockerImage.imageId}}': +# - CF_QUALITY: false + diff --git a/app.js b/app.js index 0893b113f..c8b400095 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ // -// Let's Chat +// Let's Chat main file // 'use strict'; @@ -8,40 +8,40 @@ process.title = 'letschat'; require('colors'); -var _ = require('lodash'), - path = require('path'), - fs = require('fs'), - express = require('express.oi'), - i18n = require('i18n'), - bodyParser = require('body-parser'), +var _ = require('lodash'), + path = require('path'), + fs = require('fs'), + express = require('express.oi'), + i18n = require('i18n'), + bodyParser = require('body-parser'), cookieParser = require('cookie-parser'), - compression = require('compression'), - helmet = require('helmet'), - http = require('http'), - nunjucks = require('nunjucks'), - mongoose = require('mongoose'), - migroose = require('./migroose'), + compression = require('compression'), + helmet = require('helmet'), + http = require('http'), + nunjucks = require('nunjucks'), + mongoose = require('mongoose'), + migroose = require('./migroose'), connectMongo = require('connect-mongo'), - all = require('require-tree'), - psjon = require('./package.json'), - settings = require('./app/config'), - auth = require('./app/auth/index'), - core = require('./app/core/index'); - -var MongoStore = connectMongo(express.session), - httpEnabled = settings.http && settings.http.enable, + all = require('require-tree'), + psjon = require('./package.json'), + settings = require('./app/config'), + auth = require('./app/auth/index'), + core = require('./app/core/index'); + +var MongoStore = connectMongo(express.session), + httpEnabled = settings.http && settings.http.enable, httpsEnabled = settings.https && settings.https.enable, - models = all(path.resolve('./app/models')), - middlewares = all(path.resolve('./app/middlewares')), - controllers = all(path.resolve('./app/controllers')), + models = all(path.resolve('./app/models')), + middlewares = all(path.resolve('./app/middlewares')), + controllers = all(path.resolve('./app/controllers')), app; // // express.oi Setup // if (httpsEnabled) { - app = express().https({ - key: fs.readFileSync(settings.https.key), + app = express().https({ + key: fs.readFileSync(settings.https.key), cert: fs.readFileSync(settings.https.cert) }).io(); } else { @@ -56,20 +56,20 @@ if (settings.env === 'production') { // Session var sessionStore = new MongoStore({ - url: settings.database.uri, + url: settings.database.uri, autoReconnect: true }); // Session var session = { - key: 'connect.sid', - secret: settings.secrets.cookie, - store: sessionStore, - cookie: { secure: httpsEnabled }, - resave: false, + key: 'connect.sid', + secret: settings.secrets.cookie, + store: sessionStore, + cookie: { secure: httpsEnabled }, + resave: false, saveUninitialized: true }; - +debugger; // Set compression before any routes app.use(compression({ threshold: 512 })); @@ -85,32 +85,32 @@ app.use(helmet.ieNoOpen()); app.use(helmet.noSniff()); app.use(helmet.xssFilter()); app.use(helmet.hsts({ - maxAge: 31536000, + maxAge: 31536000, includeSubdomains: true, - force: httpsEnabled, - preload: true + force: httpsEnabled, + preload: true })); app.use(helmet.contentSecurityPolicy({ defaultSrc: ['\'none\''], connectSrc: ['*'], - scriptSrc: ['\'self\'', '\'unsafe-eval\''], - styleSrc: ['\'self\'', 'fonts.googleapis.com', '\'unsafe-inline\''], - fontSrc: ['\'self\'', 'fonts.gstatic.com'], - mediaSrc: ['\'self\''], - objectSrc: ['\'self\''], - imgSrc: ['*'] + scriptSrc: ['\'self\'', '\'unsafe-eval\''], + styleSrc: ['\'self\'', 'fonts.googleapis.com', '\'unsafe-inline\''], + fontSrc: ['\'self\'', 'fonts.gstatic.com'], + mediaSrc: ['\'self\''], + objectSrc: ['\'self\''], + imgSrc: ['*'] })); var bundles = {}; app.use(require('connect-assets')({ - paths: [ + paths: [ 'media/js', 'media/less' ], - helperContext: bundles, - build: settings.env === 'production', + helperContext: bundles, + build: settings.env === 'production', fingerprinting: settings.env === 'production', - servePath: 'media/dist' + servePath: 'media/dist' })); // Public @@ -121,24 +121,24 @@ app.use('/media', express.static(__dirname + '/media', { // Templates var nun = nunjucks.configure('templates', { autoescape: true, - express: app, - tags: { - blockStart: '<%', - blockEnd: '%>', + express: app, + tags: { + blockStart: '<%', + blockEnd: '%>', variableStart: '<$', - variableEnd: '$>', - commentStart: '<#', - commentEnd: '#>' + variableEnd: '$>', + commentStart: '<#', + commentEnd: '#>' } }); function wrapBundler(func) { // This method ensures all assets paths start with "./" // Making them relative, and not absolute - return function() { + return function () { return func.apply(func, arguments) - .replace(/href="\//g, 'href="./') - .replace(/src="\//g, 'src="./'); + .replace(/href="\//g, 'href="./') + .replace(/src="\//g, 'src="./'); }; } @@ -148,7 +148,7 @@ nun.addGlobal('text_search', false); // i18n i18n.configure({ - directory: __dirname + '/locales', + directory: __dirname + '/locales', defaultLocale: settings.i18n && settings.i18n.locale || 'en' }); app.use(i18n.init); @@ -160,7 +160,7 @@ app.use(bodyParser.urlencoded({ })); // IE header -app.use(function(req, res, next) { +app.use(function (req, res, next) { res.setHeader('X-UA-Compatible', 'IE=Edge,chrome=1'); next(); }); @@ -168,13 +168,13 @@ app.use(function(req, res, next) { // // Controllers // -_.each(controllers, function(controller) { +_.each(controllers, function (controller) { controller.apply({ - app: app, - core: core, - settings: settings, + app: app, + core: core, + settings: settings, middlewares: middlewares, - models: models, + models: models, controllers: controllers }); }); @@ -183,13 +183,7 @@ _.each(controllers, function(controller) { // Mongo // -mongoose.connection.on('error', function (err) { - throw new Error(err); -}); -mongoose.connection.on('disconnected', function() { - throw new Error('Could not connect to database'); -}); // // Go Time @@ -197,17 +191,16 @@ mongoose.connection.on('disconnected', function() { function startApp() { var port = httpsEnabled && settings.https.port || - httpEnabled && settings.http.port; + httpEnabled && settings.http.port; var host = httpsEnabled && settings.https.host || - httpEnabled && settings.http.host || '0.0.0.0'; - + httpEnabled && settings.http.host || '0.0.0.0'; if (httpsEnabled && httpEnabled) { // Create an HTTP -> HTTPS redirect server var redirectServer = express(); - redirectServer.get('*', function(req, res) { + redirectServer.get('*', function (req, res) { var urlPort = port === 80 ? '' : ':' + port; res.redirect('https://' + req.hostname + urlPort + req.path); }); @@ -247,11 +240,11 @@ function checkForMongoTextSearch() { return; } - if(version[0] < 2) { + if (version[0] < 2) { return; } - if(version[0] === '2' && version[1] < 6) { + if (version[0] === '2' && version[1] < 6) { return; } @@ -259,19 +252,22 @@ function checkForMongoTextSearch() { }); } -mongoose.connect(settings.database.uri, function(err) { - if (err) { - throw err; - } +var connectionTries = 0; + + +function handleMongoConnectionState(err) { + - checkForMongoTextSearch(); + //checkForMongoTextSearch(); + + migroose.needsMigration(function (err, migrationRequired) { - migroose.needsMigration(function(err, migrationRequired) { if (err) { console.error(err); } else if (migrationRequired) { + console.log('Database migration required'.red); console.log('Ensure you backup your database first.'); console.log(''); @@ -282,6 +278,77 @@ mongoose.connect(settings.database.uri, function(err) { return process.exit(); } + console.log('starting app'); startApp(); }); + +} + +const Kefir = require('kefir'); +const interval = 2000; +const Promise = require('bluebird'); +const retry = require('bluebird-retry') +const MongoClient = require('mongodb').MongoClient; +const chalk = require('chalk'); +const debug = require('debug')('app'); + +function tryConnect(callback) { + + console.log(chalk.green('Connecting to database...')); + console.log(chalk.green(new Date())); + console.log(chalk.green(`connection is ${settings.database.uri}`)); + + let p, wrapper = {} + +try{ + + p= MongoClient.connect(settings.database.uri, + {connectTimeoutMS:3000, reconnectTries:1, promiseLibrary:Promise}); + console.log('!!'); + + wrapper = new Promise((resolve, reject)=>{ + p.then(resolve, reject); + }); + + mongoose.connection.on('error', function (err) { + console.log(chalk.red(`connection on error ${err}`)); + callback(err); + }); + + mongoose.connection.on('disconnected', function (err) { + console.log(`disconnected from database error : ${err}`); + callback("error"); + }); +}catch(e){ + console.log(e + exception); + return Promise.reject(); +} +process.on('uncaughtException', function (err) { + debug('uncaughtException: probably due to ' + err); +}) + +console.log(chalk.green('connection in progress')); +p.then(()=>{ + chalk.green('promise resolved '); +},()=>{ + chalk.green('promise rejected '); +}) +return p; + +} +let checkTimeout = ()=>{ + console.log('check timeout'); + return new Promise((resolve, reject)=>{ + setTimeout(1000, ()=>{ + console.log('rejected') + return reject(); + }) + }) +} + + let p = retry(tryConnect, { max_tries: 5, interval: 4000,timeout:30000 }) + .then(handleMongoConnectionState,()=>{ + console.log(chalk.red('we coudnt connect to DB check if its up')); + process.exit(); + }); diff --git a/app/config.js b/app/config.js index 1f2c7b009..876135141 100644 --- a/app/config.js +++ b/app/config.js @@ -165,6 +165,9 @@ var pipeline = [ if (process.env.MONGO_DOCKER) { context.result.database.uri = process.env.MONGO_DOCKER; } + if (process.env.MONGO_HELM) { + context.result.database.uri = "mongodb://" + process.env.MONGO_HELM + ":27017/hp_mongo"; + } }, function openShift(context) { diff --git a/app/tests/mongo.unit.spec.js b/app/tests/mongo.unit.spec.js deleted file mode 100644 index 1a0f4c8ed..000000000 --- a/app/tests/mongo.unit.spec.js +++ /dev/null @@ -1,57 +0,0 @@ -var debug = require('debug')('model->test'); -var mongoose = require('mongoose'); - - -var TestSchema = new mongoose.Schema({ - testField: { - type: String, - required: true//, - // trim: true - } -}); -var Entity = mongoose.model('Test1', TestSchema); -var enitytToSave = new Entity({testField:'test1123232'}); -var dbRemote = 'mongodb://admin:hpadmin@ds037415.mongolab.com:37415/hp_mongo'; -var db_local = 'mongodb://192.168.99.100:27017/hp_mongo'; -var db_docker = 'mongodb://mongo:27017/hp_mongo'; - -describe('sanity tests', function(done){ - -it('test mongo connection' , function(done){ - - mongoose.connect(dbRemote, function(err) { - - if (err) { - console.log(err); - throw err; - } - - console.log('mongo is connected'); - enitytToSave.save(function(err) { - //done(err); - debug('after save:' + err ); - if (err) { - console.log('saved process finished with error') - return done(err); - } - debug('saved succesfully'); - console.log('test entity succesfully saved'); - mongoose.connection.close(); - return done(null); - }); - }); - }); - -}); - - -/*Object.keys(user).forEach(function(key) { - debug('key:' + key); - userToSave.set(key, user[key]); -});*/ - -/* User.findByToken(username, function(err, user) { - if (err) { return done(err); } - if (!user) { return done(null, false); } - return done(null, user); -});*/ diff --git a/app/tests/tmpTocken b/app/tests/tmpTocken new file mode 100644 index 000000000..e2b0ed32a --- /dev/null +++ b/app/tests/tmpTocken @@ -0,0 +1 @@ +ya29.Gl1LBIp2oGmdfG9JDqeD9fphy1Sm9DE81Y7gZegZSCnkPbn2arXARmW7NQqsiRvtH_B958CHjVFcv-T7Yn1ebI9VCwzmGlo6p7zzTGELB1Tl9huBZeP3EuyYBea2aBI diff --git a/codefresh.yml b/codefresh.yml new file mode 100644 index 000000000..d6ca58c3d --- /dev/null +++ b/codefresh.yml @@ -0,0 +1,67 @@ +version: '1.0' +steps: + build_step: + title: Build + type: build + dockerfile: Dockerfile + image_name: demochat + tag: '${{CF_BRANCH}}' + +# unit_tests: +# title: Unit Tests +# image: ${{build_step}} +# fail_fast: false +# working-directory : /usr/src/app +# commands: +# - npm test + + unit_test: + type: composition + working_directory: '${{main_clone}}' + composition: + version: '2' + services: + mongo: + image: 'mongo:latest' + ports: + - 27017 + composition_candidates: + test: + image: '${{build_step}}' + command: npm test + push_to_registry: + title: Push To Registry + type: push + candidate: ${{build_step}} + tag: ${{CF_BRANCH}} + + deploy_to_ecs: + title: Deploy Container to ECS + image: codefresh/cf-deploy-ecs + commands: + - >- + cfecs-update --image-name containers101/demochat --image-tag + ${{CF_BRANCH}} eu-west-1 demochat-production demochat-service + environment: + - 'AWS_ACCESS_KEY_ID=${{AWS_ACCESS_KEY_ID}}' + - 'AWS_SECRET_ACCESS_KEY=${{AWS_SECRET_ACCESS_KEY}}' + when: + condition: + all: + deploy_to_ecs: '"${{DEPLOY_ECS}}" == "true"' + + deploy_to_kubernetes: + image: codefresh/cf-deploy-kubernetes + tag: latest + working_directory: ${{main_clone}} + commands: + - /cf-deploy-kubernetes deployment.yml + environment: + - KUBERNETES_USER=${{KUBERNETES_USER}} + - KUBERNETES_PASSWORD=${{KUBERNETES_PASSWORD}} + - KUBERNETES_SERVER=${{KUBERNETES_SERVER}} + - DOCKER_IMAGE_TAG=${{CF_BRANCH}} + when: + condition: + all: + deploy_to_kubernetes: '"${{DEPLOY_KUBERNETES}}" == "true"' diff --git a/codefresh_vars.yml b/codefresh_vars.yml new file mode 100644 index 000000000..14b3da8fc --- /dev/null +++ b/codefresh_vars.yml @@ -0,0 +1,47 @@ +version: '1.0' +steps: + + retrieve-git-hash: + description: retrive git tag + title: Free styling 2 + image: bravissimolabs/alpine-git + commands: + - echo $(git rev-parse --short=5 HEAD) + - export GIT_HASH=$(git rev-parse --short=5 HEAD) + - cf_export GIT_TAG=$GIT_HASH + test-git-hash: + description: retrive git tag! + title: Free styling 2 + image: ubuntu:latest + commands: + - echo $GIT_TAG + build_step: + title: Build + type: build + dockerfile: Dockerfile + image_name: containers101/demochat + tag: '${{CF_BRANCH}}' + + tag: + type: push + title: add version + description: Free text description + candidate: ${{build_step}} + tag: ${{GIT_TAG}} + image_name: verchol/demochat + registry : dockerhub + + deploy_to_kubernetes: + image: codefresh/cf-deploy-kubernetes + tag: latest + commands: + - /cf-deploy-kubernetes deployment.yml + environment: + - KUBERNETES_USER=${{KUBERNETES_USER}} + - KUBERNETES_PASSWORD=${{KUBERNETES_PASSWORD}} + - KUBERNETES_SERVER=${{KUBERNETES_SERVER}} + - DOCKER_IMAGE_TAG=${{CF_BRANCH}} + when: + condition: + all: + deploy_to_kubernetes: '"${{DEPLOY_KUBERNETES}}" == "true"' diff --git a/deploy/all.yaml b/deploy/all.yaml new file mode 100644 index 000000000..bf9a1f1ae --- /dev/null +++ b/deploy/all.yaml @@ -0,0 +1,110 @@ + +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demo-chat + labels: + deploy: test1 + service: demo-chat + app: demo-chat +spec: + replicas: 2 + template: + metadata: + labels: + deploy: test1 + service: demo-chat + spec: + imagePullSecrets: + - name: cfcr + containers: + - image: containers101/demochat:master + name: app + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP +--- + apiVersion: extensions/v1beta1 + kind: Ingress + metadata: + labels: + deploy: test1 + name: demochat-ingress + spec: + backend: + serviceName: demochat-board + servicePort: 80 +--- + apiVersion: v1 + kind: Service + metadata: + labels: + deploy: test1 + name: demochat-master + spec: + type: NodePort + selector: + app: demo-chat + ports: + - name: "http" + port: 80 + protocol: TCP + targetPort: 5000 + selector: + service: demochat-board +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: mongo + name: mongo +spec: + type: NodePort + ports: + - name: "http" + port: 27017 + protocol: TCP + targetPort: 27017 + selector: + service: mongo +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: mongo +spec: + backend: + serviceName: mongo + servicePort: 27017 +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + annotations: + io.codefresh.owner: codefresh + name: mongo +spec: + replicas: 1 + template: + metadata: + labels: + service: mongo + spec: + containers: + - args: + - mongod + - --smallfiles + image: mongo:latest + name: mongo + ports: + - containerPort: 27017 + protocol: TCP + volumeMounts: + - mountPath: /data/db + name: mongo-data + restartPolicy: Always + volumes: + - name: mongo-data + emptyDir: {} diff --git a/deploy/bluegreen/codefresh.yaml b/deploy/bluegreen/codefresh.yaml new file mode 100644 index 000000000..0672644b8 --- /dev/null +++ b/deploy/bluegreen/codefresh.yaml @@ -0,0 +1,25 @@ +version: '1.0' +steps: +# BuildingDockerImage: +# title: Building Docker Image +# type: build +# image_name: containers101/demochat +# working_directory: ./ +# dockerfile: Dockerfile +# tag: '${{CF_SHORT_REVISION}}' + BlueGreenDeploy: + title: Perform a Blue Green Deployment + image: codefresh/kube-helm:master + environment: + - KUBE_CONTEXT=helmdemo@jFrog-Helm + - NAMESPACE=bluegreen + commands: + - echo "Starting commands" + - kubectl config use-context ${KUBE_CONTEXT} + - export BlueVersion=$(kubectl get service demochat -o=jsonpath='{.spec.selector.version}' --namespace=bluegreen) #find deployed version + - export EndPoint=$(kubectl get service demochat -o jsonpath="{.status.loadBalancer.ingress[*].ip}" --namespace=bluegreen) #Find exposed service + - kubectl get deployment demochat-$BlueVersion -o=yaml --namespace=bluegreen | sed -e "s/$BlueVersion/${{CF_SHORT_REVISION}}/g" | kubectl apply --namespace=bluegreen -f - #New Deployment + - sleep 30 #wait for deployment to finish, replace with better version + #- curl --silent --show-error --fail $EndPoint #Health Check + - kubectl get service demochat -o=yaml --namespace=bluegreen | sed -e "s/$BlueVersion/${{CF_SHORT_REVISION}}/g" | kubectl apply --namespace=bluegreen -f - #Update Service YAML with Green version + - kubectl delete deployment demochat-$BlueVersion --namespace=bluegreen diff --git a/deploy/bluegreen/demochat-deployment-3f41f72.yaml b/deploy/bluegreen/demochat-deployment-3f41f72.yaml new file mode 100644 index 000000000..73417f2b1 --- /dev/null +++ b/deploy/bluegreen/demochat-deployment-3f41f72.yaml @@ -0,0 +1,24 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochat-3f41f72 +spec: + replicas: 2 + template: + metadata: + annotations: + forceRedeployUniqId: "3f41f72" + labels: + name: demochat + version: "3f41f72" + spec: + containers: + - name: demochat + image: r.cfcr.io/jfrog-azure-demo/containers101/demochat:helm-bitbucket-merge-3f41f72 + imagePullPolicy: Always + ports: + - name: http + containerPort: 5000 + protocol: TCP + imagePullSecrets: + - name: codefresh-generated-r.cfcr.io-cfcr-bluegreen diff --git a/deploy/bluegreen/demochat-deployment-55cb26a.yaml b/deploy/bluegreen/demochat-deployment-55cb26a.yaml new file mode 100644 index 000000000..775d063b8 --- /dev/null +++ b/deploy/bluegreen/demochat-deployment-55cb26a.yaml @@ -0,0 +1,24 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochat-55cb26a +spec: + replicas: 2 + template: + metadata: + annotations: + forceRedeployUniqId: "55cb26a" + labels: + name: demochat + version: "55cb26a" + spec: + containers: + - name: demochat + image: r.cfcr.io/jfrog-azure-demo/containers101/demochat:55cb26a + imagePullPolicy: Always + ports: + - name: http + containerPort: 5000 + protocol: TCP + imagePullSecrets: + - name: codefresh-generated-r.cfcr.io-cfcr-bluegreen diff --git a/deploy/bluegreen/demochat-deployment.yaml b/deploy/bluegreen/demochat-deployment.yaml new file mode 100644 index 000000000..41c8c8ee3 --- /dev/null +++ b/deploy/bluegreen/demochat-deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochat-55cb26a +spec: + replicas: 2 + template: + metadata: + annotations: + forceRedeployUniqId: "55cb26a" + labels: + name: demochat + version: "55cb26a" + spec: + containers: + - name: demochat + image: r.cfcr.io/jfrog-azure-demo/containers101/demochat:55cb26a + imagePullPolicy: Always + ports: + - name: http + containerPort: 5000 + protocol: TCP + imagePullSecrets: + - name: codefresh-generated-r.cfcr.io-cfcr-bluegreen \ No newline at end of file diff --git a/deploy/bluegreen/demochat-service-3f41f72.yaml b/deploy/bluegreen/demochat-service-3f41f72.yaml new file mode 100644 index 000000000..b4f8ef1bb --- /dev/null +++ b/deploy/bluegreen/demochat-service-3f41f72.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: demochat + labels: + name: demochat +spec: + ports: + - name: http + port: 80 + targetPort: 5000 + selector: + name: demochat + version: "3f41f72" + type: LoadBalancer \ No newline at end of file diff --git a/deploy/bluegreen/demochat-service-55cb26a.yaml b/deploy/bluegreen/demochat-service-55cb26a.yaml new file mode 100644 index 000000000..57c2a57c9 --- /dev/null +++ b/deploy/bluegreen/demochat-service-55cb26a.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: demochat + labels: + name: demochat +spec: + ports: + - name: http + port: 80 + targetPort: 5000 + selector: + name: demochat + version: "55cb26a" + type: LoadBalancer \ No newline at end of file diff --git a/deploy/bluegreen/demochat-service-live.yaml b/deploy/bluegreen/demochat-service-live.yaml new file mode 100644 index 000000000..440d5dd84 --- /dev/null +++ b/deploy/bluegreen/demochat-service-live.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"creationTimestamp":"2018-04-06T19:58:30Z","labels":{"name":"demochat"},"name":"demochat","namespace":"bluegreen","resourceVersion":"11889475","selfLink":"/api/v1/namespaces/bluegreen/services/demochat","uid":"e116fa58-39d4-11e8-ba2e-42010a800123"},"spec":{"clusterIP":"10.55.253.63","externalTrafficPolicy":"Cluster","ports":[{"name":"http","nodePort":31082,"port":80,"protocol":"TCP","targetPort":5000}],"selector":{"name":"demochat","version":"223270b"},"sessionAffinity":"None","type":"LoadBalancer"},"status":{"loadBalancer":{"ingress":[{"ip":"35.184.62.129"}]}}} + creationTimestamp: 2018-04-06T19:58:30Z + labels: + name: demochat + name: demochat + namespace: bluegreen + resourceVersion: "11892802" + selfLink: /api/v1/namespaces/bluegreen/services/demochat + uid: e116fa58-39d4-11e8-ba2e-42010a800123 +spec: + clusterIP: 10.55.253.63 + externalTrafficPolicy: Cluster + ports: + - name: http + nodePort: 31082 + port: 80 + protocol: TCP + targetPort: 5000 + selector: + name: demochat + version: 3f41f72 + sessionAffinity: None + type: LoadBalancer +status: + loadBalancer: + ingress: + - ip: 35.184.62.129 \ No newline at end of file diff --git a/deploy/bluegreen/example/blue.yaml b/deploy/bluegreen/example/blue.yaml new file mode 100644 index 000000000..723010364 --- /dev/null +++ b/deploy/bluegreen/example/blue.yaml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: nginx-1.10 +spec: + replicas: 3 + template: + metadata: + labels: + name: nginx + version: "1.10" + spec: + containers: + - name: nginx + image: nginx:1.10 + ports: + - name: http + containerPort: 80 diff --git a/deploy/bluegreen/example/green.yaml b/deploy/bluegreen/example/green.yaml new file mode 100644 index 000000000..ee3f3e65a --- /dev/null +++ b/deploy/bluegreen/example/green.yaml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: nginx-1.11 +spec: + replicas: 3 + template: + metadata: + labels: + name: nginx + version: "1.11" + spec: + containers: + - name: nginx + image: nginx:1.11 + ports: + - name: http + containerPort: 80 diff --git a/deploy/bluegreen/example/service.yaml b/deploy/bluegreen/example/service.yaml new file mode 100644 index 000000000..57c315c48 --- /dev/null +++ b/deploy/bluegreen/example/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + name: nginx +spec: + ports: + - name: http + port: 80 + targetPort: 80 + selector: + name: nginx + version: "1.10" + type: LoadBalancer diff --git a/deploy/kube-app.yml b/deploy/kube-app.yml new file mode 100644 index 000000000..29b344fc3 --- /dev/null +++ b/deploy/kube-app.yml @@ -0,0 +1,21 @@ +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demo-chat + labels: + service: demo-chat +spec: + replicas: 1 + template: + metadata: + labels: + service: demo-chat + spec: + containers: + - image: ${{build_step}} + name: app + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP diff --git a/deploy/kube-ingress-demo.yml b/deploy/kube-ingress-demo.yml new file mode 100644 index 000000000..062ee0916 --- /dev/null +++ b/deploy/kube-ingress-demo.yml @@ -0,0 +1,8 @@ +apiVersion: extensions/v1beta1g +kind: Ingress +metadata: + name: demochat-ingress +spec: + backend: + serviceName: demochat-board + servicePort: 80 diff --git a/deploy/kube-ingress.yml b/deploy/kube-ingress.yml new file mode 100644 index 000000000..48b232d68 --- /dev/null +++ b/deploy/kube-ingress.yml @@ -0,0 +1,25 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: demo-chat + name: demo-chat +spec: + type: NodePort + ports: + - name: "http" + port: 80 + protocol: TCP + targetPort: 5000 + selector: + service: demo-chat +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: demochat-ingress +spec: + backend: + serviceName: demochat-board + servicePort: 80 diff --git a/deploy/kube-mongo.yml b/deploy/kube-mongo.yml new file mode 100644 index 000000000..8cfa8aa1c --- /dev/null +++ b/deploy/kube-mongo.yml @@ -0,0 +1,71 @@ +#--- +#kind: StorageClass +#apiVersion: storage.k8s.io/v1beta1 +#metadata: +# name: gce-disk +#provisioner: kubernetes.io/gce-pd +#parameters: +# type: pd-ssd + +#--- +#apiVersion: v1 +#kind: PersistentVolume +#metadata: + #name: mongo-volume + #annotations: + # volume.beta.kubernetes.io/storage-class: gce-disk +#spec: + #accessModes: + # - ReadWriteOnce + #capacity: + # storage: 5Gi + #hostPath: + # path: /data/pv0001/ + +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + io.codefresh.owner: codefresh + labels: + service: mongo + name: mongo +spec: + ports: + - name: "mongodb" + port: 27017 + protocol: TCP + targetPort: 27017 + selector: + service: mongo +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + annotations: + io.codefresh.owner: codefresh + name: mongo +spec: + replicas: 1 + template: + metadata: + labels: + service: mongo + spec: + containers: + - args: + - mongod + - --smallfiles + image: mongo:latest + name: mongo + ports: + - containerPort: 27017 + protocol: TCP + volumeMounts: + - mountPath: /data/db + name: mongo-data + restartPolicy: Always + volumes: + - name: mongo-data + emptyDir: {} diff --git a/deploy/kube-service.yml b/deploy/kube-service.yml new file mode 100644 index 000000000..149345abf --- /dev/null +++ b/deploy/kube-service.yml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: demochat-master + name: demochat-master +spec: + type: NodePort + ports: + - name: "http" + port: 80 + protocol: TCP + targetPort: 5000 + selector: + service: demochat-board diff --git a/deploy/mongo/kube-service.yml b/deploy/mongo/kube-service.yml new file mode 100644 index 000000000..149345abf --- /dev/null +++ b/deploy/mongo/kube-service.yml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: demochat-master + name: demochat-master +spec: + type: NodePort + ports: + - name: "http" + port: 80 + protocol: TCP + targetPort: 5000 + selector: + service: demochat-board diff --git a/deploy/mongo/mongo-ingress.yml b/deploy/mongo/mongo-ingress.yml new file mode 100644 index 000000000..4786b3b6b --- /dev/null +++ b/deploy/mongo/mongo-ingress.yml @@ -0,0 +1,25 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: mongo + name: mongo +spec: + type: NodePort + ports: + - name: "http" + port: 27017 + protocol: TCP + targetPort: 27017 + selector: + service: mongo +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: mongo +spec: + backend: + serviceName: mongo + servicePort: 27017 diff --git a/deployment-board-demo.yml b/deployment-board-demo.yml new file mode 100644 index 000000000..a32419b74 --- /dev/null +++ b/deployment-board-demo.yml @@ -0,0 +1,23 @@ +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochatboard + labels: + service: demochatboard +spec: + replicas: 2 + template: + metadata: + annotations: + forceRedeployUniqId: "{{CF_REVISION}}" + labels: + service: demochatboard + spec: + containers: + - image: verchol/demochat-board:{{CF_BRANCH}} + name: app + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP diff --git a/deployment-master.yml b/deployment-master.yml new file mode 100644 index 000000000..93c392efe --- /dev/null +++ b/deployment-master.yml @@ -0,0 +1,23 @@ +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochatmaster + labels: + service: demochatmaster +spec: + replicas: 1 + template: + metadata: + annotations: + forceRedeployUniqId: "{{CF_REVISION}}" + labels: + service: demochatmaster + spec: + containers: + - image: verchol/demochat-board:{{CF_BRANCH}} + name: app + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP diff --git a/deployment.yml b/deployment.yml new file mode 100644 index 000000000..7fe897ac6 --- /dev/null +++ b/deployment.yml @@ -0,0 +1,23 @@ +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: demochat-master + labels: + service: demochat-master +spec: + replicas: 1 + template: + metadata: + annotations: + forceRedeployUniqId: "{{CF_REVISION}}" + labels: + service: app + spec: + containers: + - image: verchol/demochat:{{CF_BRANCH}} + name: app + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..272447f2b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +#this is an example of a self-hosted chat app. +#the composition uses just mongo as a database and an image that was built from a demo application https://github.com/containers101/demochat + +version: '2' +services: + demochat: + image: demochat:0.1 + ports: + - 5000:5000 + depends_on: + - mongo + mongo: + image: mongo diff --git a/fullpipeline.yml b/fullpipeline.yml new file mode 100644 index 000000000..9f6740f4a --- /dev/null +++ b/fullpipeline.yml @@ -0,0 +1,111 @@ +version: '1.0' +steps: + BuildingDockerImage: + title: Building Docker Image + type: build + image_name: containers101/demochat + working_directory: ./ + dockerfile: Dockerfile + tag: '${{CF_BRANCH_TAG_NORMALIZED}}' + RunningUnitTests: + title: Running Unit Tests + image: '${{BuildingDockerImage}}' + working_directory: IMAGE_WORK_DIR + commands: + - bash unit_test.sh + on_success: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - CF_QUALITY: true + on_fail: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - CF_QUALITY: false + RunningPerformanceTests: + title: Running Performance Tests + type: composition + composition: + version: '2' + services: + aut: + ports: + - 5000 + image: 'containers101/demochat:master' + mongo: + image: mongo + composition_candidates: + cfintegration: + image: 'r.cfcr.io/razielt77_github/razielt/taurus:master' + command: bash runtests + environment: + - CF_VOLUME_PATH=${{CF_VOLUME_PATH}} + - TOKEN=${{TOKEN}} + volumes: + - '${{CF_VOLUME_NAME}}:/codefresh/volume' + add_flow_volume_to_composition: true + when: + condition: + all: + testresults: '"${{FAIL}}" == "0"' + on_success: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - CF_QUALITY: true + - PerformanceReport: ${{PER_LINK}} + on_fail: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - CF_QUALITY: false + add_jira_info: + title: Parsing jira Commit + image: r.cfcr.io/razielt77_github/containers101/annotator:master + command: + - bash script.sh + working_directory: IMAGE_WORK_DIR + environment: + - CF_COMMIT_MESSAGE = ${{CF_COMMIT_MESSAGE}} + - CF_VOLUME_PATH=${{CF_VOLUME_PATH}} + export: + title: "Exporting variables..." + image: alpine + commands: + - echo "Exporting variables..." + set_metadata: + title: "Setting metadata on image..." + image: alpine + commands: + - echo "Setting metadata on image..." + on_finish: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - Jira: ${{JIRA_URL}} + - PerformanceReport: ${{PER_LINK}} + - PerformanceLatency: ${{PER_LATE}} + - UnitCoverage: ${{UNIT_COV}} + - Unit: ${{UNIT}} + rename_env: + title: Run and rename environment + type: launch-composition + composition: 'full-application' + environment_name: '${{CF_REPO_OWNER}}-${{CF_REPO_NAME}}-${{CF_COMMIT_AUTHOR}}' + when: + condition: + all: + testresults: '"${{FAIL}}" == "1"' + passfail: + title: failed + image: alpine + commands: + - echo "exit ${{FAIL}}" + - sh -c "exit ${{FAIL}}" + on_fail: + metadata: + set: + - '${{BuildingDockerImage.imageId}}': + - CF_QUALITY: false + diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/helm/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/helm/demochat/Chart.yaml b/helm/demochat/Chart.yaml new file mode 100644 index 000000000..77b3c13a9 --- /dev/null +++ b/helm/demochat/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: demochat +version: 0.2.0 +icon: https://codefresh.io/wp-content/uploads/2018/01/demochat.png diff --git a/helm/demochat/charts/mongo-0.2.0.tgz b/helm/demochat/charts/mongo-0.2.0.tgz new file mode 100644 index 000000000..a06b1d8d0 Binary files /dev/null and b/helm/demochat/charts/mongo-0.2.0.tgz differ diff --git a/helm/demochat/requirements.lock b/helm/demochat/requirements.lock new file mode 100644 index 000000000..ee5eba010 --- /dev/null +++ b/helm/demochat/requirements.lock @@ -0,0 +1,10 @@ +dependencies: +- condition: "" + enabled: false + import-values: null + name: mongo + repository: https://razielt77.github.com/helm + tags: null + version: 0.2.0 +digest: sha256:85ecfc6c5c80a77823ba6ad7ca5758d2f78eaec105d89ceee30b419d8ed6fe47 +generated: 2018-01-16T21:52:04.399476-08:00 diff --git a/helm/demochat/requirements.yaml b/helm/demochat/requirements.yaml new file mode 100644 index 000000000..b9485b56f --- /dev/null +++ b/helm/demochat/requirements.yaml @@ -0,0 +1,5 @@ +dependencies: +- name: mongo + version: "0.2.0" + repository: "https://razielt77.github.com/helm" + diff --git a/helm/demochat/templates/NOTES.txt b/helm/demochat/templates/NOTES.txt new file mode 100644 index 000000000..35af16efd --- /dev/null +++ b/helm/demochat/templates/NOTES.txt @@ -0,0 +1,17 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.hostname }} + http://{{- .Values.ingress.hostname }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.externalPort }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fullname" . }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:{{ .Values.service.externalPort }} +{{- end }} diff --git a/helm/demochat/templates/_helpers.tpl b/helm/demochat/templates/_helpers.tpl new file mode 100644 index 000000000..f0d83d2ed --- /dev/null +++ b/helm/demochat/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm/demochat/templates/deployment.yaml b/helm/demochat/templates/deployment.yaml new file mode 100644 index 000000000..2a75a969e --- /dev/null +++ b/helm/demochat/templates/deployment.yaml @@ -0,0 +1,30 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{.Release.Name}} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + app: {{.Release.Name}} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{.Release.Name}} + release: {{.Release.Name}} + heritage: Tiller + spec: + {{- if .Values.imagePullSecret }} + imagePullSecrets: + - name: "{{.Values.imagePullSecret}}" + {{- end }} + containers: + - name: {{.Release.Name}} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + env: + - name: MONGO_HELM + value: "{{.Release.Name}}-mongo" + diff --git a/helm/demochat/templates/ingress.yaml b/helm/demochat/templates/ingress.yaml new file mode 100644 index 000000000..8efbd1876 --- /dev/null +++ b/helm/demochat/templates/ingress.yaml @@ -0,0 +1,35 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := .Release.Name -}} +{{- $servicePort := .Values.service.externalPort -}} +{{- $path := .Release.Name -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + labels: + app: {{ .Release.Name }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +# release: "{{ .Release.Name }}" +# heritage: "{{ .Release.Service }}" +# annotations: +# ingress.kubernetes.io/rewrite-target: / +# annotations: +# {{- range $key, $value := .Values.ingress.annotations }} +# {{ $key }}: {{ $value | quote }} +# {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: /{{ $path }} + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/helm/demochat/templates/service.yaml b/helm/demochat/templates/service.yaml new file mode 100644 index 000000000..9ac36a913 --- /dev/null +++ b/helm/demochat/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{.Release.Name}} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + app: {{.Release.Name}} + release: {{.Release.Name}} + heritage: Tiller +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + protocol: TCP +# targetPort: {{ .Values.service.internalPort }} +# name: {{ .Values.service.name }} + selector: + app: {{.Release.Name}} diff --git a/helm/demochat/values.yaml b/helm/demochat/values.yaml new file mode 100644 index 000000000..ef8711d3d --- /dev/null +++ b/helm/demochat/values.yaml @@ -0,0 +1,34 @@ +# Default values for mongo. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +imagePullSecret: codefresh-generated-r.cfcr.io-cfcr-default +image: + repository: r.cfcr.io/razielt77_github/containers101/demochat + tag: master + pullPolicy: IfNotPresent +service: + name: demochat + type: LoadBalancer + externalPort: 5000 + internalPort: 5000 +ingress: + enabled: false + # Used to create Ingress record (should used with service.type: ClusterIP). + hosts: + - minikube + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - secretName: chart-example-tls + # hosts: + # - chart-example.local +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi diff --git a/k8deployment.yml b/k8deployment.yml new file mode 100644 index 000000000..362542144 --- /dev/null +++ b/k8deployment.yml @@ -0,0 +1,13 @@ +version: '1.0' +steps: + RunningDeployScript: + title: Running Deploy Script + type: deploy + kind: kubernetes + cluster: my-cluster@FirstKubernetes + namespace: default + when: + branch: + only: + - master + service: demochat diff --git a/migroose.js b/migroose.js index e27f9bac2..4f3f969d7 100644 --- a/migroose.js +++ b/migroose.js @@ -16,6 +16,7 @@ module.exports = { }, needsMigration: function(cb) { + return cb(null, false); var runner = new Runner(process.cwd(), 'migrootions'); var migrations = runner.getMigrations(); var lastMigration = migrations.slice(migrations.length - 1)[0]; diff --git a/mongo b/mongo new file mode 100644 index 000000000..eb02d5fa7 --- /dev/null +++ b/mongo @@ -0,0 +1,2 @@ +FROM mongo:latest + diff --git a/package.json b/package.json index cac06b685..c6ca0ef66 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,9 @@ "scripts": { "start": "node $DEBUGGER app.js", "stop": "pkill --signal SIGINT letschat", - "prestart": "migroose", "migrate": "migroose", "test": "mocha ./app/tests" }, - "engine": { - "node": "0.10.x", - "npm": "2.1.x" - }, "repository": { "type": "git", "url": "git://github.com/sdelements/lets-chat.git" @@ -64,26 +59,31 @@ "dependencies": { "async": "^1.4.2", "bcryptjs": "~2.2.2", + "bluebird": "^3.5.0", + "bluebird-retry": "^0.10.1", "body-parser": "^1.14.0", + "chalk": "^1.1.3", "colors": "~1.1.2", "compression": "^1.5.2", "connect-assets": "^5.0.1", "connect-mongo": "^0.8.2", "cookie-parser": "^1.4.0", - "debug": "^2.2.0", + "debug": "^2.6.3", "express.oi": "^0.0.19", "helmet": "^0.11.0", "i18n": "^0.5.0", "js-yaml": "^3.4.2", - "less": "^2.5.1", + "kefir": "^3.7.1", + "less": "2.6.1", "lodash": "^3.10.1", "md5": "^2.0.0", "migroose": "^0.5.0", "migroose-cli": "^0.1.0", "moment": "^2.10.6", - "mongoose": "~4.1.8", + "mongodb": "^2.2.25", + "mongoose": "^4.11.6", "mongoose-unique-validator": "~0.4.1", - "mongoose-validate": "0.0.5", + "mongoose-validate": "https://github.com/Codefresh-Examples/mongoose-validate.git", "multer": "^0.1.8", "node-uuid": "^1.4.3", "node-xmpp-server": "2.1.0", diff --git a/templates/login.html b/templates/login.html index 8548c7437..e2e4a7e6b 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,6 +1,6 @@ <% extends 'base.html' %> -<% block title %>Login · Let's Chat, Friends !!<% endblock %> +<% block title %>Login · Let's Chat<% endblock %> <% block class %>lcb-login animated fadeIn<% endblock %> @@ -14,7 +14,7 @@ <% block body %>
-

Let's Chat

+

Let's Chat Blue 3