From 2625cbe0d2eda6a7ea7ee203a27a5b00bc4fbe91 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 2 Oct 2021 14:43:31 +0800 Subject: [PATCH 1/2] add script for downloading the dist files from github --- .dockerignore | 2 +- .gitignore | 1 + extra/download-dist.js | 57 ++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 1 + package.json | 4 ++- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 extra/download-dist.js diff --git a/.dockerignore b/.dockerignore index 539e9328..9aa6ba32 100644 --- a/.dockerignore +++ b/.dockerignore @@ -27,7 +27,7 @@ CNAME install.sh SECURITY.md tsconfig.json - +/tmp ### .gitignore content (commented rules are duplicated) diff --git a/.gitignore b/.gitignore index 2bf60f7c..0863015d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist-ssr /private /out +/tmp diff --git a/extra/download-dist.js b/extra/download-dist.js new file mode 100644 index 00000000..0a08b7f9 --- /dev/null +++ b/extra/download-dist.js @@ -0,0 +1,57 @@ +console.log("Downloading dist"); +const https = require("https"); +const tar = require("tar"); + +const packageJSON = require("../package.json"); +const fs = require("fs"); +const version = packageJSON.version; + +const filename = "dist.tar.gz"; + +const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`; +download(url); + +function download(url) { + console.log(url); + + https.get(url, (response) => { + if (response.statusCode === 200) { + console.log("Extracting dist..."); + + if (fs.existsSync("./dist")) { + + if (fs.existsSync("./dist-backup")) { + fs.rmdirSync("./dist-backup", { + recursive: true + }); + } + + fs.renameSync("./dist", "./dist-backup"); + } + + const tarStream = tar.x({ + cwd: "./", + }); + + tarStream.on("close", () => { + fs.rmdirSync("./dist-backup", { + recursive: true + }); + console.log("Done"); + }); + + tarStream.on("error", () => { + if (fs.existsSync("./dist-backup")) { + fs.renameSync("./dist-backup", "./dist"); + } + console.log("Done"); + }); + + response.pipe(tarStream); + } else if (response.statusCode === 302) { + download(response.headers.location); + } else { + console.log("dist not found"); + } + }); +} diff --git a/package-lock.json b/package-lock.json index 34615b9d..60f9a7bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "redbean-node": "0.1.2", "socket.io": "~4.2.0", "socket.io-client": "~4.2.0", + "tar": "^6.1.11", "tcp-ping": "~0.1.1", "thirty-two": "~1.0.2", "timezones-list": "~3.0.1", diff --git a/package.json b/package.json index 17bfe975..cf22cd99 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "build-docker-nightly-alpine": "docker buildx build -f dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push", "build-docker-nightly-amd64": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain", "upload-artifacts": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain", - "setup": "git checkout 1.7.3 && npm install --legacy-peer-deps && node node_modules/esbuild/install.js && npm run build && npm prune", + "setup": "git checkout 1.7.3 && npm ci --production && npm run download-dist", + "download-dist": "node extra/download-dist.js", "update-version": "node extra/update-version.js", "mark-as-nightly": "node extra/mark-as-nightly.js", "reset-password": "node extra/reset-password.js", @@ -77,6 +78,7 @@ "redbean-node": "0.1.2", "socket.io": "~4.2.0", "socket.io-client": "~4.2.0", + "tar": "^6.1.11", "tcp-ping": "~0.1.1", "thirty-two": "~1.0.2", "timezones-list": "~3.0.1", From d3517e76c1a73f3623d22f2caecf127d1926caa5 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 3 Oct 2021 15:27:15 +0800 Subject: [PATCH 2/2] change to npm ci --- dockerfile | 2 +- dockerfile-alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerfile b/dockerfile index 969d5ff3..3746722f 100644 --- a/dockerfile +++ b/dockerfile @@ -2,7 +2,7 @@ FROM louislam/uptime-kuma:base-debian AS build WORKDIR /app COPY . . -RUN npm install --legacy-peer-deps && \ +RUN npm ci && \ npm run build && \ npm prune --production && \ chmod +x /app/extra/entrypoint.sh diff --git a/dockerfile-alpine b/dockerfile-alpine index 178afcab..8cbfbe23 100644 --- a/dockerfile-alpine +++ b/dockerfile-alpine @@ -2,7 +2,7 @@ FROM louislam/uptime-kuma:base-alpine AS build WORKDIR /app COPY . . -RUN npm install --legacy-peer-deps && \ +RUN npm ci && \ npm run build && \ npm prune --production && \ chmod +x /app/extra/entrypoint.sh