From b17854735e105ee58c3c2136419fc0adda1fcc38 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 4 Nov 2016 14:24:23 -0600 Subject: [PATCH 1/3] Initial commit of deployment code --- Dockerfile | 1 + app.js | 13 +++++++---- circle.yaml | 21 ++++++++++++++++++ docker-compose.yml | 24 ++++++++++++++++++++ package.json | 4 +++- scripts/deploy.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 circle.yaml create mode 100644 docker-compose.yml create mode 100644 scripts/deploy.sh diff --git a/Dockerfile b/Dockerfile index 22ba7e318..b98397323 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ WORKDIR /usr/src/app # Setup the environment ENV PATH /usr/src/app/bin:$PATH +ENV TALK_PORT 5000 EXPOSE 5000 # Install app dependencies diff --git a/app.js b/app.js index 7ce7c91ab..c9e44f854 100644 --- a/app.js +++ b/app.js @@ -1,11 +1,16 @@ -/* This is the entrypoint for the Talk Platform server. */ - -// Initialize application framework. const express = require('express'); +const morgan = require('morgan'); +const path = require('path'); const app = express(); +// Middleware declarations. +app.use(morgan('dev')); + +// API Routes. app.use('/api/v1', require('./routes/api')); -app.use('/client/', express.static('./dist')); + +// Static Routes. +app.use('/client/', express.static(path.join(__dirname, 'dist'))); module.exports = app; diff --git a/circle.yaml b/circle.yaml new file mode 100644 index 000000000..f454424d4 --- /dev/null +++ b/circle.yaml @@ -0,0 +1,21 @@ +machine: + node: + version: 6 + services: + - docker + +test: + override: + - MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml ./node_modules/.bin/mocha tests --reporter mocha-junit-reporter + - npm run lint + +deployment: + release: + tag: /[0-9]+(\.[0-9]+)*/ + commands: + - bash ./scripts/deploy.sh + + latest: + branch: master + commands: + - bash ./scripts/deploy.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..ecfac00bc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '2' +services: + + talk: + image: coralproject/talk:latest + build: . + restart: always + ports: + - "5000:5000" + environment: + - "TALK_PORT=5000" + - "TALK_MONGO_URL=mongodb://mongo" + depends_on: + - mongo + + mongo: + image: mongo:3.2 + restart: always + volumes: + - mongo:/data/db + +volumes: + mongo: + external: false diff --git a/package.json b/package.json index 096863202..6d44eb48b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "dependencies": { "debug": "^2.2.0", "express": "^4.14.0", - "mongoose": "^4.6.5" + "mongoose": "^4.6.5", + "morgan": "^1.7.0" }, "devDependencies": { "babel-core": "6.14.0", @@ -65,6 +66,7 @@ "imports-loader": "^0.6.5", "json-loader": "^0.5.4", "mocha": "^3.1.2", + "mocha-junit-reporter": "^1.12.1", "pre-git": "^3.10.0", "pym.js": "^1.1.1", "react": "15.3.2", diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 000000000..5d79c0ef9 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e + +docker login -u $DOCKER_USER -p $DOCKER_PASS + +# Sourced from https://segment.com/blog/ci-at-segment/ + +deploy_tag() { + # Find our individual versions from the tags + if [ -n "$(echo $CIRCLE_TAG | grep -E '.*\..*\..*')" ] + then + major=$(echo $CIRCLE_TAG | cut -d. -f1) + minor=$(echo $CIRCLE_TAG | cut -d. -f2) + patch=$(echo $CIRCLE_TAG | cut -d. -f3) + + major_version_tag=$major + minor_version_tag=$major.$minor + patch_version_tag=$major.$minor.$patch + + tag_list="$major_version_tag $minor_version_tag $patch_version_tag" + else + tag_list=$CIRCLE_TAG + fi + + # Tag the new image with major, minor and patch version tags. + for version in $tag_list + do + echo "==> tagging $version" + docker tag coralproject/talk:latest coralproject/talk:$version + done + + # Push each of the tags to docker hub, including latest + for version in $tag_list latest + do + echo "==> pushing $version" + docker push coralproject/talk:$version + done +} + +deploy_latest() { + echo "==> pushing latest" + docker push coralproject/talk:latest +} + +# build the repo +docker build -t coralproject/talk . + +# deploy based on the env +if [ -n "$CIRCLE_TAG" ] +then + deploy_tag +else + deploy_latest +fi From 09a4bcb213df6f1042f977674e5c16aa10c17ef5 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 4 Nov 2016 14:26:32 -0600 Subject: [PATCH 2/3] Added test badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70e2d1110..d295ef326 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Talk +# Talk [![CircleCI](https://circleci.com/gh/coralproject/talk.svg?style=svg)](https://circleci.com/gh/coralproject/talk) A commenting platform from The Coral Project. [https://coralproject.net](https://coralproject.net) ### Getting Started From 9956249cae09c87455cbc06eb8f7bf230cc8661d Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 4 Nov 2016 14:35:05 -0600 Subject: [PATCH 3/3] Fixed the filename... --- circle.yaml => circle.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename circle.yaml => circle.yml (100%) diff --git a/circle.yaml b/circle.yml similarity index 100% rename from circle.yaml rename to circle.yml