-
Notifications
You must be signed in to change notification settings - Fork 17
Carbone 2.0 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Carbone 2.0 #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,4 +60,6 @@ typings/ | |
| # next.js build output | ||
| .next | ||
|
|
||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| .idea | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| FROM node:8 | ||
| FROM node:12 | ||
|
|
||
| WORKDIR /tmp | ||
| RUN wget http://downloadarchive.documentfoundation.org/libreoffice/old/6.3.3.1/deb/x86_64/LibreOffice_6.3.3.1_Linux_x86-64_deb.tar.gz -O libo.tar.gz | ||
| RUN wget http://downloadarchive.documentfoundation.org/libreoffice/old/6.4.5.2/deb/x86_64/LibreOffice_6.4.5.2_Linux_x86-64_deb.tar.gz -O libo.tar.gz | ||
| RUN apt update \ | ||
| && apt install -y libxinerama1 libfontconfig1 libdbus-glib-1-2 libcairo2 libcups2 libglu1-mesa libsm6 unzip \ | ||
| && tar -zxvf libo.tar.gz | ||
| WORKDIR LibreOffice_6.3.3.1_Linux_x86-64_deb/DEBS | ||
| WORKDIR LibreOffice_6.4.5.2_Linux_x86-64_deb/DEBS | ||
| RUN dpkg -i *.deb | ||
|
|
||
| RUN mkdir /tmp-reports | ||
| COPY . /carbone-api | ||
| WORKDIR /carbone-api | ||
| RUN yarn | ||
| RUN yarn install --production | ||
fleebzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CMD node index | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| const path = require(`path`); | ||
| const fs = require(`fs-extra`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can replace fs extra and remove extra dependency in flavor of: const fs = require(`fs`).promises; |
||
| const _ = require(`lodash`); | ||
| const util = require(`util`); | ||
| const carbone = require(`carbone`); | ||
| const telejson = require(`telejson`); | ||
|
|
@@ -15,38 +14,43 @@ app.use(bodyParser.urlencoded({ extended: true })); | |
|
|
||
| const render = util.promisify(carbone.render); | ||
|
|
||
| // Flagging default formatters to remove custom ones later | ||
| _.forEach(carbone.formatters, formatter => formatter.$isDefault = true); | ||
| const defaultFormatters = {...carbone.formatters}; | ||
|
|
||
| app.get('/', (req, res) => { | ||
| res.sendFile(path.resolve(`./test.html`)); | ||
| }); | ||
|
|
||
| app.post('/render', upload.single(`template`), async (req, res) => { | ||
| const template = req.file; | ||
| if(!template) { | ||
| return res.status(400).send(`Template file required`); | ||
| } | ||
|
|
||
| const originalNameWOExt = template.originalname.split(`.`).slice(0, -1).join(`.`); | ||
| const originalFormat = template.originalname.split(`.`).reverse()[0]; | ||
| let data = req.body.data; | ||
| let options = {}; | ||
| let formatters = {}; | ||
| try { | ||
| options = JSON.parse(req.body.options); | ||
| } catch (e) {} | ||
| } catch (e) { | ||
| return res.status(400).send(`Can't parse options JSON: ${e}`); | ||
| } | ||
| options.convertTo = options.convertTo || originalFormat; | ||
| options.outputName = options.outputName || `${originalNameWOExt}.${options.convertTo}`; | ||
| if (typeof data !== `object` || data === null) { | ||
| try { | ||
| data = JSON.parse(req.body.data); | ||
| } catch (e) { | ||
| data = {}; | ||
| return res.status(400).send(`Can't parse data JSON: ${e}`); | ||
| } | ||
| } | ||
| try { | ||
| formatters = telejson.parse(req.body.formatters); | ||
| } catch (e) {} | ||
|
|
||
| // Removing previous custom formatters before adding new ones | ||
| carbone.formatters = _.filter(carbone.formatters, formatter => formatter.$isDefault === true); | ||
| carbone.formatters = {...defaultFormatters}; | ||
|
|
||
| carbone.addFormatters(formatters); | ||
|
|
||
|
|
@@ -56,7 +60,7 @@ app.post('/render', upload.single(`template`), async (req, res) => { | |
| report = await render(template.path, data, options); | ||
| } catch (e) { | ||
| console.log(e); | ||
| return res.status(500).send(`Internal server error`); | ||
| return res.status(500).send(`Internal server error: ${e}`); | ||
| } | ||
|
|
||
| fs.remove(template.path); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to native fs dependency |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| { | ||
| "name": "carbone-docker", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "All what you need to build a standalone carbone.io Docker image", | ||
| "main": "index.js", | ||
| "author": "Florian Bezagu <florian@bezagu.com>", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "body-parser": "^1.18.3", | ||
| "carbone": "^1.2.0", | ||
| "express": "^4.16.4", | ||
| "fs-extra": "^7.0.1", | ||
| "lodash": "^4.17.15", | ||
| "multer": "^1.4.1", | ||
| "telejson": "^3.0.3" | ||
| "body-parser": "^1.19.0", | ||
| "carbone": "^2.0.0", | ||
| "express": "^4.17.1", | ||
| "fs-extra": "^9.0.1", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this package
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ? It's used in
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry didn't see the other comment about the native There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and can be replaced with native build in |
||
| "multer": "^1.4.2", | ||
| "telejson": "^4.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "forever": "^1.0.0" | ||
| "forever": "^3.0.0" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workdirs should not be used like this, I prefer this example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could agree just : what's the point but adding a slow
COPYstep ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.js has to be copied into container right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry misread your proposal. Now I can say I disagree 😛
From dockerfile_best-practices :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :DDD Agree anyway we can use that node:lts and rest 😄
Thank you!