diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..e215ac6 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,10 @@ +kind: pipeline +name: default + +steps: + - name: docker build + image: plugins/docker + settings: + repo: registry:5000/appreports + dockerfile: dockerfile + insecure: true diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..36cc3e5 --- /dev/null +++ b/dockerfile @@ -0,0 +1,12 @@ +FROM node:lts-alpine + +RUN mkdir appreports +COPY ./* /appreports +WORKDIR /appreports + +RUN yarn; \ + yarn compile; + +EXPOSE 3000 + +ENTRYPOINT ["node", "index.js"] diff --git a/index.js b/index.js index 83f4b0c..5e838bc 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ const api = require ('./lib/api'); const http_proxy = require ('express-http-proxy'); const history_fallback = require ('connect-history-api-fallback'); const fs = require ('fs'); +const { argv } = require ('yargs'); const salt = crypto.create_salt (); const hash = crypto.hash_sha512 ('asd', salt); @@ -29,9 +30,12 @@ const user = { password: password_helper.hash (hash) }; +const is_dev = argv.dev; + (async () => { - fs.unlinkSync ('db.sqlite'); - await db.init (true); + if (fs.existsSync ('db.sqlite')) + fs.unlinkSync ('db.sqlite'); + await db.init (is_dev); const app = express (); app.use (cookie_parser ()); @@ -47,7 +51,10 @@ const user = { app.use (api); app.use (history_fallback ()); - app.use (http_proxy ('localhost:8080')); + if (is_dev) + app.use (http_proxy ('localhost:8080')); + else + app.use (express.static ('dist')); app.listen (3000, () => { console.log ('listening on 3000'); diff --git a/lib/api/post-log.js b/lib/api/post-log.js index a84323c..e05d73c 100644 --- a/lib/api/post-log.js +++ b/lib/api/post-log.js @@ -29,7 +29,7 @@ module.exports = async (req, res) => { } const { message, data, timestamp } = log; - await db.log.insert (app_id, message, data, timestamp); + await db.log.insert (app_id, message, JSON.stringify (data), timestamp); res.status (http.status_created) .end (); diff --git a/lib/db/index.js b/lib/db/index.js index 7b037d4..cba75fa 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -23,6 +23,8 @@ async function init (use_fake_seed) { await db.migrate.latest (); if (use_fake_seed) await db.seed.run ({ specific: 'fake.js' }); + else + await db.seed.run ({ specific: 'prod.js' }); } function get_db () { diff --git a/package.json b/package.json index 4bde7b5..4e44262 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs", "test": "echo \"no test\"", - "compile": "tsc --allowJs --declaration --emitDeclarationOnly index.js", + "compile": "vue-cli-service build", "serve": "vue-cli-service serve" }, "dependencies": { @@ -31,7 +31,8 @@ "vue": "^2.6.11", "vue-chartjs": "^3.5.0", "vue-router": "^3.2.0", - "vuex": "^3.4.0" + "vuex": "^3.4.0", + "yargs": "^15.4.1" }, "devDependencies": { "@sapphirecode/eslint-config": "^2.1.16", @@ -48,5 +49,8 @@ }, "license": "GPL-3.0-or-later", "main": "index.js", - "author": "Timo Hocker " + "author": { + "name": "Timo Hocker", + "email": "timo@scode.ovh" + } } \ No newline at end of file diff --git a/seeds/fake.js b/seeds/fake.js index fb53073..d313c1a 100644 --- a/seeds/fake.js +++ b/seeds/fake.js @@ -35,11 +35,6 @@ function create_log (index, simplex) { } async function seed (knex) { - await knex ('log') - .del (); - await knex ('app') - .del (); - // eslint-disable-next-line no-console console.log ('creating seeds'); for (let i = 0; i < 5; i++) diff --git a/seeds/prod.js b/seeds/prod.js new file mode 100644 index 0000000..c25661f --- /dev/null +++ b/seeds/prod.js @@ -0,0 +1,19 @@ +/* + * Copyright (C) Sapphirecode - All Rights Reserved + * This file is part of appreports which is released under GPL-3.0-or-later. + * See file 'LICENSE' for full license details. + * Created by Timo Hocker , August 2020 + */ + +'use strict'; + +async function seed (knex) { + // eslint-disable-next-line no-console + console.log ('creating prod seeds'); + await knex ('app') + .insert ( + { name: 'test app' } + ); +} + +module.exports = { seed }; diff --git a/yarn.lock b/yarn.lock index ef64dfa..9a6d29d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9427,7 +9427,7 @@ yargs@^13.3.2: y18n "^4.0.0" yargs-parser "^13.1.2" -yargs@^15.0.0: +yargs@^15.0.0, yargs@^15.4.1: version "15.4.1" resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==