Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
🔀 Add continuous integration pipeline
Browse files Browse the repository at this point in the history
- The continuous deployment setup is against with oursky/puttimages-web to
https://puttyimages.pandawork.com
- It comes with example unit and integration test
- Test are run at Travis-CI
- It includes seeding data for kick start dev and test

refs #5
  • Loading branch information
rickmak committed Jun 8, 2018
2 parents 94e68c6 + 966eb07 commit 64791b0
Show file tree
Hide file tree
Showing 24 changed files with 2,480 additions and 215 deletions.
12 changes: 12 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
"babel-preset-backpack"
],
"env": {
"test": {
"presets": [
["env"]
]
}
}
}
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ module.exports = {
root: true,
parser: 'babel-eslint',
env: {
'jest/globals': true,
browser: true,
node: true,
},
extends: 'airbnb-base',
extends: [
'airbnb-base',
'plugin:jest/recommended',
'prettier',
],
// required to lint *.vue files
plugins: [
'jest',
'html',
],
// add your custom rules here
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ dist

# Backpack build
build

# tests
coverage
176 changes: 176 additions & 0 deletions .k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ipfs-pv-claim
namespace: likecoin
labels:
app: puttyimages
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pgsql-pv-claim
namespace: likecoin
labels:
app: puttyimages
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: puttyimages-ipfs
namespace: likecoin
spec:
selector:
matchLabels:
app: puttyimages-ipfs
replicas: 1
template:
metadata:
labels:
app: puttyimages-ipfs
spec:
containers:
- name: ipfs
image: ipfs/go-ipfs:v0.4.15
ports:
- containerPort: 8080
volumeMounts:
- name: ipfs-persistent-storage
mountPath: /data/ipfs
volumes:
- name: ipfs-persistent-storage
persistentVolumeClaim:
claimName: ipfs-pv-claim
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: puttyimages-db
namespace: likecoin
spec:
selector:
matchLabels:
app: puttyimages-db
replicas: 1
template:
metadata:
labels:
app: puttyimages-db
spec:
containers:
- name: pgsql
image: postgres:10.4
ports:
- containerPort: 5432
volumeMounts:
- name: pgsql-persistent-storage
mountPath: /data
volumes:
- name: pgsql-persistent-storage
persistentVolumeClaim:
claimName: pgsql-pv-claim
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: puttyimages-web
namespace: likecoin
spec:
selector:
matchLabels:
app: puttyimages-web
replicas: 1
template:
metadata:
labels:
app: puttyimages-web
spec:
containers:
- name: web
image: oursky/puttyimages-web:latest
ports:
- containerPort: 3000
env:
- name: HOST
value: 0.0.0.0
- name: IPFS_HOST
value: ipfs
---
apiVersion: v1
kind: Service
metadata:
labels:
app: web
name: web
namespace: likecoin
spec:
ports:
- port: 80
protocol: TCP
targetPort: 3000
selector:
app: puttyimages-web
sessionAffinity: None
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: ipfs
namespace: likecoin
labels:
app: puttyimages-ipfs
spec:
ports:
- port: 8080
selector:
app: puttyimages-ipfs
clusterIP: None
---
apiVersion: v1
kind: Service
metadata:
name: db
namespace: likecoin
labels:
app: puttyimages-db
spec:
ports:
- port: 5432
selector:
app: puttyimages-db
clusterIP: None
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
labels:
app: puttyimages
name: puttyimages
namespace: likecoin
annotations:
ingress.kubernetes.io/proxy-body-size: 10m
spec:
rules:
- host: puttyimages.pandawork.com
http:
paths:
- path: /
backend:
serviceName: web
servicePort: 80
tls:
- hosts:
- puttyimages.pandawork.com
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: generic
services:
- docker
sudo: required
install:
- docker-compose build
script:
- docker-compose up -d
- docker-compose exec nuxt npm run lint
- docker-compose exec nuxt npm run sequelize db:migrate
- docker-compose exec nuxt npm run sequelize db:seed:all
- docker-compose exec nuxt npm test
- docker-compose down
deploy:
- provider: script
script: ./scripts/deploy-docker-hub.sh
skip_cleanup: true
on:
repo: oursky/puttyimages-web
branch: master
after_deploy:
- ./scripts/trigger-github-deploy.sh
env:
global:
# DOCKER_USERNAME
- secure: PC9cYzOPyVQAfx+kFoHC5gGvnvcgQiOPQeNZv/to+S+Sh9g7NE+ATrLZLDJDQlCePhOSB+2HA1n/cmMXhyT4D3eiYXSlCbkme5Zr78Ss+FkSVPxNdp4O6FxC4qiACeCpNQ4090HI+SfJOcZdF6DAMR0Sgff4qKd0w03bsRTdkKtfPnUkhB3/R86rzXkNFGSSHcp802yVdNIDoyY5P/5zasKCN/oslw1WhhmwMC8Mh63rNSnTAFru1101wbUMGUr1wMluoygsYDW6A5/kzgNBQyJVV4eH7CSD29COSLyjGUyf+iGYBMSWfJ4bCOjKkvv6lgSiah8Bf65W26PGZ/zzSwF/3h+X+Pprlp1Aj16SIzGB+pRg4zvPMGKs1NmEANrpkBPGBLnaPlfXocTI5WImX4ykFz9qCZtjQl7U7U67sSshevyebmvVrfD2i+65iRHecnEMjTf9doHtYg0V1Rr82q8Am4vW/U5vTq3kIx2xBsgsPed0bYaoUv9EEiJIS9NSWx6caNCC+A4b0t4rHAapspwAJBbotuhZKDMSfsNygfdyhff6bbXALsHtrwb0ocpxPkH8igbp/phzdiUmzW34TiXJZKES5o10wUhbDgPJDETWAsgsC1+svd2tczEvaXy8Sk2n4X+TilrLPVt57ugPDZee5MSDAm8wq4NjBj7r46s=
# DOCKER_PASSWORD
- secure: d8zIElU2Hx15AVsWE/8rN6gyaHPMwGNZrLp3DRtTj36X1vDbGlLkR9KsR09lgAUSkK94xHVP0GxbKtUOrk/ZYg2ZGAvEYLr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RqNPueeCwx2Aib7z9I6UeayC1a/2xPVrA7MITYybCs0SdW412IzzJkokZBphEBIgZDoBuvHjE67vPPj2OJso+wHUvjSEUgfQYfV6RZB4UPXWPy7bCFENljgN8wwANUxyjfNAmpOe8wOIyOFoNVbZzaUd9bVxbUkFZXt2q3kjoWFN1T5Soea+CpiFrCxmDUFvSzqr8RE=
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: test

docker_compose_test := docker-compose --project-name puttyimages_test

test:
$(docker_compose_test) down -v
$(docker_compose_test) build 1>/dev/null 2>&1
$(docker_compose_test) up -d
$(docker_compose_test) exec nuxt npm run lint
$(docker_compose_test) exec nuxt npm run sequelize db:migrate
$(docker_compose_test) exec nuxt npm run sequelize db:seed:all
$(docker_compose_test) exec nuxt npm run test
$(docker_compose_test) stop
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Puttyimegs is an open stock image DApp that live within the
## Development Setup

The suggested way of development environment is docker based. This guide will
assume you have Docker Community Edition 18+ installed. Please download at
assume you have Docker Community Edition 18+ installed. Please download at
[https://store.docker.com](https://store.docker.com) and follow the
installation instruction.

Expand All @@ -20,8 +20,8 @@ $ docker-compose build

# Run the DB migration and reseed the DB for the first time run or after you
# pull an update.
$ docker-compose run nuxt npm run sequelize db:migrate
$ docker-compose run nuxt npm run sequelize db:seed:all
$ docker-compose run --rm nuxt npm run sequelize db:migrate
$ docker-compose run --rm nuxt npm run sequelize db:seed:all

# Kick of the development setup
$ docker-compose up
Expand All @@ -30,6 +30,25 @@ $ docker-compose up
Local files are mount into docker you can modify file in your fs and will
hot reload.

## Test

``` bash
make test
```

## Continuous Integration

Oursky hosts a staging continuous integration pipeline for fast review. The
deployed endpoint is
[https://puttyimages.pandawork.com](https://puttyimages.pandawork.com). The
endpoint is in sync with the `master` branch of [Oursky
fork](https://github.com/oursky/puttyimages-web) via Travis-CI. You can send PR to the
branch if you want your changes reflect on the review endpoint.

The continuous integration setup is assuming an
[kubernetes](https://kubernetes.io) environment. If you want to deploy your
own instances, you can checkout the `./k8s` folder for details.

## Production

``` bash
Expand Down
12 changes: 12 additions & 0 deletions __mocks__/ipfs-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let mockFiles = {};

const IPFSApi = {
setMockFiles(files) {
mockFiles = files;
},
files: {
cat: jest.fn().mockImplementation((path) => Promise.resolve(mockFiles[path])),
},
};

module.exports = IPFSApi;
25 changes: 25 additions & 0 deletions __tests__/integration/api/__snapshots__/users.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`get user info by id 1`] = `
Object {
"id": 1,
"name": "Alexandre",
}
`;

exports[`get users list 1`] = `
Array [
Object {
"id": 1,
"name": "Alexandre",
},
Object {
"id": 2,
"name": "Pooya",
},
Object {
"id": 3,
"name": "Sébastien",
},
]
`;
9 changes: 9 additions & 0 deletions __tests__/integration/api/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const axios = require('axios');

const host = process.env.HOST || '127.0.0.1';
const port = process.env.PORT || 3000;

module.exports = {
get: (url) => axios.get(`http://${host}:${port}/api/${url}`),
post: (url, data) => axios.post(`http://${host}:${port}/api/${url}`, data),
};
11 changes: 11 additions & 0 deletions __tests__/integration/api/users.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const api = require('./api');

test('get users list', async () => {
const response = await api.get('users');
expect(response.data).toMatchSnapshot();
});

test('get user info by id', async () => {
const response = await api.get('users/1');
expect(response.data).toMatchSnapshot();
});
15 changes: 15 additions & 0 deletions __tests__/unit/ipfs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const ipfs = require('ipfs-api');

const MOCK_FILE_INFO = {
'/file': 'file content',
};

test('should cat file', () => {
ipfs.setMockFiles(MOCK_FILE_INFO);
expect(ipfs.files.cat).not.toHaveBeenCalled();

return ipfs.files.cat('/file').then((file) => {
expect(file).toEqual('file content');
expect(ipfs.files.cat).toHaveBeenCalledTimes(1);
});
});
13 changes: 13 additions & 0 deletions __tests__/unit/models.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const sequelize = require('sequelize');

const models = require('../../server/models');

test('get sequelize instance', async () => {
expect(models.sequelize).toBeInstanceOf(sequelize);
expect(models.Sequelize).toBeInstanceOf(Function);
const User = models.user;
expect(new User()).toBeInstanceOf(sequelize.Model);
if (User.associate) {
expect(User.associate).toBeInstanceOf(Function);
}
});
Loading

0 comments on commit 64791b0

Please sign in to comment.