Skip to content

Commit

Permalink
Nextcloud migration:: add security tips + reduce size (#307)
Browse files Browse the repository at this point in the history
* Add security tips
* Don't rebuild on start
* Build a full bundle with rollup, then minimize image size
  • Loading branch information
guimard authored Jan 5, 2024
1 parent 927d5a6 commit eae8590
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions tdrive/backend/utils/nextcloud-migration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
27 changes: 17 additions & 10 deletions tdrive/backend/utils/nextcloud-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,41 @@
"type": "module",
"scripts": {
"build": "npm run build:clean && npm run build:ts",
"build:ts": "tsc",
"build:ts": "rollup -c",
"build:clean": "rimraf ./dist",
"clean": "npm run build:clean",
"prestart": "npm run build",
"start": "node dist/express_server.js",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dependencies": {},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.11",
"@types/ldapjs": "^2.2.5",
"axios": "^1.4.0",
"express": "^4.18.2",
"form-auto-content": "^3.2.1",
"formdata-node": "^6.0.3",
"jest": "^29.7.0",
"ldapjs": "^3.0.2",
"ldif": "^0.5.1",
"pino": "^8.17.1",
"pino-pretty": "^10.3.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.11",
"@types/ldapjs": "^2.2.5",
"jest": "^29.7.0",
"pino-pretty": "^10.3.0",
"rimraf": "^3.0.2",
"rollup": "^4.9.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
}
}
22 changes: 22 additions & 0 deletions tdrive/backend/utils/nextcloud-migration/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

export default {
input: './src/express_server.ts',
output: {
format: 'es',
dir: 'dist',
entryFileNames: '[name].js',
sourcemap: true
},
plugins: [
commonjs(),
json(),
nodeResolve({preferBuiltins: true}),
typescript(),
terser(),
]
}
12 changes: 10 additions & 2 deletions tdrive/docker/tdrive-nextcloud-migration/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Use an official Node.js runtime as the base image
FROM node:bullseye

run apt update && apt -y dist-upgrade
RUN apt install dirmngr

RUN echo "deb http://ppa.launchpad.net/nextcloud-devs/client/ubuntu zesty main" >> /etc/apt/sources.list.d/nextcloud-client.list
RUN echo "deb-src http://ppa.launchpad.net/nextcloud-devs/client/ubuntu zesty main" >> /etc/apt/sources.list.d/nextcloud-client.list

RUN apt install dirmngr
RUN apt-key adv --recv-key --keyserver keyserver.ubuntu.com AD3DD469

RUN apt update
Expand All @@ -13,15 +15,21 @@ RUN apt install --assume-yes nextcloud-desktop-cmd

RUN apt install ldap-utils

RUN apt autoremove && apt clean && rm -rf /var/lib/apt/lists/*

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy app
COPY backend/utils/nextcloud-migration/src/** ./src/
COPY backend/utils/nextcloud-migration/.nvmrc ./
COPY backend/utils/nextcloud-migration/*.json ./
COPY backend/utils/nextcloud-migration/rollup.config.js ./

RUN npm i && npm run build && npm cache clean --force && rm -rf node_modules

RUN npm i && npm run build
# Don't rebuild on start
RUN perl -i -ne 'print unless/prestart/' package.json

# Run the Node.js application
CMD ["npm", "run", "start"]

0 comments on commit eae8590

Please sign in to comment.