Skip to content
Permalink
Browse files
Started the DevOps Lab
  • Loading branch information
aa7401 committed Nov 11, 2019
1 parent a67949f commit 2b2eb4b864b1ea221294ba44371532006882c4e0
Show file tree
Hide file tree
Showing 26 changed files with 722 additions and 2 deletions.

This file was deleted.

@@ -0,0 +1,28 @@

# DevOps

In this lab you will learn how to deploy your app to a cloud server and how to set up a complete devops build chain. For this tutorial you will need to have an account on the [GitLab](https://gitlab.com) server as we will be learning how to use the GitLab CI continuous integration tools. (Note that GitHub has recently introduced a rival service called [GitHub Actions](https://github.com/features/actions) however at the time of writing this was still in Beta).

Create an account using your University email address and log in. Create an empty private repository called devops and make a note of the git clone URL.

You should now clone the `template-dynamic-website` repository (the original template, not the one you have been using for your assignment) into a temporary location on your computer.

```shell
git clone https://github.coventry.ac.uk/web/template-dynamic-websites.git temp
```

Once cloned you need to _mirror push_ to the empty gitlab repository.

```shell
cd temp/ && git push --mirror xxx
```

## Deploying to the Cloud

Using Heroku

## Running a CI Workflow

Introduction to CI and gitlab Ci

Committing and pushing to trigger the workflow.
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

mkdir screenshots
mkdir trace
node index.js&
node_modules/.bin/jest --runInBand --detectOpenHandles acceptance\ tests/*
kill %1
@@ -0,0 +1,8 @@

path:
- "/."
languages:
- javascript
exclude:
- "**/node_modules/**"
reporter: json
@@ -0,0 +1,2 @@
node_modules/
docs/
@@ -0,0 +1,57 @@

{
"env": {
"es6": true,
"jasmine": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 8
},
"rules": {
"arrow-body-style": 2,
"arrow-spacing": [1, { "before": true, "after": true }],
"brace-style": 2,
"camelcase": [2, {"properties": "never"}],
"complexity": [2, {"max": 3}],
"eol-last": 1,
"eqeqeq": 2,
"global-require": 2,
"handle-callback-err": 2,
"indent": [1, "tab", { "SwitchCase": 1 }],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"linebreak-style": [1, "unix"],
"max-depth": ["error", {"max": 4}],
"max-len": ["error", { "code": 80 }],
"max-nested-callbacks": ["error", {"max": 3}],
"max-params": ["error", {"max": 3}],
"max-statements": ["error", {"max": 10}],
"no-cond-assign": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty": 1,
"no-empty-function": 1,
"no-multiple-empty-lines": 1,
"no-extra-parens": 2,
"no-func-assign": 2,
"no-irregular-whitespace": 1,
"no-magic-numbers": [1, { "ignore": [-1, 0, 1, 2] }],
"no-multi-spaces": 1,
"no-multi-str": 1,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-self-assign": 2,
"no-trailing-spaces": 1,
"no-undef": 2,
"no-unused-vars": 1,
"no-var": 2,
"prefer-arrow-callback": 1,
"prefer-const": 2,
"quotes": [1, "single"],
"semi": [1, "never"],
"space-before-function-paren": [1, "never"],
"strict": [2, "global"],
"yoda": 2
}
}
@@ -0,0 +1,3 @@
.DS_Store
node_modules/
docs/
@@ -0,0 +1,80 @@
image: node:latest

stages:
- code-testing
- staging-server
- acceptance-testing

linting:
stage: code-testing
script:
- npm install
- npm run linter

dependency-checks:
stage: code-testing
script:
- npm install
- npm run dependency

code-duplication:
stage: code-testing
script:
- npm install
- npm run duplication

unit-testing:
stage: code-testing
script:
- npm install
- npm test

code-coverage:
stage: code-testing
script:
- npm install
- npm run coverage
- npm run check-coverage

coverage-report:
stage: staging-server
script:
- npm install
- npm run coverage
#- mv ./docs/coverage/ public/
artifacts:
paths:
- docs
expire_in: 30 days
only:
- master

deploy-staging-server:
stage: staging-server
script:
- apt-get update -qy
- apt-get install -y ruby ruby-dev rubygems-integration
- gem install dpl
- dpl --provider=heroku --app=notes-api-test --api-key=95023c27-5a9d-4250-a3fd-d2e19e0dac02
only:
- master

acceptance-tests:
stage: acceptance-testing
script:
- npm install --only=dev
- npm run acceptance
only:
- master

# https://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html

# production:
# type: deploy
# script:
# - apt-get update -qy
# - apt-get install -y ruby-dev
# - gem install dpl
# - dpl --provider=heroku --app=gitlab-ci-python-test-prod --api-key=$HEROKU_PRODUCTION_API_KEY
# only:
# - tags
@@ -0,0 +1,10 @@

instrumentation:
excludes: ['*-spec.js', 'spec/*', 'integration/*']
reporting:
dir: ./docs/coverage/
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
@@ -0,0 +1,11 @@

# Notes

This code is designed to demonstrate the use of Continuous Integration.

## Dependencies
```
npm install
npm install --only=dev
npm install --only=production
```
@@ -0,0 +1,21 @@

'use strict'

const frisby = require('frisby')
const status = require('../status-codes.json')
const url = 'https://notes-api-test.herokuapp.com'
console.log(url)
console.log(status.ok)

it('should be a teapot', done => {
frisby.get('http://httpbin.org/status/200')
.expect('status', status.ok)
.done(done)
});

it ('should return a status of 200', done => {
frisby
.get(`${url}/notes`)
.expect('status', status.ok)
.done(done)
})
@@ -0,0 +1,6 @@

{
"spec_files": [
"acceptance/api-spec.js"
]
}
@@ -0,0 +1,20 @@

'use strict'

const Jasmine = require('jasmine')
const jasmine = new Jasmine()

jasmine.loadConfigFile('acceptance/jasmine.json')

const JasmineConsoleReporter = require('jasmine-console-reporter')
const reporter = new JasmineConsoleReporter({
colors: true,
cleanStack: true,
verbosity: 3,
listStyle: 'indent',
activity: true
})

jasmine.addReporter(reporter)

jasmine.execute()
@@ -0,0 +1,51 @@

'use strict'

// const etag = require('etag')
const restify = require('restify')
const server = restify.createServer()

const restifyBodyParser = require('restify-plugins').bodyParser
server.use(restifyBodyParser())
const restifyQueryParser = require('restify-plugins').queryParser
server.use(restifyQueryParser())
const restifyAuthParser = require('restify-plugins').authorizationParser
server.use(restifyAuthParser())

const notes = require('./notes.js')
const defaultPort = 8080

const status = {
'OK': 200,
'badRequest': 400
}

server.get('/notes', async(req, res) => {
try {
const allNotes = notes.getAllNotes()
res.setHeader('content-type', 'application/json')
res.setHeader('accepts', 'GET')
res.send(status.OK, {notes: allNotes})
} catch(err) {
res.send(status.badRequest, {error: err.message})
}
})

server.post('/notes', async(req, res) => {
try {
//TODO
} catch(err) {
//TODO
}
})

console.log(`NODE_ENV: ${process.env['NODE_ENV']}`)
const port = process.env.PORT || defaultPort

server.listen(port, err => {
if (err) {
console.error(err)
} else {
console.log(`App is ready on port ${port}`)
}
})
@@ -0,0 +1,6 @@

{
"spec_files": [
"integration/notes-spec.js"
]
}
@@ -0,0 +1,18 @@

'use strict'

const notes = require('../notes.js')

describe('integration module', () => {
describe('add notes', () => {
//TODO
})
describe('get all notes', () => {
it('should return list of 2 notes', () => {
//TODO
})
it('should throw an error if no notes', () => {
//TODO
})
})
})
@@ -0,0 +1,20 @@

'use strict'

const Jasmine = require('jasmine')
const jasmine = new Jasmine()

jasmine.loadConfigFile('spec/jasmine.json')

const JasmineConsoleReporter = require('jasmine-console-reporter')
const reporter = new JasmineConsoleReporter({
colors: true,
cleanStack: true,
verbosity: 3,
listStyle: 'indent',
activity: true
})

jasmine.addReporter(reporter)

jasmine.execute()

0 comments on commit 2b2eb4b

Please sign in to comment.