Skip to content

Commit bd54804

Browse files
moving around stuff, huge README update
1 parent 500a70a commit bd54804

File tree

114 files changed

+4971
-1986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+4971
-1986
lines changed

.scripts/npm_start.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
require('@sensebox/opensensemap-api');

.scripts/npm_tag-container.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
currentBranch=$(git branch | grep -e "^*" | cut -d' ' -f 2)
7+
8+
if [ "$currentBranch" != "master" ]; then
9+
echo "Tags for containers can only be made from 'master' branch"
10+
exit 1
11+
fi
12+
13+
# Extract latest git tag
14+
currentVersion=$(git tag -l --sort=-v:refname | grep dockerhub-v | head -n 1 | tr -d 'dockerhub\-v')
15+
16+
# Increment
17+
newVersion=$(($currentVersion+1))
18+
19+
# tag new version
20+
git tag "dockerhub-v$newVersion"
21+
22+
echo "Creation of new tag for docker hub was successful. New tag is 'dockerhub-v$newVersion'."
23+
echo "Please run 'git push origin master' to trigger the build on docker hub."
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/*
4+
NPM package.json version script. Do not run manually!
5+
6+
Only tested on Linux. Node v6.
7+
8+
This script overwrites the first Markdown headline "## Unreleased" with the
9+
version in the package.json and prepends a new "## Unreleased" headline.
10+
11+
*/
12+
13+
const { version } = require('../package.json'),
14+
fs = require('fs');
15+
16+
const filename = 'CHANGELOG.md';
17+
18+
fs.readFile(filename, 'utf-8', function(err, data) {
19+
if (err) return console.log(err);
20+
const result = data.replace(
21+
/## Unreleased/i,
22+
`## Unreleased\n\n## v${version}`
23+
);
24+
25+
fs.writeFile(filename, result, 'utf8', function(err) {
26+
if (err) return console.log(err);
27+
});
28+
});

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js:
55
- "6"
66

77
install: true
8-
script: ./utils/deploy-docs.sh
8+
script: ./api/.scripts/deploy-docs.sh
99

1010
env:
1111
global:

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM node:6-alpine
22

3+
ENV NODE_ENV=production
4+
35
RUN apk --no-cache --virtual .build add python make g++ git
46

57
# taken from node:6-onbuild
@@ -8,15 +10,16 @@ WORKDIR /usr/src/app
810

911
COPY package.json /usr/src/app/
1012
COPY yarn.lock /usr/src/app/
11-
RUN yarn install --pure-lockfile
13+
RUN yarn install --pure-lockfile --production
1214
# required because the prebuilt binaries are not compatible with musl
1315
# remove when https://github.com/kelektiv/node.bcrypt.js/issues/528 is resolved
1416
RUN npm rebuild bcrypt --build-from-source
15-
COPY . /usr/src/app
17+
COPY .scripts /usr/src/app/
1618

19+
COPY .git /usr/src/app/
1720
# for git 2.1.4
1821
RUN echo -n $(git rev-parse --abbrev-ref HEAD) $(TZ=UTC git log --date=local --pretty=format:"%ct %h" -n 1) > revision; rm -rf .git
1922

2023
RUN apk del .build
2124

22-
CMD [ "npm", "start" ]
25+
CMD [ "yarn", "start" ]

README.md

Lines changed: 88 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,96 @@
1-
openSenseMap-API
2-
================
3-
4-
[![Join the chat at https://gitter.im/sensebox/openSenseMap-API](https://badges.gitter.im/sensebox/openSenseMap-API.svg)](https://gitter.im/sensebox/openSenseMap-API?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5-
This is the back-end for [openSenseMap](https://opensensemap.org).
6-
7-
openSenseMap is part of the [senseBox](https://sensebox.de) project.
8-
To get more information about openSenseMap and senseBox visit the before mentioned links or have a look at this [video](https://www.youtube.com/watch?v=uTOWYa42_rI).
9-
10-
Originally, this API has been built as part the bachelor thesis of @mpfeil at the ifgi (Institute for Geoinformatics, WWU Münster).
11-
12-
### Technologies
13-
14-
* [node.js]
15-
* [MongoDB]
16-
17-
### Development
18-
19-
#### Node.js
20-
It is assumed that you have installed node.js Version 6 LTS. Install dependencies with [yarn](https://yarnpkg.com/)
21-
```
22-
yarn install
23-
```
24-
25-
There are several config keys in `config/index.js`. These can also be configured through environment keys. Just prefix your environment keys with `OSEM_` to be read by the api.
26-
27-
#### Database
28-
The API needs a running MongoDB instance with a `OSeM-api` database and credentials.
29-
30-
The best way to run the database for development is to use the supplied `docker-compose.yml` and run
31-
```
32-
docker-compose up -d db
33-
```
34-
35-
### `require()` openSenseMap-API for other projects
36-
37-
You can require several parts of the API in other projects.
38-
39-
Install it as dependency
40-
```
41-
# for specific branch/commit/tag append #<branch/commit/tag>
42-
yarn add git://github.com/sensebox/openSenseMap-API.git
43-
```
44-
45-
This allows you to use parts like models and decoding in your own project. See `index.js`.
46-
47-
### Create the JSDoc pages
48-
49-
To create the documentation you need [apidocjs](http://apidocjs.com/) and run:
50-
```
51-
apidoc -e node_modules/
52-
```
53-
54-
### Running Tests
55-
You can run the tests in containers using docker and docker-compose.
1+
# openSenseMap API
2+
3+
[openSenseMap] is part of the [senseBox] project. To get more information about openSenseMap and senseBox visit the before mentioned links or have a look at this [video](https://www.youtube.com/watch?v=uTOWYa42_rI), read the [API docs](https://docs.opensensemap.org) or the [openSenseMap](https://osem.books.sensebox.de/) chapter in our [books](https://books.sensebox.de/).
4+
5+
## Organization
6+
7+
This repository is a monorepo for the packages
8+
9+
- [![@sensebox/opensensemap-api-models NPM Version](https://img.shields.io/npm/v/@sensebox/opensensemap-api-models.svg)](https://www.npmjs.com/package/@sensebox/opensensemap-api-models) [@sensebox/opensensemap-api-models](models) The data models and database connection of openSenseMap.
10+
- [![@sensebox/opensensemap-api NPM Version](https://img.shields.io/npm/v/@sensebox/opensensemap-api.svg)](https://www.npmjs.com/package/@sensebox/opensensemap-api) [@sensebox/opensensemap-api](api) The REST API used by [https://opensensemap.org](https://opensensemap.org) running at [https://api.opensensemap.org](https://api.opensensemap.org).
11+
12+
### Directories
13+
- root directory
14+
- not published on NPM
15+
- is used to build a Docker container image
16+
- contains tests (run with `./run-tests`)
17+
- [api](api) directory
18+
- NPM [@sensebox/opensensemap-api](https://www.npmjs.com/package/@sensebox/opensensemap-api)
19+
- [Changelog](api/CHANGELOG.md)
20+
- should not appear as dependency of other packages
21+
- [models](models) directory
22+
- NPM [@sensebox/opensensemap-api-models](https://www.npmjs.com/package/@sensebox/opensensemap-api-models)
23+
- [Changelog](models/CHANGELOG.md)
24+
- `require('@sensebox/opensensemap-api-models')` for access to data models
25+
26+
### Branches
27+
- master (runs in production)
28+
- Is never used to publish versions of subpackages
29+
- [package.json](package.json) contains specific versions from NPM
30+
- Is used for container build tags
31+
- development (runs on testing server)
32+
- Releases for subpackages are done from here
33+
- [package.json](package.json) contains `file:./api` and `file:./models` as versions
34+
- gh-pages
35+
- Hosts API docs for [https://docs.opensensemap.org/](https://docs.opensensemap.org/)
36+
- Is generated and pushed to github by Travis CI [![sensebox/openSenseMap-API Build Status](https://travis-ci.org/sensebox/openSenseMap-API.svg?branch=master)](https://travis-ci.org/sensebox/openSenseMap-API)
37+
38+
### Tags and Versions
39+
Git Tags are used for:
40+
- Docker hub builds `dockerhub-v1`. Version number is increased by one for each new version.
41+
- NPM tags for subpackages. [Uses Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html)
42+
- `@sensebox/opensensemap-api-v1.0.0`
43+
- `@sensebox/opensensemap-api-models-v1.0.0`
44+
45+
### Release new NPM versions
46+
Make sure you've documented your changes in the `CHANGELOG.md` file of the respective package and have comitted everything to the development branch.
47+
48+
To create a new NPM version, use `npm version`.
49+
1. Have everything commited for the release
50+
1. Document your changes in `CHANGELOG.md` under `## Unreleased`. Do not `git add` the file
51+
1. Run `npm version [ major | minor | patch ] -m "[<PACKAGENAME>-v%s] <Your commit message>"`
52+
1. `git push origin development`
53+
1. `npm publish`
54+
55+
### Docker container images
56+
#### Development images
57+
Every commit on branch `development` will be built with the tag `development`. Versions of `@sensebox/opensensemap-api` and `@sensebox/opensensemap-api-models` will be the current development snapshot.
58+
59+
#### Versioned container images
60+
- Check out `master` branch
61+
- Go to root directory
62+
- Modify version of `@sensebox/opensensemap-api` and `@sensebox/opensensemap-api-models` to desired versions
63+
- Make sure versions of `@sensebox/opensensemap-api` and `@sensebox/opensensemap-api-models` are published on NPM
64+
- Optional
65+
- Run tests
66+
- Build docker image locally
67+
- Run `yarn` to update `yarn.lock`
68+
- Commit `package.json` and `yarn.lock`
69+
- Run `npm run tag-container`
70+
- Run `git push origin master`
71+
- Docker images are built automatically by the Docker hub for all tags starting with `dockerhub-v`
72+
73+
## Development
74+
- Have [Node.js] v6, [yarn](https://yarnpkg.com/), [Docker](https://docs.docker.com/engine/installation/) and [docker-compose](https://docs.docker.com/compose/install/) installed
75+
- Go to the subdirectory in which you want to develop
76+
- Only for [api](api): Run `yarn install`
77+
- Start your development database (`docker-compose up -d db`)
78+
79+
## Running Tests
80+
You can run the tests in containers using Docker and docker-compose.
5681
```
5782
# Only run this once or every time you change dependencies in package.json
58-
docker-compose -p osemapitest -f tests-docker-compose.yml build osem-api
83+
./run-tests.sh build
5984
6085
./run-tests.sh
6186
```
6287

63-
### Running in Production
64-
65-
Look at the [OSeM-compose](https://github.com/sensebox/osem-compose) repository. It contains a deployment with docker compose.
66-
67-
### License
88+
## Running the API
89+
### Configuration
90+
These packages read their configuration either from their respective `src/config.js` file or environment variables starting with `OSEM_`. Environment variables override values in `src/config.js`.
6891

69-
[MIT](license.md) - Matthias Pfeil 2015 - 2017
92+
### Container based
93+
The repository [OSeM-compose](https://github.com/sensebox/osem-compose) contains a deployment of all services with docker compose. The image built from this repository is called [`sensebox/opensensemap-api`](https://hub.docker.com/r/sensebox/opensensemap-api/).
7094

71-
[node.js]:http://nodejs.org/
72-
[MongoDB]:http://www.mongodb.com/
95+
[openSenseMap]:https://opensensemap.org/
96+
[senseBox]:https://sensebox.de/

.eslintrc.js renamed to api/.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ module.exports = {
156156
'error',
157157
'never'
158158
],
159-
'no-warning-comments': 'error'
159+
'no-warning-comments': 'error',
160+
'prefer-promise-reject-errors': 'error'
160161
}
161162
};

utils/deploy-docs.sh renamed to api/.scripts/deploy-docs.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
set -euo pipefail
44
IFS=$'\n\t'
55

6-
76
# move to the build dir..
8-
cd $TRAVIS_BUILD_DIR
7+
cd "$TRAVIS_BUILD_DIR"
98

109
# install apidocs
11-
npm install -g [email protected]
12-
13-
# deploy!
10+
npm install -g [email protected]
1411

1512
# run apidoc
1613
apidoc -i . -f js -e node_modules
@@ -42,6 +39,5 @@ git config user.email "[email protected]"
4239
# commit
4340
git commit -m "apidoc build from ${TRAVIS_COMMIT} by Travis"
4441

45-
# push to github!
42+
# push to github
4643
git push "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" gh-pages
47-

api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# @sensebox/opensensemap-api Changelog
2+
3+
## Unreleased
4+
- Initial Release after splitting api and models

api/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# @sensebox/opensensemap-api
2+
3+
This package contains the HTTP REST API for the openSenseMap. Originally, this API has been built as part the bachelor thesis of [@mpfeil](https://github.com/mpfeil) at the ifgi (Institute for Geoinformatics, WWU Münster).
4+
5+
The package should never be required by any other package. If you want to use the openSenseMap models, look at [@sensebox/opensensemap-api-models](../models).
6+
7+
## Development
8+
9+
- Install Docker, Node.js v6, yarn
10+
- Run `yarn` in this directory
11+
- Run development database `docker-compose up -d db`
12+
13+
Also see [README](../README.md)
14+
15+
16+
## Create the API documentation pages
17+
18+
To create the documentation you need [apidocjs](http://apidocjs.com/) and run:
19+
```
20+
apidoc -e node_modules/
21+
```
22+
23+
## Technologies
24+
25+
* [Node.js]
26+
* [MongoDB]
27+
28+
## License
29+
30+
[MIT](license.md) - Matthias Pfeil 2015 - 2017
31+
32+
[Node.js]:http://nodejs.org/
33+
[MongoDB]:http://www.mongodb.com/

0 commit comments

Comments
 (0)