Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from derogab/dev
Browse files Browse the repository at this point in the history
Add docker support
  • Loading branch information
derogab authored Feb 29, 2020
2 parents a124f40 + 9fd79da commit 74fe1cd
Show file tree
Hide file tree
Showing 18 changed files with 1,494 additions and 1,634 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
yarn.lock
daemon
assets
Dockerfile
docker-compose.yml
.travis.yml
.git
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_DAEMON_SOCKET_PORT=8081
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN yarn

# Copy app
COPY . .

# Expose ports
EXPOSE 3000

# Run command
CMD [ "yarn", "start" ]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ yarn run all
```
The previous command starts both the [daemon](./daemon) and the web interface.

## Docker
#### Manual
1. [Start the `coingraph-daemon`](./daemon/README.md#start-container) and then
2.
```shell
docker run -d \
-p 3000:3000 \
--link DAEMON_CONTAINER_ID \
derogab/coingraph-client
```

#### Using `docker-compose`
Open `docker-compose.yml` and eventually change environment variables.

And then
```shell
docker-compose up -d --build
```

## License
_Coingraph_ is made with ♥ by [derogab](https://github.com/derogab) and the [amazing dev team](https://github.com/derogab/coingraph/graphs/contributors). It is released under the MIT license.
6 changes: 6 additions & 0 deletions daemon/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
yarn.lock
data
db.json
Dockerfile
docker-compose.yml
5 changes: 5 additions & 0 deletions daemon/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TIMEOUT=180
DATABASE=db.json
IO_PORT=8081
API_PORT=8080
CRYPTOCURRENCIES=bitcoin,ethereum
20 changes: 20 additions & 0 deletions daemon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN yarn

# Copy app
COPY . .

# Expose ports
EXPOSE 8080 8081

# Run command
ENTRYPOINT [ "node", "app.js" ]
CMD []
41 changes: 39 additions & 2 deletions daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,46 @@ yarn
```

## Configuration
Open `config.yml` and eventually change your preferences.
Open `.env` and eventually change default preferences.

## Usage
```shell
yarn start
node app.js
```
Or with custom params
```shell
node app.js \
--db db.json \
--crypto bitcoin,ethereum \
--timeout 180 \
--api-port 8080 \
--io-port 8081
```
Info: custom params overwrite default preferences in `.env`.

## Docker
###### Build image from source
```shell
docker build -t derogab/coingraph-daemon .
```
###### Start container
```shell
docker run -d \
-p 8080:8080 \
-p 8081:8081 \
-v /path/to/host/data:/usr/src/app/data \
derogab/coingraph-daemon
```
Or with custom params
```shell
docker run -d \
-p 8080:8080 \
-p 8081:8081 \
-v /path/to/host/data:/usr/src/app/data \
derogab/coingraph-daemon \
--db db.json \
--crypto bitcoin,ethereum \
--timeout 180 \
--api-port 8080 \
--io-port 8081
```
30 changes: 22 additions & 8 deletions daemon/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@
* A daemon for coingraph
*
*/
const fs = require('fs');
const YAML = require('yaml');
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const io = require('socket.io')()
const express = require('express')

/**
* Environment variables
*
*/
require('dotenv').config();

/**
* Args
*
*/
var argv = require('minimist')(process.argv.slice(2));

/**
* Init
*
*/
const file = fs.readFileSync('./config.yml', 'utf8');
const config = YAML.parse(file);
*/
const config = {
url: 'https://api.coinmarketcap.com/v1/ticker/',
timeout: argv.timeout || process.env.TIMEOUT || 180,
db: argv.db || process.env.DATABASE || 'db.json',
cryptocurrencies: (argv.crypto || process.env.CRYPTOCURRENCIES).split(',')
}

const adapter = new FileSync(config.db.file || 'db.json');
const adapter = new FileSync('data/' + config.db);
const db = low(adapter);
db.defaults({ status: {}, cryptocurrencies: [] }).write();

const io_port = 8081
const io_port = argv['io-port'] || process.env.IO_PORT || 8081
io.listen(io_port)
console.log('IO listening on port ', io_port)

const app = express()
const api_port = config.api.port || 8080
const api_port = argv['api-port'] || process.env.API_PORT || 8080
app.listen(api_port)
console.log('API listening on port ', api_port)

Expand Down
10 changes: 0 additions & 10 deletions daemon/config.yml

This file was deleted.

Empty file added daemon/data/.gitkeep
Empty file.
5 changes: 3 additions & 2 deletions daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"main": "app.js",
"dependencies": {
"axios": "^0.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"fs": "^0.0.1-security",
"http": "^0.0.0",
"lowdb": "^1.0.0",
"socket.io": "^2.3.0",
"yaml": "^1.7.2"
"minimist": "^1.2.0",
"socket.io": "^2.3.0"
},
"scripts": {
"start": "node app.js"
Expand Down
4 changes: 2 additions & 2 deletions daemon/routes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(db, io, app, config) {
*
*/
function realtime(crypto) {
axios.get(config.resource.url + crypto, {
axios.get(config.url + crypto, {
params: {

}
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports = function(db, io, app, config) {
// always executed
setTimeout(function(){
realtime(crypto);
}, config.resource.timeout * 1000 || 60000);
}, config.timeout * 1000 || 60000);
});
}

Expand Down
Loading

0 comments on commit 74fe1cd

Please sign in to comment.