mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-08-22 10:24:19 -05:00
Add Docker config
This commit is contained in:
8
docker-compose.yml
Normal file
8
docker-compose.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
|
||||
app:
|
||||
build: docker/app
|
||||
volumes:
|
||||
- ./:/app
|
||||
13
docker/app/Dockerfile
Normal file
13
docker/app/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM ubuntu:16.04
|
||||
|
||||
# NodeJS / Yarn
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y curl \
|
||||
&& curl -sL https://deb.nodesource.com/setup_6.x | bash - \
|
||||
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
|
||||
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y nodejs yarn
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["yarn", "start"]
|
||||
@@ -5,7 +5,8 @@
|
||||
"watch": "npm run dev -- --watch",
|
||||
"build": "webpack -p --env production",
|
||||
"serve": "webpack-dev-server --content-base public/",
|
||||
"splatnet": "node src/splatoon/update.js"
|
||||
"splatnet": "node src/splatoon/update.js",
|
||||
"start": "node src/splatoon/run.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.16.2",
|
||||
@@ -16,6 +17,7 @@
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"bulma": "^0.5.0",
|
||||
"clean-webpack-plugin": "^0.1.16",
|
||||
"cron": "^1.2.1",
|
||||
"css-loader": "^0.28.4",
|
||||
"dotenv": "^4.0.0",
|
||||
"extract-text-webpack-plugin": "^3.0.0",
|
||||
|
||||
12
readme.md
12
readme.md
@@ -12,8 +12,20 @@ yarn serve
|
||||
yarn build
|
||||
```
|
||||
|
||||
Or via Docker:
|
||||
|
||||
```shell
|
||||
docker-compose run --rm app yarn build
|
||||
```
|
||||
|
||||
## Update SplatNet Data
|
||||
|
||||
```shell
|
||||
yarn splatnet
|
||||
```
|
||||
|
||||
On a schedule via Docker:
|
||||
|
||||
```shell
|
||||
docker-compose up -d app
|
||||
```
|
||||
|
||||
9
src/splatoon/run.js
Normal file
9
src/splatoon/run.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const CronJob = require('cron').CronJob;
|
||||
const splatnet = require('./splatnet');
|
||||
|
||||
console.info('Starting periodic tasks...');
|
||||
|
||||
// Run every day at 2min 30sec after the hour
|
||||
new CronJob('02 24 * * * *', () => {
|
||||
splatnet.update();
|
||||
}, null, true);
|
||||
25
src/splatoon/splatnet.js
Normal file
25
src/splatoon/splatnet.js
Normal file
@@ -0,0 +1,25 @@
|
||||
require('dotenv').config();
|
||||
const axios = require('axios');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const mkdirp = require('mkdirp');
|
||||
|
||||
const dataPath = path.resolve('public/data');
|
||||
|
||||
// SplatNet2 API
|
||||
const api = axios.create({
|
||||
baseURL: 'https://app.splatoon2.nintendo.net/api/',
|
||||
headers: {'Cookie': `iksm_session=${process.env.NINTENDO_SESSION_ID}`},
|
||||
});
|
||||
|
||||
module.exports.update = function() {
|
||||
// Make sure the data path exists
|
||||
mkdirp(dataPath);
|
||||
|
||||
// Update map schedules
|
||||
console.info('Updating map schedules...');
|
||||
api.get('schedules').then(response => {
|
||||
fs.writeFile(`${dataPath}/schedules.json`, JSON.stringify(response.data));
|
||||
console.info('Updated map schedules.');
|
||||
});
|
||||
}
|
||||
@@ -1,22 +1,3 @@
|
||||
require('dotenv').config();
|
||||
const axios = require('axios');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const mkdirp = require('mkdirp');
|
||||
const splatnet = require('./splatnet');
|
||||
|
||||
// Make sure the data path exists
|
||||
const dataPath = path.resolve('public/data');
|
||||
mkdirp(dataPath);
|
||||
|
||||
// SplatNet2 API
|
||||
const api = axios.create({
|
||||
baseURL: 'https://app.splatoon2.nintendo.net/api/',
|
||||
headers: {'Cookie': `iksm_session=${process.env.NINTENDO_SESSION_ID}`},
|
||||
});
|
||||
|
||||
// Update map schedules
|
||||
console.info('Updating map schedules...');
|
||||
api.get('schedules').then(response => {
|
||||
fs.writeFile(`${dataPath}/schedules.json`, JSON.stringify(response.data));
|
||||
console.info('Updated map schedules.');
|
||||
});
|
||||
splatnet.update();
|
||||
|
||||
14
yarn.lock
14
yarn.lock
@@ -1384,6 +1384,12 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
|
||||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
cron@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/cron/-/cron-1.2.1.tgz#3a86c09b41b8f261ac863a7cc85ea4735857eab2"
|
||||
dependencies:
|
||||
moment-timezone "^0.5.x"
|
||||
|
||||
cross-spawn@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982"
|
||||
@@ -3357,7 +3363,13 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdi
|
||||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
moment@^2.18.1:
|
||||
moment-timezone@^0.5.x:
|
||||
version "0.5.13"
|
||||
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.13.tgz#99ce5c7d827262eb0f1f702044177f60745d7b90"
|
||||
dependencies:
|
||||
moment ">= 2.9.0"
|
||||
|
||||
"moment@>= 2.9.0", moment@^2.18.1:
|
||||
version "2.18.1"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user