Преглед изворни кода

refactor(docker): improve build for optimized caching

Only use one step inside the Dockerfile to avoid re-running everything in each pipeline
Nicolas Meienberger пре 2 година
родитељ
комит
bc95544846
3 измењених фајлова са 19 додато и 188 уклоњено
  1. 7 27
      Dockerfile
  2. 3 12
      package.json
  3. 9 149
      pnpm-lock.yaml

+ 7 - 27
Dockerfile

@@ -1,45 +1,25 @@
-FROM node:18 AS build
-
-RUN npm install node-gyp -g
-
-WORKDIR /api
-COPY ./packages/system-api/package.json /api/package.json
-RUN npm i
-# ---
-WORKDIR /dashboard
-COPY ./packages/dashboard/package.json /dashboard/package.json
-RUN npm i
-
-WORKDIR /api
-COPY ./packages/system-api /api
-RUN npm run build
-# ---
-WORKDIR /dashboard
-COPY ./packages/dashboard /dashboard
-RUN npm run build
-
-
 FROM alpine:3.16.0 as app
 
 WORKDIR /
 
 # Install dependencies
 RUN apk --no-cache add docker-compose nodejs npm bash g++ make git
-
 RUN npm install node-gyp -g
 
 WORKDIR /api
 COPY ./packages/system-api/package*.json /api/
-RUN npm install --production
+RUN npm install --omit=dev
 
 WORKDIR /dashboard
 COPY ./packages/dashboard/package*.json /dashboard/
-RUN npm install --production
+RUN npm install --omit=dev
 
-COPY --from=build /api/dist /api/dist
+WORKDIR /api
 COPY ./packages/system-api /api
-
-COPY --from=build /dashboard/.next /dashboard/.next
+RUN npm i -g @swc/cli @swc/core && npm run build && npm uninstall -g @swc/cli @swc/core
+# ---
+WORKDIR /dashboard
 COPY ./packages/dashboard /dashboard
+RUN npm i typescript @types/node && npm run build && npm uninstall typescript @types/node
 
 WORKDIR /

+ 3 - 12
package.json

@@ -3,7 +3,6 @@
   "version": "0.5.0",
   "description": "A homeserver for everyone",
   "scripts": {
-    "test": "jest",
     "prepare": "husky install",
     "commit": "git-cz",
     "act:test-install": "act --container-architecture linux/amd64 -j test-install",
@@ -11,23 +10,16 @@
     "start:dev": "docker-compose -f docker-compose.dev.yml --env-file .env.dev up --build",
     "start:rc": "docker-compose -f docker-compose.rc.yml --env-file .env up --build",
     "start:prod": "docker-compose --env-file .env up --build",
-    "build:common": "cd packages/common && npm run build",
     "start:pg": "docker run --name test-db -p 5433:5432 -d --rm -e POSTGRES_PASSWORD=postgres postgres",
     "version": "echo $npm_package_version"
   },
   "devDependencies": {
-    "@types/jest": "^27.5.0",
-    "@types/js-yaml": "^4.0.5",
-    "@types/node": "17.0.31",
-    "husky": "^8.0.1",
-    "jest": "^28.1.0",
-    "js-yaml": "^4.1.0",
-    "ts-jest": "^28.0.2",
-    "typescript": "4.6.4",
     "@commitlint/cli": "^17.0.3",
     "@commitlint/config-conventional": "^17.0.3",
     "@commitlint/cz-commitlint": "^17.0.3",
-    "commitizen": "^4.2.4"
+    "commitizen": "^4.2.4",
+    "husky": "^8.0.1",
+    "inquirer": "8.2.4"
   },
   "repository": {
     "type": "git",
@@ -39,7 +31,6 @@
     "url": "https://github.com/meienberger/runtipi/issues"
   },
   "homepage": "https://github.com/meienberger/runtipi#readme",
-  "dependencies": {},
   "config": {
     "commitizen": {
       "path": "@commitlint/cz-commitlint"

+ 9 - 149
pnpm-lock.yaml

@@ -7,28 +7,16 @@ importers:
       '@commitlint/cli': ^17.0.3
       '@commitlint/config-conventional': ^17.0.3
       '@commitlint/cz-commitlint': ^17.0.3
-      '@types/jest': ^27.5.0
-      '@types/js-yaml': ^4.0.5
-      '@types/node': 17.0.31
       commitizen: ^4.2.4
       husky: ^8.0.1
-      jest: ^28.1.0
-      js-yaml: ^4.1.0
-      ts-jest: ^28.0.2
-      typescript: 4.6.4
+      inquirer: 8.2.4
     devDependencies:
       '@commitlint/cli': 17.0.3
       '@commitlint/config-conventional': 17.0.3
-      '@commitlint/cz-commitlint': 17.0.3_commitizen@4.2.5
-      '@types/jest': 27.5.0
-      '@types/js-yaml': 4.0.5
-      '@types/node': 17.0.31
+      '@commitlint/cz-commitlint': 17.0.3_yes7iyjckc3rubj3ixzwc3ince
       commitizen: 4.2.5
       husky: 8.0.1
-      jest: 28.1.0_@types+node@17.0.31
-      js-yaml: 4.1.0
-      ts-jest: 28.0.2_z3fx76c5ksuwr36so7o5uc2kcy
-      typescript: 4.6.4
+      inquirer: 8.2.4
 
   packages/dashboard:
     specifiers:
@@ -2033,7 +2021,7 @@ packages:
       ajv: 8.11.0
     dev: true
 
-  /@commitlint/cz-commitlint/17.0.3_commitizen@4.2.5:
+  /@commitlint/cz-commitlint/17.0.3_yes7iyjckc3rubj3ixzwc3ince:
     resolution: {integrity: sha512-360I6wnaUWzc23D8Xn4B/cu8thy8GDJPZ4QsYk4xjVzDDyXZ6oXJB0+OlwkpWpSvjuLYAmEKiImvo0yLTASmlg==}
     engines: {node: '>=v14'}
     peerDependencies:
@@ -2045,6 +2033,7 @@ packages:
       '@commitlint/types': 17.0.0
       chalk: 4.1.2
       commitizen: 4.2.5
+      inquirer: 8.2.4
       lodash: 4.17.21
       word-wrap: 1.2.3
     transitivePeerDependencies:
@@ -2879,49 +2868,6 @@ packages:
       slash: 3.0.0
     dev: true
 
-  /@jest/core/28.1.0:
-    resolution: {integrity: sha512-/2PTt0ywhjZ4NwNO4bUqD9IVJfmFVhVKGlhvSpmEfUCuxYf/3NHcKmRFI+I71lYzbTT3wMuYpETDCTHo81gC/g==}
-    engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
-    peerDependencies:
-      node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0
-    peerDependenciesMeta:
-      node-notifier:
-        optional: true
-    dependencies:
-      '@jest/console': 28.1.0
-      '@jest/reporters': 28.1.0
-      '@jest/test-result': 28.1.0
-      '@jest/transform': 28.1.0
-      '@jest/types': 28.1.0
-      '@types/node': 17.0.31
-      ansi-escapes: 4.3.2
-      chalk: 4.1.2
-      ci-info: 3.3.0
-      exit: 0.1.2
-      graceful-fs: 4.2.10
-      jest-changed-files: 28.0.2
-      jest-config: 28.1.0_@types+node@17.0.31
-      jest-haste-map: 28.1.0
-      jest-message-util: 28.1.0
-      jest-regex-util: 28.0.2
-      jest-resolve: 28.1.0
-      jest-resolve-dependencies: 28.1.0
-      jest-runner: 28.1.0
-      jest-runtime: 28.1.0
-      jest-snapshot: 28.1.0
-      jest-util: 28.1.0
-      jest-validate: 28.1.0
-      jest-watcher: 28.1.0
-      micromatch: 4.0.5
-      pretty-format: 28.1.0
-      rimraf: 3.0.2
-      slash: 3.0.0
-      strip-ansi: 6.0.1
-    transitivePeerDependencies:
-      - supports-color
-      - ts-node
-    dev: true
-
   /@jest/core/28.1.0_ts-node@10.8.2:
     resolution: {integrity: sha512-/2PTt0ywhjZ4NwNO4bUqD9IVJfmFVhVKGlhvSpmEfUCuxYf/3NHcKmRFI+I71lYzbTT3wMuYpETDCTHo81gC/g==}
     engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
@@ -6403,7 +6349,7 @@ packages:
       eslint-import-resolver-webpack:
         optional: true
     dependencies:
-      '@typescript-eslint/parser': 5.22.0_hcfsmds2fshutdssjqluwm76uu
+      '@typescript-eslint/parser': 5.22.0_uhoeudlwl7kc47h4kncsfowede
       debug: 3.2.7
       eslint-import-resolver-node: 0.3.6
       find-up: 2.1.0
@@ -7800,7 +7746,7 @@ packages:
       mute-stream: 0.0.8
       ora: 5.4.1
       run-async: 2.4.1
-      rxjs: 7.5.5
+      rxjs: 7.5.6
       string-width: 4.2.3
       strip-ansi: 6.0.1
       through: 2.3.8
@@ -8246,34 +8192,6 @@ packages:
       - supports-color
     dev: true
 
-  /jest-cli/28.1.0_@types+node@17.0.31:
-    resolution: {integrity: sha512-fDJRt6WPRriHrBsvvgb93OxgajHHsJbk4jZxiPqmZbMDRcHskfJBBfTyjFko0jjfprP544hOktdSi9HVgl4VUQ==}
-    engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
-    hasBin: true
-    peerDependencies:
-      node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0
-    peerDependenciesMeta:
-      node-notifier:
-        optional: true
-    dependencies:
-      '@jest/core': 28.1.0
-      '@jest/test-result': 28.1.0
-      '@jest/types': 28.1.0
-      chalk: 4.1.2
-      exit: 0.1.2
-      graceful-fs: 4.2.10
-      import-local: 3.1.0
-      jest-config: 28.1.0_@types+node@17.0.31
-      jest-util: 28.1.0
-      jest-validate: 28.1.0
-      prompts: 2.4.2
-      yargs: 17.4.1
-    transitivePeerDependencies:
-      - '@types/node'
-      - supports-color
-      - ts-node
-    dev: true
-
   /jest-cli/28.1.0_qxft4nzwxz7jey57xog52j3doy:
     resolution: {integrity: sha512-fDJRt6WPRriHrBsvvgb93OxgajHHsJbk4jZxiPqmZbMDRcHskfJBBfTyjFko0jjfprP544hOktdSi9HVgl4VUQ==}
     engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
@@ -8302,45 +8220,6 @@ packages:
       - ts-node
     dev: true
 
-  /jest-config/28.1.0_@types+node@17.0.31:
-    resolution: {integrity: sha512-aOV80E9LeWrmflp7hfZNn/zGA4QKv/xsn2w8QCBP0t0+YqObuCWTSgNbHJ0j9YsTuCO08ZR/wsvlxqqHX20iUA==}
-    engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
-    peerDependencies:
-      '@types/node': '*'
-      ts-node: '>=9.0.0'
-    peerDependenciesMeta:
-      '@types/node':
-        optional: true
-      ts-node:
-        optional: true
-    dependencies:
-      '@babel/core': 7.17.10
-      '@jest/test-sequencer': 28.1.0
-      '@jest/types': 28.1.0
-      '@types/node': 17.0.31
-      babel-jest: 28.1.0_@babel+core@7.17.10
-      chalk: 4.1.2
-      ci-info: 3.3.0
-      deepmerge: 4.2.2
-      glob: 7.2.0
-      graceful-fs: 4.2.10
-      jest-circus: 28.1.0
-      jest-environment-node: 28.1.0
-      jest-get-type: 28.0.2
-      jest-regex-util: 28.0.2
-      jest-resolve: 28.1.0
-      jest-runner: 28.1.0
-      jest-util: 28.1.0
-      jest-validate: 28.1.0
-      micromatch: 4.0.5
-      parse-json: 5.2.0
-      pretty-format: 28.1.0
-      slash: 3.0.0
-      strip-json-comments: 3.1.1
-    transitivePeerDependencies:
-      - supports-color
-    dev: true
-
   /jest-config/28.1.0_qxft4nzwxz7jey57xog52j3doy:
     resolution: {integrity: sha512-aOV80E9LeWrmflp7hfZNn/zGA4QKv/xsn2w8QCBP0t0+YqObuCWTSgNbHJ0j9YsTuCO08ZR/wsvlxqqHX20iUA==}
     engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
@@ -8690,25 +8569,6 @@ packages:
       supports-color: 8.1.1
     dev: true
 
-  /jest/28.1.0_@types+node@17.0.31:
-    resolution: {integrity: sha512-TZR+tHxopPhzw3c3560IJXZWLNHgpcz1Zh0w5A65vynLGNcg/5pZ+VildAd7+XGOu6jd58XMY/HNn0IkZIXVXg==}
-    engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
-    hasBin: true
-    peerDependencies:
-      node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0
-    peerDependenciesMeta:
-      node-notifier:
-        optional: true
-    dependencies:
-      '@jest/core': 28.1.0
-      import-local: 3.1.0
-      jest-cli: 28.1.0_@types+node@17.0.31
-    transitivePeerDependencies:
-      - '@types/node'
-      - supports-color
-      - ts-node
-    dev: true
-
   /jest/28.1.0_qxft4nzwxz7jey57xog52j3doy:
     resolution: {integrity: sha512-TZR+tHxopPhzw3c3560IJXZWLNHgpcz1Zh0w5A65vynLGNcg/5pZ+VildAd7+XGOu6jd58XMY/HNn0IkZIXVXg==}
     engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
@@ -11266,8 +11126,8 @@ packages:
       tslib: 1.14.1
     dev: true
 
-  /rxjs/7.5.5:
-    resolution: {integrity: sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==}
+  /rxjs/7.5.6:
+    resolution: {integrity: sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==}
     dependencies:
       tslib: 2.4.0
     dev: true