Fix logging, fix a few bugs, add docker file, move files a bit and add auto build and publish to docker

This commit is contained in:
Jonatan Nilsson 2021-10-11 03:39:01 +00:00
parent 799c4419dc
commit d2e263afbe
11 changed files with 30 additions and 29 deletions

View file

@ -18,11 +18,16 @@ jobs:
name: Run tests
command: |
npm run test:linux
# - deploy:
# name: Push to docker
# command: |
# docker login -u $DOCKER_USER -p $DOCKER_PASS
# docker push ${di}
- setup_remote_docker
- run:
name: Build docker image
command: |
docker build -t ${di}:build_${CIRCLE_BUILD_NUM} -t ${di}:${CIRCLE_SHA1} -t ${di}:${dtag} .
- deploy:
name: Push to docker
command: |
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push ${di}
workflows:
version: 2

2
.gitignore vendored
View file

@ -58,7 +58,7 @@ typings/
.env
# Local development config file
config/config.json
config/*.json
# Public folder should be ignored
public/*

View file

@ -1,18 +1,14 @@
FROM node:alpine
ARG NODE=development
FROM alpine
ENV HOME=/app \
NODE_ENV=${NODE}
COPY package.json $HOME/
NODE_ENV=production
WORKDIR $HOME
RUN npm install
COPY package.json $HOME/
COPY . $HOME/
RUN apk update && apk upgrade && apk add nodejs npm && npm install --production
EXPOSE 4020
COPY api $HOME/api
CMD ["npm", "start"]

View file

@ -52,7 +52,7 @@ if (nconf.get('NODE_ENV') === 'production') {
nconf.file('main', path.resolve(path.join(__dirname, configFile)))
// Load defaults
nconf.file('default', path.resolve(path.join(__dirname, '../config/config.default.json')))
nconf.file('default', path.resolve(path.join(__dirname, '../api/config.default.json')))
// Final sanity checks

View file

@ -20,10 +20,3 @@ for (let i = 0; i < settings.streams.length; i++) {
const log = bunyan.createLogger(settings)
export default log
log.logMiddleware = () =>
(ctx, next) => {
ctx.log = log
return next()
}

View file

@ -14,6 +14,8 @@ export default class MediaRoutes {
let result = await this.formidable.uploadFile(ctx, site)
ctx.log.info(`Uploaded ${result.filename}`)
ctx.body = {
filename: result.filename,
path: `/${site}/${result.filename}`

View file

@ -13,6 +13,9 @@ const app = new Flaska({
app.before(function(ctx) {
ctx.__started = performance.now()
ctx.log = ctx.log.child({
ip: ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress,
})
})
app.after(function(ctx) {
@ -21,11 +24,11 @@ app.after(function(ctx) {
if (ctx.status >= 400) {
logger = ctx.log.warn
}
logger({
logger.apply(ctx.log, [{
path: ctx.url,
status: ctx.status,
ms: Math.round(ended),
}, 'Request finished')
}, 'Request finished'])
})
app.onerror(function(err, ctx) {

View file

@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"start": "node --experimental-modules api/server.mjs",
"start": "node api/server.mjs",
"start:bunyan": "node api/server.mjs | bunyan",
"test": "set NODE_ENV=test&& eltro test/**/*.test.mjs -r dot",
"test:linux": "NODE_ENV=test eltro 'test/**/*.test.mjs' -r dot"
},
@ -21,7 +21,7 @@
"homepage": "https://github.com/nfp-projects/storage-upload#readme",
"dependencies": {
"bunyan-lite": "^1.1.1",
"flaska": "^0.9.6",
"flaska": "^0.9.7",
"formidable": "^1.2.2",
"nconf-lite": "^2.0.0"
},

View file

@ -8,8 +8,11 @@ serv.log = {
warn: stub(),
info: stub(),
error: stub(),
child: stub(),
}
serv.log.child.returns(serv.log)
export const server = serv
export function createClient() {

View file

@ -5,7 +5,6 @@ import path from 'path'
import { server, resetLog } from '../helper.server.mjs'
import Client from '../helper.client.mjs'
import config from '../../api/config.mjs'
import encode from '../../api/jwt/encode.mjs'
let __dirname = path.dirname(fileURLToPath(import.meta.url))